You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enhance semantic search scoring to account for multiple matching chunks #778
Currently, semantic search groups embeddings by node and returns math::max(similarity) as the relevance score. This means a document is scored by its single best-matching chunk only.
Current query logic (surreal_store.rs:4666-4679):
SELECT
node,
math::max(vector::similarity::cosine(vector, $query_vector)) AS similarity
FROM embedding
WHERE stale = false AND vector <|{knn_limit}|> $query_vector
GROUP BY node
This doesn't capture breadth of relevance - a document with 5 chunks all scoring 0.8 is arguably more relevant than a document with 1 chunk scoring 0.85.
Proposed Enhancement
Improve the scoring algorithm to consider multiple matching chunks. Options:
Count matches: Include number of chunks above threshold in scoring
Average top-N: Average the top 3 chunk scores instead of just max
Beyond multi-chunk scoring, we should consider hybrid search combining semantic similarity with BM25 keyword matching.
Problem with Pure Semantic Search
A query like "testing concurrency investigation" only scores 0.65 against a document titled "Test Suite Concurrency Investigation" - despite the near-exact title match. This happens because:
The title gets diluted by all the body content in chunked embeddings
Semantic search doesn't give extra weight to exact keyword matches
Activity
malibio commentedon Dec 23, 2025
Additional Enhancement: BM25 Hybrid Search
Beyond multi-chunk scoring, we should consider hybrid search combining semantic similarity with BM25 keyword matching.
Problem with Pure Semantic Search
A query like "testing concurrency investigation" only scores 0.65 against a document titled "Test Suite Concurrency Investigation" - despite the near-exact title match. This happens because:
Proposed Solution: Hybrid BM25 + Semantic
Where:
Implementation Options
SurrealDB native full-text search
DEFINE ANALYZERwith tokenizers/filtersDEFINE INDEX ... SEARCH ANALYZERsearch::score()function for BM25 rankingTitle boosting (simpler alternative)
Benefits
References
malibio commentedon Dec 23, 2025
Test baseline: Frontend 3431 passed, Rust 674 passed
feat: Enhance semantic search scoring with multi-chunk breadth boost …
feat: Enhance semantic search scoring with multi-chunk breadth boost (#…
feat: Enhance semantic search scoring with multi-chunk breadth boost (#…
feat: Enhance semantic search scoring with multi-chunk breadth boost (#…
feat: Enhance semantic search scoring with multi-chunk breadth boost (#…