Metadata filtering restricts vector-search results using structured attributes stored with each item. In a RAG pipeline, it combines semantic similarity with constraints such as city, locality, language, or year, reducing irrelevant context and improving personalization. section 6.2 section 6.6
A practical implementation follows this sequence:
- Store filterable fields as payload metadata alongside each embedding, such as hotel name, review text, and locality. section 6.2
- Construct a filter only when a constraint is supplied; a city value becomes a Qdrant field condition matching the locality payload. section 6.2
- Pass the filter into vector search so Qdrant returns the highest-scoring matching points and their payloads for prompt construction. section 6.2
City-specific hotel retrieval
For the query “Amazing hotel close to everything,” setting city_filter to “Istanbul” limits retrieval to Istanbul records. The generated answer can then cite matching hotels, localities, review text, and similarity scores rather than mixing results from other cities. section 6.2
def search_qdrant_with_filter(query, model, client, city=None, k=10): #A
query_filter = None
if city:
query_filter = models.Filter( #B
must=[
models.FieldCondition(
key="locality",
match=models.MatchValue(value=city)
)
]
)
text_hits = client.query_points(
collection_name="hotel_reviews",
query=query_embedding,
query_filter=query_filter,
limit=k,
with_payload=True,
).points
return text_hits
Inspect the incremental Python implementation that builds an optional locality filter and passes it to Qdrant vector search. section 6.2




