Hybrid Search with Qdrant: Solving RAG’s ‘Amnesia’ with Specific Keywords

Artificial Intelligence tutorial - IT technology blog
Artificial Intelligence tutorial - IT technology blog

When Your AI System Stumbles on Specific Keywords

You’ve just finished building a RAG chatbot for your company and confidently take it to a demo. Your boss types in a specific product code: “Dell XPS 9315 Specifications”. Instead of returning that exact model, the chatbot rambles about the XPS 13 series in general or, worse, an older model. The result? A disappointed boss and a confused developer.

The issue isn’t the data. The data is already in your Vector Database, but the AI simply can’t “pick out” exactly what you need. Real-world Enterprise AI deployments show that while Vector Search is great at understanding intent, it often ‘surrenders’ when faced with SKUs, proper names, or technical jargon. This is exactly where Hybrid Search comes to the rescue.

The Core Issue: Why Vector Search Alone Isn’t Enough?

Vector Search works by compressing text semantics into a sequence of numbers (Embeddings). During this compression, the model prioritizes the general ‘flavor’ of the sentence over exact character matching.

Take this example: “iPhone 13” and “iPhone 14” have extremely close vector coordinates. In the eyes of the AI, they are both high-end Apple smartphones. If a user needs an exact replacement part for the iPhone 13, the system might return results for the iPhone 14 because the semantic similarity is as high as 98%.

Conversely, Keyword Search (like the BM25 algorithm) acts like a literal proofreader. It doesn’t need to know what an “iPhone” is; it only cares if the text matches character for character. Its weakness is its rigidity. If a user types “Apple smartphone,” it will be completely ‘blind’ if those exact words don’t exist in the document.

Hybrid Search: The Best of Both Worlds

Instead of choosing one over the other, Hybrid Search combines Dense Retrieval (Vector Search – semantic understanding) and Sparse Retrieval (Keyword Search – exact matching).

In a technical documentation project I worked on, switching from pure Vector Search to Hybrid Search boosted Top-1 Accuracy from 62% to 89%. Qdrant is currently one of the few engines that provides highly optimized native support for this mechanism right at its core.

Implementation Guide with Qdrant and Python

To get started, you need to install qdrant-client. I recommend using fastembed to handle embeddings locally without needing to call external APIs.

pip install qdrant-client fastembed

Step 1: Initialize the Client

We will use Qdrant’s :memory: mode for a quick demo without a complex Docker setup.

from qdrant_client import QdrantClient

# Run directly in RAM for testing
client = QdrantClient(":memory:")

Step 2: Set Up a Hybrid Collection

The key is here. You must define both vectors_config (for Dense) and sparse_vectors_config (for Keyword).

from qdrant_client.models import Distance, VectorParams, SparseVectorParams

client.create_collection(
    collection_name="hybrid_rag_demo",
    vectors_config={
        "dense": VectorParams(size=384, distance=Distance.COSINE)
    },
    sparse_vectors_config={
        "sparse": SparseVectorParams()
    }
)

Step 3: Smart Data Ingestion

Qdrant has a great feature that automates vector creation. You just provide the raw text, and the system handles the rest.

documents = [
    "Dell XPS 9315 Laptop core i7 12th Gen",
    "Macbook Pro M2 14-inch Retina display",
    "Troubleshooting guide for Electrolux washing machine error E01"
]

# Qdrant automatically generates both Dense and Sparse vectors
client.add(
    collection_name="hybrid_rag_demo",
    documents=documents
)

Step 4: Combined Querying

The system uses the RRF (Reciprocal Rank Fusion) algorithm to merge results from both search methods.

results = client.query(
    collection_name="hybrid_rag_demo",
    query_text="Washing machine error E01",
    limit=3
)

for hit in results:
    print(f"Result: {hit.metadata['document']} | Score: {hit.score:.4f}")

3 Critical Lessons for Real-World Implementation

After several ‘stumbles’ while bringing Hybrid Search to production, here are the lessons I’ve learned:

  • Weight Adjustment: Not every project needs a 50/50 split. For data containing many technical codes or logs, prioritize a higher weight for Keyword Search.
  • Language Specifics: Sparse Vectors rely heavily on tokenization. For languages like Vietnamese, you should use libraries like pyvi or underthesea to pre-process text before feeding it into Qdrant to avoid “washing machine” queries returning “car wash” results.
  • Resource Costs: Storing two types of vectors increases storage requirements by about 20-30%. However, this is a small price to pay for the significant boost in system accuracy.

Conclusion

Don’t let your chatbot become useless just because it can’t find a specific product code. Combining Hybrid Search with a Reranking step using a Cross-Encoder is the perfect duo for any modern RAG system. The standard workflow should be: Hybrid Search -> Rerank top 10 -> Feed to LLM. Good luck with your AI projects!

Share: