Hybrid Search in Manticore Search: Combining BM25 and KNN
Hybrid search in Manticore Search combines full-text BM25 search and vector KNN search into a single query. This allows for simultaneous consideration of exact keywords and semantic similarity. For a query like "cheap running shoes," BM25 will provide matches based on tokens, while KNN will capture the meaning of phrases such as "comfortable footwear for jogging."
The method uses Reciprocal Rank Fusion (RRF) to merge ranked lists. Documents with high positions in either search receive priority in the final ranking.
Advantages of the Hybrid Approach
Full-text search is effective for rare terms, SKUs, and error codes. Vector search captures synonyms and natural language, as embeddings of related concepts are positioned close together in the vector space.
Weaknesses of each method:
- BM25 struggles with synonyms.
- KNN ignores exact identifiers without semantic meaning.
Hybrid retrieval improves recall for mixed queries, minimizing the need for complex logic.
Use Cases
Hybrid search is relevant in the following scenarios:
- Queries with intent and details, e.g.,
python error 403 forbidden— the error code via BM25, the description via KNN. - RAG pipelines for LLMs — feeding the most relevant text chunks.
- Catalogs with structured (product models) and unstructured data (descriptions).
- Unpredictable user patterns — exact phrases or descriptive language.
In e-commerce, hybrid search processes names, descriptions, and visual embeddings in parallel.
RRF Mechanism
RRF aggregates ranks without normalizing scores. Formula: 1 / (rank_constant + rank). Default rank_constant=60.
Example merging top-3:
| Document | BM25 Rank | KNN Rank | RRF Score |
|----------|-----------|----------|-----------|
| Doc A | 1 | 2 | 0.0325 |
| Doc C | 3 | 1 | 0.0323 |
| Doc B | 2 | - | 0.0161 |
| Doc D | - | 3 | 0.0159 |
Doc A leads due to high positions in both lists. RRF is preferable to score-based merging as it doesn't require scale calibration.
Subqueries (MATCH and KNN) execute in parallel; filters apply to all.
Practical Example with Knowledge Bases
In support databases, query "Cannot connect to server" + error code E-5020.
KNN results:
| # | Title | Distance |
|---|-------|----------|
|1| E-5030: DNS | 0.572 |
|2| E-2091: Timeout | 0.583 |
|3| E-5020: SSL | 0.605 |
Hybrid with MATCH('E-5020') and KNN:
SELECT title, hybrid_score()
FROM support_articles
WHERE knn(embedding, 'can not connect to the server')
AND MATCH('E-5020')
LIMIT 5
OPTION fusion_method='rrf';
| # | Title | Hybrid Score |
|---|-------|--------------|
|1| Error E-5020: SSL Certificate Mismatch | 0.032 |
|2| E-5030 | 0.016 |
|3| E-2091 | 0.016 |
E-5020 rises to first place: BM25 captures the exact code, KNN captures the context.
Running Hybrid Search
Automatic mode with hybrid_match():
SELECT id, hybrid_score()
FROM products
WHERE hybrid_match('running shoes');
JSON API:
POST /search
{
"table": "products",
"hybrid": { "query": "running shoes" }
}
Manticore generates embeddings, performs searches, and merges results.
Explicit control:
SELECT id, hybrid_score()
FROM products
WHERE match('running shoes')
AND knn(embedding, (0.12, 0.45, 0.78, ...))
OPTION fusion_method='rrf';
Available metrics: hybrid_score(), weight() (BM25), knn_dist().
Fusion Settings
rank_constant: dominance of top positions (lower values increase emphasis).fusion_weights: subquery weights, e.g., (text=0.5, knn=0.3).window_size: volume of intermediate results.
Multiple KNN:
SELECT id, hybrid_score()
FROM products
WHERE match('running shoes') AS text
AND knn(title_vec, (0.12, 0.45, ...)) AS title_sim
AND knn(image_vec, (0.88, 0.21, ...)) AS image_sim
OPTION fusion_method='rrf',
fusion_weights=(text=0.5, title_sim=0.3, image_sim=0.2);
Key Takeaways
- Hybrid search distributes signals: identifiers via BM25, meaning via KNN.
- RRF ensures stable merging without calibration.
- Support for multiple vector spaces for multimodal data.
- Parallel execution minimizes latency.
- Automatic embedding generation simplifies integration.
— Editorial Team
No comments yet.