Skip to main content

Hybrid Search

Overview

By default, RAGLight retrieves documents using semantic search — it embeds the query and finds the closest vectors in the store. Hybrid search extends this by combining two complementary retrieval strategies:
  • Semantic search — captures meaning and context (via embeddings + vector store)
  • BM25 — captures exact keyword matches (via the BM25Okapi algorithm)
The two result lists are merged using Reciprocal Rank Fusion (RRF), a rank aggregation algorithm that is both simple and robust.
Semantic search alone can struggle when:
  • queries contain rare technical terms or acronyms
  • documents are sparse or domain-specific
  • the user expects an exact term to appear in the answer
BM25 alone misses synonyms and paraphrasing. Hybrid search combines both to improve retrieval quality across a wider range of query types.

How it works

At retrieval time, hybrid search follows these steps:
Why 2k? Fetching more candidates from each method before fusion ensures that good results that rank lower in one list still have a chance to surface in the final top k. RRF score formula:
where k_rrf = 60 (a standard constant that smooths rank decay), and the sum runs over each ranked list the document appears in.

Configuration

Via VectorStoreConfig (simple API)

Pass this config to RAGPipeline or AgenticRAGPipeline — the rest of the pipeline is unchanged.

Via the Builder API (advanced)

Works with both Chroma and Qdrant:

Search modes

RAGLight supports three search modes, all configured via search_type: The default is "semantic" — existing code requires no changes to keep its current behavior.

Full example


BM25 index persistence

The BM25 index is built from the same documents stored in your vector store. It is automatically:
  • populated when documents are ingested via pipeline.build() or vector_store.ingest()
  • saved to {persist_directory}/bm25_{collection_name}.json
  • reloaded on next startup from that file
No additional setup is required. The BM25 index stays in sync with the vector store automatically.
Remote Qdrant: when using Qdrant in remote mode (host + port), there is no local persist_directory. In this case the BM25 index is kept in-memory and rebuilt from the remote collection at startup. This adds a brief startup cost proportional to collection size, but requires no additional storage.

Summary

  • Hybrid search combines semantic and BM25 retrieval with Reciprocal Rank Fusion
  • Enable it by setting search_type=Settings.SEARCH_HYBRID in VectorStoreConfig
  • The default remains "semantic" — no breaking change for existing code
  • Supported on both Chroma and Qdrant backends
  • The BM25 index is persisted automatically alongside your vector store data (in-memory for remote Qdrant)
  • Use hybrid search when your knowledge base contains technical terms, acronyms, or sparse text