Fix/24 hybrid retriever keyword weighting - #764
Open
GarabKDorji wants to merge 7 commits into
Open
Conversation
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
This PR updates the hybrid retriever’s scoring formula so that a strong keyword match cannot independently promote a chunk with little or no semantic relevance. The keyword score now acts as a controlled boost to the vector score instead of contributing as a separate additive term. This keeps semantic relevance as the foundation of the final ranking while still rewarding chunks found by both vector and keyword search.
Issue
Closes #24
Changes
-Updated the hybrid scoring formula in rag/retriever/hybrid.py.
-Changed the keyword contribution from an independent additive term to a contribution scaled by the vector score.
-Prevented keyword-only chunks with no semantic relevance from receiving a positive blended score.
-Preserved the existing default weights of 0.7 for vector search and 0.3 for keyword search.
-Added or updated regression tests in tests/unit/test_hybrid.py to cover the incorrect ranking behavior.
-Updated JOURNAL.md with implementation details, testing results, and investigation findings.
Testing
make test-unit)make test-integration)make lint)make typecheck)tests/unit/test_hybrid.py — 6 passed, 0 failed.
The two reproduction tests committed in Week 8 now pass with no change to their data:
-test_semantic_vector_chunk_should_outrank_keyword_only_chunk
-test_keyword_score_boosts_weaker_vector_chunk_above_stronger_vector_chunk
The four pre-existing tests are unaffected and the both-searches boost still produces the maximum score of 1.0, and the min_score, empty-result and max_chunks paths are unchanged.
Pre-existing failures
Before making my changes:
The type checker reported missing return-type annotations in:
After making my changes, I reran the relevant checks and confirmed that all six targeted hybrid retriever tests pass. My changes did not introduce additional failures. The remaining project-wide failures are pre-existing and unrelated to this contribution.
Screenshots / Demo
Notes for Reviewers