Skip to content

feat(store): replace FTS5 default ranking with weighted BM25#526

Open
daniel-baf wants to merge 1 commit into
Gentleman-Programming:mainfrom
daniel-baf:feat/weighted-bm25-ranking
Open

feat(store): replace FTS5 default ranking with weighted BM25#526
daniel-baf wants to merge 1 commit into
Gentleman-Programming:mainfrom
daniel-baf:feat/weighted-bm25-ranking

Conversation

@daniel-baf

@daniel-baf daniel-baf commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Closes #241

PR Type

  • type:bug — Bug fix
  • type:feature — New feature
  • type:docs — Documentation only
  • type:refactor — Code refactoring (no behavior change)
  • type:chore — Maintenance, dependencies, tooling
  • type:breaking-change — Breaking change

Summary

  • Replaced SQLite FTS5 default ranking (fts.rank) in Store.Search query with a weighted BM25 query: bm25(observations_fts, 5.0, 1.0, 0.0, 0.0, 0.0, 3.0).
  • Prioritizes matches in title (5.0 weight) and topic_key (3.0 weight) over lower-relevance columns like tool_name or type.
  • Added unit test coverage validating that title matches rank higher than content matches.

Changes

File Change
internal/store/store.go Replace fts.rank with bm25(...) query and update ORDER BY clause
internal/store/store_test.go Add TestSearch_WeightedBM25Ranking unit test

Test Plan

  • Unit tests pass locally: go test ./...
  • E2E tests pass locally: go test -tags e2e ./internal/server/...
  • Manually tested the affected functionality (verified via unit test)

Contributor Checklist

  • I linked an approved issue above (Closes #241)
  • I added exactly one type:* label to this PR
  • I ran unit tests locally
  • I ran e2e tests locally
  • Docs updated (no behavior change needing doc changes)
  • Commits follow conventional commits format
  • No Co-Authored-By trailers in commits

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced search ranking algorithm to deliver more relevant results, with improved prioritization based on where query terms appear in your observations

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0b5d141f-dd26-42fa-a332-b6d97eabe503

📥 Commits

Reviewing files that changed from the base of the PR and between 44faeee and dc1d2b5.

📒 Files selected for processing (2)
  • internal/store/store.go
  • internal/store/store_test.go

📝 Walkthrough

Walkthrough

Store.Search now computes rank via bm25(observations_fts, 5.0, 1.0, 0.0, 0.0, 0.0, 3.0) instead of fts.rank, applying per-column weights to the FTS5 query, and sorts results by that alias. A new test verifies the title-match observation is ranked before the content-match observation.

Changes

Weighted BM25 FTS5 Ranking

Layer / File(s) Summary
BM25 rank projection, ordering, and regression test
internal/store/store.go, internal/store/store_test.go
Store.Search projection replaces fts.rank with bm25(observations_fts, 5.0, 1.0, 0.0, 0.0, 0.0, 3.0) as rank and the ORDER BY clause updated to reference the new alias. TestSearch_WeightedBM25Ranking seeds two observations and asserts the title-matching result precedes the content-matching result.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: replacing FTS5 default ranking with weighted BM25 in the Store.Search function.
Linked Issues check ✅ Passed The PR fully implements all requirements from issue #241: weighted BM25 ranking with specified column weights, only 2 lines of SQL changed, direct topic_key route preserved, and new test validates ranking behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing weighted BM25 ranking as specified in issue #241; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(store): replace FTS5 default ranking with weighted BM25

1 participant