LLM Learning Hub

workspace/llm-course/home

Metadata Filtering

Metadata filtering restricts vector search results to those whose associated metadata (e.g., source, date, author) matches a predicate, combining semantic search with structured queries.

What is Metadata Filtering?

Metadata filtering restricts vector search results to those whose associated metadata (e.g., source, date, author) matches a predicate, combining semantic search with structured queries.

Metadata filtering restricts vector search results to those whose associated metadata (e.g., source, date, author) matches a predicate, combining semantic search with structured queries.

Where is it used?

Qdrant `Filter`, Weaviate `where` clauses, and pgvector `WHERE` filters are used in RAG to restrict retrieval to a user's docs or a specific date range; LangChain exposes this via `filter` kwargs.

How to build it

In Qdrant, call `client.search("docs", query_vector=vec, query_filter=Filter(must=[FieldCondition(key="source", match=MatchValue(value="api"))]))` to retrieve only matching chunks.