Construct a dual-channel retrieval engine combining BM25 exact keyword matching and dense vector embeddings, fused via Reciprocal Rank Fusion (RRF), while enforcing cryptographic multi-tenant metadata isolation.
~120 minutes hands-on · FDE Track, Core Production difficulty.
A legal tech client complains that their pure vector search misses exact statutory clause references (e.g. Section 43A) and accidentally leaks confidential documents between subsidiary tenants. You will stand up a Qdrant vector store and implement an RRF hybrid search pipeline with mandatory tenant pre-filters.
hybrid_search.py: Hybrid search engine combining BM25 and vector embeddings.rrf_fusion.py: Mathematical Reciprocal Rank Fusion blending logic.benchmark.py: Test harness proving 100% tenant isolation and >90% recall@5.Install Dependencies:
pip install qdrant-client==1.9.1 rank-bm25==0.2.2 numpy==1.26.4
Implement Reciprocal Rank Fusion (RRF): Write the mathematical rank fusion function that takes ranked IDs from BM25 and vector search, calculates $1 / (60 + \text{rank})$, and sorts descending.
Enforce Tenant Isolation:
In hybrid_search.py, ensure that every Qdrant query filter contains a mandatory {"key": "tenant_id", "match": {"value": authenticated_tenant}}.
Verify It Works: Execute 50 cross-tenant adversarial queries. Assert that zero results from Tenant B ever appear in searches initiated by Tenant A.