How does metadata filtering improve retrieval?
Chunks are stored with fields such as source, date, language, product or access level. Filtering on those fields before or during vector search removes irrelevant or forbidden documents, improving precision and enforcing who is allowed to see what.
Explain it simply
When you search IRCTC for trains, you set date, source and destination first. You do not scroll through every train in the country and hope the right one ranks high.
Metadata filtering does the same for RAG. Each chunk carries labels: document type, version, department, year, language, customer id. A query for "leave policy" from an employee in India can be filtered to the India HR documents of the current year, so the semantically similar but wrong US policy never appears.
It also supports security. Access control labels let you retrieve only what the user is permitted to see. Do this in the retrieval layer, because trusting the model to hide restricted text is unsafe. The filters can come from the user's session or be extracted from the question.
Example
query: "notice period for resignation"
filter: {"country": "IN", "doc_type": "policy", "valid": true}
-> vector search runs only among matching chunksWhat to say in the interview
"Metadata filters narrow the candidate set by attributes like version, region or access level, improving precision and enforcing permissions in the retrieval layer rather than relying on the LLM to withhold content."
Common mistakes
- Retrieving everything, then asking the model not to reveal restricted parts.