feat(store): replace FTS5 default ranking with weighted BM25 scoring#245
Open
Snakeblack wants to merge 1 commit intoGentleman-Programming:mainfrom
Open
feat(store): replace FTS5 default ranking with weighted BM25 scoring#245Snakeblack wants to merge 1 commit intoGentleman-Programming:mainfrom
Snakeblack wants to merge 1 commit intoGentleman-Programming:mainfrom
Conversation
Replace fts.rank with bm25(observations_fts, 5.0, 1.0, 0.0, 0.0, 0.0, 3.0) to apply weighted BM25 scoring in FTS5 search queries. Weights: title=5, content=1, tool_name=0, type=0, project=0, topic_key=3. Direct topic_key route (Rank=-1000) remains unchanged. Closes Gentleman-Programming#241
There was a problem hiding this comment.
Pull request overview
Updates the SQLite FTS5 search ranking used by Store.Search to use weighted BM25 scoring so matches in higher-signal columns (e.g., title, topic_key) rank ahead of lower-signal matches.
Changes:
- Replace
fts.rankwith a weightedbm25(observations_fts, ...) AS rankscore in the FTS5 search query. - Update
ORDER BYto sort by the newrankalias. - Add tests covering ranking expectations, the direct
topic_keyroute guard, and query-safety regression checks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/store/store.go |
Switches FTS5 ranking from fts.rank to weighted BM25 and orders by the BM25 alias. |
internal/store/store_test.go |
Adds regression tests for BM25 ranking behavior, direct topic_key behavior, and edge-case query safety. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+6803
to
+6810
| if !strings.Contains(results[0].Title, "kubernetes") { | ||
| t.Fatalf("expected first result to have 'kubernetes' in title (title-match), got %q", results[0].Title) | ||
| } | ||
| if results[0].TopicKey != nil && strings.Contains(*results[0].TopicKey, "kubernetes") { | ||
| // First result should be the title-match, not the topic-match | ||
| } else if !strings.Contains(results[0].Title, "kubernetes") { | ||
| t.Fatalf("first result should be the title-match observation") | ||
| } |
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
Replace
fts.rankwithbm25(observations_fts, 5.0, 1.0, 0.0, 0.0, 0.0, 3.0)in the FTS5 search query to apply weighted BM25 scoring.Weights
What changed
store.go: replacedfts.rankwithbm25()call and updatedORDER BYto use the aliasstore_test.go: TDD cycle covering ranking order, direct topic_key route guard, and edge-case query safetyTDD Evidence
Notes
TestNewErrorBranchesis a pre-existing Windows file-locking failure, unrelated to this changeCloses #241