Metadata Filtering
Narrowing vector search results by structured attributes (date, category, department, access level) before or after semantic matching. Without metadata filtering, a support agent searching for 'refund policy' might retrieve the refund policy from 2023 instead of the current one, or surface an internal policy document that shouldn't be shown to customers. Metadata filters ensure the agent only retrieves documents that match the relevant context—current versions, correct department, appropriate access level.
Example
A legal agent searches for contract templates. Vector search finds 20 semantically similar documents. Metadata filtering narrows to: jurisdiction = 'California,' document type = 'template' (not 'executed contract'), and status = 'current' (not 'archived'). The agent returns 3 relevant templates instead of 20 mixed results.
Frequently asked questions
- Should metadata filtering happen before or after vector search?
- Pre-filtering (before vector search) is more efficient—it reduces the search space. Post-filtering is simpler to implement but wastes compute searching irrelevant documents. Most production systems use pre-filtering for hard constraints (access control, active status) and post-filtering for soft preferences (recency, popularity).