feat(serve): hybrid text+visual search with BM25 and Reciprocal Rank Fusion#97
Open
aafaq-rashid-comprinno wants to merge 1 commit into
Open
Conversation
…Fusion
Add an opt-in hybrid search mode that fuses FAISS visual results with
BM25 text results using Reciprocal Rank Fusion (RRF). This improves
precision on text-heavy queries (entity names, specific facts) while
retaining visual retrieval for tables/charts/diagrams.
Implementation:
- New module: serve/src/pixelrag_serve/hybrid.py
- BM25Index: in-memory inverted index with standard BM25 scoring (k1=1.2, b=0.75)
- reciprocal_rank_fusion(): merges multiple ranked lists (k=60, per Cormack et al.)
- Auto-builds from articles.json titles/URLs, caches as bm25_index.json
- API change: SearchRequest gains `hybrid: bool` field (default false)
- When hybrid=true, BM25 text results are fused with FAISS visual results
per-query before result assembly
Usage:
curl -X POST http://localhost:30001/search \
-d '{"queries": [{"text": "Albert Einstein"}], "n_docs": 5, "hybrid": true}'
8 new tests covering BM25 scoring, disambiguation, save/load, RRF fusion,
and articles.json integration.
|
@aafaq-rashid-comprinno is attempting to deploy a commit to the andylizf's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in hybrid search that fuses FAISS visual results with BM25 text results using Reciprocal Rank Fusion (RRF, Cormack et al. 2009). This improves precision on text-heavy queries (entity names, specific facts) while retaining visual retrieval for tables/charts/diagrams.
Problem
Pure visual search struggles with text-only queries like "Albert Einstein" when the visual embedding doesn't strongly match a specific article. Adding a lightweight text signal improves recall for named entities and factual lookups without degrading visual results.
Implementation
New module:
serve/src/pixelrag_serve/hybrid.pyBM25Index— in-memory inverted index with standard BM25 scoring (k1=1.2, b=0.75)reciprocal_rank_fusion()— merges multiple ranked lists (k=60 constant)load_or_build_bm25()— auto-builds fromarticles.jsontitles/URLs, caches asbm25_index.jsonAPI change
SearchRequestgainshybrid: boolfield (defaultfalse— fully backward compatible).When
hybrid=true:Usage
curl -X POST http://localhost:30001/search \ -d '{ "queries": [{"text": "Albert Einstein"}], "n_docs": 5, "hybrid": true }'Testing
ruff checkcleanFuture work