Hybrid search with filters

Sometimes semantic search alone is not enough. What if you search for "cards" but get results about both gift cards and credit card billing? You need to combine vector similarity with metadata filtering, and this is called hybrid search.

03_vector_stores.ipynb
python
from qdrant_client.models import Filter, FieldCondition, MatchValue

# Search for "cards" but only in billing-related policies
query = "cards"
query_resp = litellm.embedding(model=EMBEDDING_MODEL, input=[query])

# Without filter: gets gift cards AND billing
all_results = client.query_points(
    collection_name="green_bites_policies",
    query=query_resp.data[0]["embedding"],
    limit=3
)

# With filter: only billing category
filtered_results = client.query_points(
    collection_name="green_bites_policies",
    query=query_resp.data[0]["embedding"],
    query_filter=Filter(
        must=[
            FieldCondition(
                key="category",
                match=MatchValue(value="billing")
            )
        ]
    ),
    limit=3
)

print("Filtered results (billing only):")
for point in filtered_results.points:
    print(f"  {point.score:.4f} | {point.payload['text']}")

Filter search results by metadata category

Hybrid search flow

Vector similarity and metadata filters work together.

Timed quiz: Quick check

Loading practice…

Flashcards: Flashcards

Loading practice…

Checkpoint: RAG knowledge check

Loading practice…