## Definition **Metadata filtering** attaches structured fields to each indexed chunk — source, author, date, document type, language, access permissions — so retrieval can restrict to the right **subset** before or during ranking. It combines *what a chunk is about* ([[Embedding-Based Retrieval|vectors]]) with *which subset it belongs to* (metadata). ## Why it matters - **Access control** — return only documents a user is allowed to see. This is a hard correctness and security requirement, not an optimisation: without it, retrieval leaks data across tenants or permission boundaries. - **Recency and scope** — restrict to a time range, project, product, or language. - **Precision** — dropping irrelevant partitions before ranking means the nearest vectors are also the *relevant* ones. ## How it combines with vector search A metadata predicate is applied around nearest-neighbour search in the [[Vector Database]]. *Pre-filtering* narrows the candidate set first (safe for access control); *post-filtering* ranks first, then filters (faster, but can return too few). Access-control filters must be pre-filters. ## Related - [[Vector Database]] - [[Retrieval-Augmented Generation]] - [[RAG Chunking Strategy]] - [[Hybrid Search]] ## Sources - [[AI Engineering - Chip Huyen]]