Repository navigation
feat: Enhance semantic search scoring with multi-chunk breadth boost - #781
Conversation
…(Issue #778) Improves semantic search ranking by considering both chunk similarity and breadth of relevance. Documents with multiple relevant chunks now rank higher than those with a single high-scoring chunk. ## Changes ### Scoring Algorithm (Issue #778) - New composite score formula: `max_similarity * (1 + 0.3 * log10(matching_chunks))` - Single-chunk documents score unchanged (log10(1) = 0) - Multi-chunk documents get breadth boost (e.g., 5 chunks → 1.21x multiplier) ### Updated `EmbeddingSearchResult` Model - Added `score`: Composite relevance score (primary ranking) - Added `max_similarity`: Best chunk similarity (raw cosine) - Added `matching_chunks`: Count of chunks above threshold - Removed `similarity` field (replaced by `score` and `max_similarity`) ### Enhanced SQL Query - Subquery calculates per-chunk similarity before grouping - Counts chunks exceeding threshold per node - Results sorted by composite score in Rust (DB pre-sorts by max_similarity) - Increased KNN limit from 3x to 5x to capture more chunks per node ### Test Coverage - New `test_multi_chunk_scoring_breadth_boost` validates ranking behavior - Updated existing tests to use new field names - Verifies breadth boost formula correctness ## Example Results | Document | Max Sim | Chunks | Score | |----------|---------|--------|-------| | Doc A | 0.85 | 1 | 0.85 | | Doc B | 0.80 | 5 | 0.97 | Doc B now ranks higher due to broader relevance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review: PR #781 - Semantic Search Multi-Chunk ScoringReview Type: Initial Review Requirements Check (Issue #778)
Summary: 3/3 required criteria met, 0/1 optional criteria implemented. Architectural AssessmentThe implementation follows a clean, well-documented approach:
Code Review Findings🟢 Positive Observations
🟡 Suggested Improvements
Security Review✅ No security concerns identified:
Performance Analysis✅ Performance impact is minimal:
The PR description confirms tests passed with acceptable performance. Recommendation✅ APPROVE This is a well-designed enhancement that:
The change is a clear net positive for the codebase and improves semantic search quality by rewarding broader document relevance. Principal Engineer AI Review |
malibio
left a comment
There was a problem hiding this comment.
Review complete: APPROVE recommended. Clean, well-tested implementation of multi-chunk breadth scoring. All required acceptance criteria met. See detailed review in comments above.
Address code review feedback: document the invariant that matching_chunks from SQL count() is always >= 1, and explain why the .max(1.0) guard exists as defensive programming against edge cases. Addresses reviewer recommendation from PR #781. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Review Feedback Addressed✅ Addressed (1 recommendation)
⏭️ Skipped (2 recommendations)
📊 Summary
Review feedback addressed by Claude Code |
…781) * feat: Enhance semantic search scoring with multi-chunk breadth boost (Issue #778) Improves semantic search ranking by considering both chunk similarity and breadth of relevance. Documents with multiple relevant chunks now rank higher than those with a single high-scoring chunk. ## Changes ### Scoring Algorithm (Issue #778) - New composite score formula: `max_similarity * (1 + 0.3 * log10(matching_chunks))` - Single-chunk documents score unchanged (log10(1) = 0) - Multi-chunk documents get breadth boost (e.g., 5 chunks → 1.21x multiplier) ### Updated `EmbeddingSearchResult` Model - Added `score`: Composite relevance score (primary ranking) - Added `max_similarity`: Best chunk similarity (raw cosine) - Added `matching_chunks`: Count of chunks above threshold - Removed `similarity` field (replaced by `score` and `max_similarity`) ### Enhanced SQL Query - Subquery calculates per-chunk similarity before grouping - Counts chunks exceeding threshold per node - Results sorted by composite score in Rust (DB pre-sorts by max_similarity) - Increased KNN limit from 3x to 5x to capture more chunks per node ### Test Coverage - New `test_multi_chunk_scoring_breadth_boost` validates ranking behavior - Updated existing tests to use new field names - Verifies breadth boost formula correctness ## Example Results | Document | Max Sim | Chunks | Score | |----------|---------|--------|-------| | Doc A | 0.85 | 1 | 0.85 | | Doc B | 0.80 | 5 | 0.97 | Doc B now ranks higher due to broader relevance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * style: Apply cargo fmt formatting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Add clarifying comment for matching_chunks guard Address code review feedback: document the invariant that matching_chunks from SQL count() is always >= 1, and explain why the .max(1.0) guard exists as defensive programming against edge cases. Addresses reviewer recommendation from PR #781. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…781) * feat: Enhance semantic search scoring with multi-chunk breadth boost (Issue #778) Improves semantic search ranking by considering both chunk similarity and breadth of relevance. Documents with multiple relevant chunks now rank higher than those with a single high-scoring chunk. ## Changes ### Scoring Algorithm (Issue #778) - New composite score formula: `max_similarity * (1 + 0.3 * log10(matching_chunks))` - Single-chunk documents score unchanged (log10(1) = 0) - Multi-chunk documents get breadth boost (e.g., 5 chunks → 1.21x multiplier) ### Updated `EmbeddingSearchResult` Model - Added `score`: Composite relevance score (primary ranking) - Added `max_similarity`: Best chunk similarity (raw cosine) - Added `matching_chunks`: Count of chunks above threshold - Removed `similarity` field (replaced by `score` and `max_similarity`) ### Enhanced SQL Query - Subquery calculates per-chunk similarity before grouping - Counts chunks exceeding threshold per node - Results sorted by composite score in Rust (DB pre-sorts by max_similarity) - Increased KNN limit from 3x to 5x to capture more chunks per node ### Test Coverage - New `test_multi_chunk_scoring_breadth_boost` validates ranking behavior - Updated existing tests to use new field names - Verifies breadth boost formula correctness ## Example Results | Document | Max Sim | Chunks | Score | |----------|---------|--------|-------| | Doc A | 0.85 | 1 | 0.85 | | Doc B | 0.80 | 5 | 0.97 | Doc B now ranks higher due to broader relevance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * style: Apply cargo fmt formatting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Add clarifying comment for matching_chunks guard Address code review feedback: document the invariant that matching_chunks from SQL count() is always >= 1, and explain why the .max(1.0) guard exists as defensive programming against edge cases. Addresses reviewer recommendation from PR #781. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…781) * feat: Enhance semantic search scoring with multi-chunk breadth boost (Issue #778) Improves semantic search ranking by considering both chunk similarity and breadth of relevance. Documents with multiple relevant chunks now rank higher than those with a single high-scoring chunk. ## Changes ### Scoring Algorithm (Issue #778) - New composite score formula: `max_similarity * (1 + 0.3 * log10(matching_chunks))` - Single-chunk documents score unchanged (log10(1) = 0) - Multi-chunk documents get breadth boost (e.g., 5 chunks → 1.21x multiplier) ### Updated `EmbeddingSearchResult` Model - Added `score`: Composite relevance score (primary ranking) - Added `max_similarity`: Best chunk similarity (raw cosine) - Added `matching_chunks`: Count of chunks above threshold - Removed `similarity` field (replaced by `score` and `max_similarity`) ### Enhanced SQL Query - Subquery calculates per-chunk similarity before grouping - Counts chunks exceeding threshold per node - Results sorted by composite score in Rust (DB pre-sorts by max_similarity) - Increased KNN limit from 3x to 5x to capture more chunks per node ### Test Coverage - New `test_multi_chunk_scoring_breadth_boost` validates ranking behavior - Updated existing tests to use new field names - Verifies breadth boost formula correctness ## Example Results | Document | Max Sim | Chunks | Score | |----------|---------|--------|-------| | Doc A | 0.85 | 1 | 0.85 | | Doc B | 0.80 | 5 | 0.97 | Doc B now ranks higher due to broader relevance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * style: Apply cargo fmt formatting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Add clarifying comment for matching_chunks guard Address code review feedback: document the invariant that matching_chunks from SQL count() is always >= 1, and explain why the .max(1.0) guard exists as defensive programming against edge cases. Addresses reviewer recommendation from PR #781. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
Improves semantic search ranking by considering both chunk similarity and breadth of relevance. Documents with multiple relevant chunks now rank higher than those with a single high-scoring chunk (Issue #778).
score = max_similarity * (1 + 0.3 * log10(matching_chunks))EmbeddingSearchResult: Now includesscore,max_similarity, andmatching_chunksfieldsExample Results
Doc B ranks higher due to broader relevance.
Test plan
bun run rust:test- 674 tests passedbun run test- 3431 tests passedtest_multi_chunk_scoring_breadth_boosttest passescargo clippy- no warningsbun run quality:fix- no issuesCloses #778
🤖 Generated with Claude Code