Retrieval-Augmented Generation104 · Module II · Lesson 07 of 13
Article · 12 min

Metadata filtering

The feature that saves most production systems.

Summary

Metadata filtering restricts retrieval to documents matching structured predicates (date > 2024, author = 'x', category = 'contract'). It is the feature that saves most production RAG systems: retrieving from the right subset beats reranking the wrong universe.

Objectives
  • 01Design a metadata schema for a corpus.
  • 02State the difference between pre-filter and post-filter.
  • 03Recognize when metadata is doing the work retrieval was blamed for.
The Lesson

The schema

Attach structured metadata to every chunk: source, date, author, category, permissions, version. Design metadata around the queries you actually run. Missing metadata is silently painful — you can add it later, but only to new chunks unless you reindex.

Filter placement

Pre-filter: apply the predicate before ANN search. Correct results, sometimes slower. Post-filter: search, then filter, potentially returning fewer than k results if too many were filtered out. Most vector DBs support both; pre-filter unless you have a reason not to.

Key Ideas
  • Metadata filtering often outperforms retrieval improvement.
  • Design the schema for the queries, not the documents.