Skip to content

feat(#250): FTS5 hybrid search with Reciprocal Rank Fusion (RRF) - #261

Merged
ajianaz merged 3 commits into
developfrom
feat/250-fts5-hybrid-rrf
Jun 10, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/250-fts5-hybrid-rrf

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add FTS5 full-text search as a parallel retrieval channel alongside vector similarity search, merged via Reciprocal Rank Fusion (RRF).

Changes

New module: memory/fts5.rs

  • FTS5 virtual table with content=memories (shadow table)
  • Auto-sync triggers (INSERT/DELETE/UPDATE)
  • Phrase search + token-OR fallback for broader matching
  • rebuild_fts5() for migration from existing data

Schema migration v1 → v2

  • Auto-creates FTS5 virtual table + triggers
  • Rebuilds FTS5 index from existing memories
  • Idempotent — safe for new and existing databases

Hybrid recall with RRF

  • RecallStrategy enum: hybrid (default), vector, fts5
  • recall_hybrid() routes by strategy
  • recall_rrf() merges both channels: score = 1/(k + rank_vector) + 1/(k + rank_fts5)
  • Graceful fallback: FTS5 fail → vector-only, vector fail → FTS5-only
  • Deprecated memories excluded from FTS5 results

Benchmark rationale (from issue)

Query type Vector FTS5 Hybrid
Semantic/conceptual ✅ strong ❌ weak ✅ best
Exact entity lookup ❌ weak (near-duplicate trap) ✅ exact match ✅ best
Named entity queries ❌ confused by near-duplicates ✅ precise ✅ best

Verification

  • ✅ cargo clippy --all-targets -- -D warnings — clean
  • ✅ cargo test — 107/107 pass (6 new FTS5 tests)
  • ✅ Backward compatible: existing DBs get FTS5 table on next open
  • ✅ FTS5-only, vector-only, and hybrid modes all tested

Fixes: #250

- New module: memory/fts5.rs — FTS5 virtual table, triggers, phrase/token search
- Schema migration v1→v2: auto-create FTS5 table + rebuild index for existing DBs
- RecallStrategy enum: hybrid (default), vector, fts5
- recall_hybrid() routes by strategy
- recall_rrf() merges vector + FTS5 via Reciprocal Rank Fusion (k=60)
- FTS5 triggers keep index in sync on insert/delete/update
- Phrase search with token-OR fallback for broader matching
- Deprecated memories excluded from FTS5 results
- Graceful fallback: FTS5 fail → vector-only, vector fail → FTS5-only
- 6 new tests: search, tokens, namespace, rebuild, deprecated, exists

Fixes: #250
@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@ajianaz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 40 minutes and 31 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 17c0e177-b9f6-4b9c-8371-2c085d1e8045

📥 Commits

Reviewing files that changed from the base of the PR and between ba2ff65 and e2deae9.

📒 Files selected for processing (7)
  • crates/uteke-core/src/lib.rs
  • crates/uteke-core/src/memory/fts5.rs
  • crates/uteke-core/src/memory/mod.rs
  • crates/uteke-core/src/memory/schema.rs
  • crates/uteke-core/src/memory/store.rs
  • crates/uteke-core/src/memory/types.rs
  • crates/uteke-core/src/operations.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/250-fts5-hybrid-rrf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (4)

  • crates/uteke-core/src/memory/fts5.rs:88 — In search_fts5, the FTS5 rank column returns BM25 values which are negative and unbounded (e.g., -15.3, -0.5). The expression (1.0 + rank).clamp(0.0, 1.0) in recall_fts5_only (operations.rs) will produce 0.0 for any BM25 score ≤ -1.0, which is most results. This means nearly all FTS5 results get a score of 0.0, making the score meaningless for ranking or display.
  • crates/uteke-core/src/operations.rs:282 — The score conversion ((1.0 + rank).clamp(0.0, 1.0)) as f32 is broken for BM25 ranks. FTS5 BM25 returns negative values (e.g., -15.3), so 1.0 + (-15.3) = -14.3, which clamps to 0.0. Almost all results will have score 0.0, making the score field useless for consumers of this API.
  • crates/uteke-core/src/operations.rs:368 — The normalization score / (2.0 / (RRF_K as f64 + 1.0)) assumes the maximum RRF score is 2.0 / (k+1), but this is only true if a single result is rank 0 in both lists. With limit * 3 results from each source, the theoretical max is correct, but the .min(1.0) clamp masks potential issues. More importantly, the denominator 2.0 / 61.0 ≈ 0.0328 means scores get inflated by ~30x, which may not be the intended behavior.
  • crates/uteke-core/src/operations.rs:376 — At line 376, memories.remove(&id).unwrap() can panic if the ID exists in rrf_scores but not in memories. While this shouldn't happen given the current logic (both are populated together), it's a defensive programming concern. If the logic ever changes, this becomes a runtime panic.

Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit 209c42d into develop Jun 10, 2026
9 checks passed
@ajianaz
ajianaz deleted the feat/250-fts5-hybrid-rrf branch June 10, 2026 01:27
ajianaz added a commit that referenced this pull request Jun 10, 2026
* fix: address Cora review critical issues (7 items)

FTS5 (from PR #261):
- Fix BM25 score conversion: rank is negative unbounded, clamping to
  0..1 produced 0.0 for all results. Now uses rank-based scoring
  (placeholder 1.0) since actual ranking is done by RRF in hybrid.
- Fix RRF normalization: denominator calculation was correct but
  .min(1.0) was misleading. Replaced with explicit .clamp(0.0, 1.0).
- Replace memories.remove().unwrap() with expect() for clearer panic msg.

Metadata (from PR #262):
- Replace as_object_mut().unwrap() with if-let pattern to prevent panic.
- Server-mode remember now includes entity/category/meta in request body
  instead of silently ignoring them.

* style: cargo fmt
ajianaz added a commit that referenced this pull request Aug 13, 2026
* feat(#250): FTS5 hybrid search with Reciprocal Rank Fusion

- New module: memory/fts5.rs — FTS5 virtual table, triggers, phrase/token search
- Schema migration v1→v2: auto-create FTS5 table + rebuild index for existing DBs
- RecallStrategy enum: hybrid (default), vector, fts5
- recall_hybrid() routes by strategy
- recall_rrf() merges vector + FTS5 via Reciprocal Rank Fusion (k=60)
- FTS5 triggers keep index in sync on insert/delete/update
- Phrase search with token-OR fallback for broader matching
- Deprecated memories excluded from FTS5 results
- Graceful fallback: FTS5 fail → vector-only, vector fail → FTS5-only
- 6 new tests: search, tokens, namespace, rebuild, deprecated, exists

Fixes: #250

* style: cargo fmt

* fix: use derive Default for RecallStrategy (clippy compat)
ajianaz added a commit that referenced this pull request Aug 13, 2026
* fix: address Cora review critical issues (7 items)

FTS5 (from PR #261):
- Fix BM25 score conversion: rank is negative unbounded, clamping to
  0..1 produced 0.0 for all results. Now uses rank-based scoring
  (placeholder 1.0) since actual ranking is done by RRF in hybrid.
- Fix RRF normalization: denominator calculation was correct but
  .min(1.0) was misleading. Replaced with explicit .clamp(0.0, 1.0).
- Replace memories.remove().unwrap() with expect() for clearer panic msg.

Metadata (from PR #262):
- Replace as_object_mut().unwrap() with if-let pattern to prevent panic.
- Server-mode remember now includes entity/category/meta in request body
  instead of silently ignoring them.

* style: cargo fmt
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: FTS5 hybrid search with Reciprocal Rank Fusion (RRF)

1 participant