How do metadata filters improve retrieval?
RAG · Intermediate 2
Short answer
Store fields such as source, date, product, region, language and access level with each chunk. At query time, filter on them before or alongside the similarity search, for example only 2025 policies for Karnataka, so results are relevant, current and permitted. Get metadata from the document structure or extract it with a model, and keep it consistent.
Deeper answer
Pure similarity search cannot tell an old policy from a new one if the wording is similar. Filters fix that cheaply. A model can turn a user's question into filters, such as 'last quarter' into a date range, a pattern often called self-querying.
Watch for over-filtering that removes the right answer, and for missing metadata on some documents, which silently excludes them.
What a strong answer covers
- Stores fields with each chunk
- Filters during search
- Improves relevance and freshness
- Enforces access levels
- Extracts metadata and can derive filters from the query
Answer it out loud in the mock interview about 1 min
Follow-ups to expect
- How would you turn 'last quarter's reports' into a filter?
- What happens to chunks with missing metadata?
Common mistakes
- Relying on similarity alone for dates and versions
- Inconsistent metadata values
Learn it
- How do you choose a chunk size for RAG?
- Your RAG app gives wrong answers. How do you find the cause?
- Design a RAG system that lets a law firm search and ask questions about 50,000 contracts.
- How would you detect hallucinations in a production RAG application?
- What are embeddings, and how are they used in search?
- How do you make a RAG system cite sources and stay grounded?
- What are hybrid search and reranking, and when do they help?
- How do you keep a RAG index up to date as documents change?
- How would you build RAG over documents full of charts and images?
- Your RAG system must handle scanned PDFs, tables and slides. How do you ingest them?
- How do you make sure users only get answers from documents they are allowed to see?
- What are query rewriting and HyDE, and when do they help?
- Your HR assistant keeps quoting last year's leave policy. How do you fix it?
- Tell me about a RAG system you built and how you measured whether it worked.
- Can you do retrieval for long documents without a vector database?
- What is RAG, and why would you use it?
- When would you use graph RAG instead of standard vector RAG?