Skip to content

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

Closed

Description

@ajianaz

Summary

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

Background

Industry research (Sibyl-Memory benchmark, vstash paper arxiv:2604.15484, sqlite-memory, wmem) shows that hybrid FTS5 + vector search outperforms either approach alone:

  • FTS5 wins on exact entity lookup, named entity queries, structured data (e.g., "alamat PT Maju Jaya")
  • Vector wins on conceptual/semantic queries, paraphrased queries (e.g., "cara deploy yang kita bahas bulan lalu")
  • Hybrid (RRF) merges both, taking the best of each

Sibyl Benchmark Evidence

  • FTS5-only: 350/350 retrieval on structured data (500 companies, 1 token difference)
  • But vector systems fail on near-duplicates where 1 token distinguishes entities
  • All vector systems scored 0/50 on trap questions (fake entities) — always returns nearest neighbor

Implementation Plan

1. FTS5 Virtual Table

CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
    content,
    tags,
    namespace,
    content=memories,
    content_rowid=rowid
);

-- Triggers to keep FTS5 in sync
CREATE TRIGGER memories_ai AFTER INSERT ON memories BEGIN
    INSERT INTO memories_fts(rowid, content, tags, namespace)
    VALUES (new.rowid, new.content, new.tags, new.namespace);
END;

CREATE TRIGGER memories_ad AFTER DELETE ON memories BEGIN
    INSERT INTO memories_fts(memories_fts, rowid, content, tags, namespace)
    VALUES (delete, new.rowid, new.content, new.tags, new.namespace);
END;

2. Dual Search Execution

pub fn recall_hybrid(&self, query: &str, limit: usize) -> Vec<SearchResult> {
    let vector_results = self.vector_search(query, limit * 3);
    let fts_results = self.fts5_search(query, limit * 3);
    rrf_merge(vector_results, fts_results, limit)
}

3. RRF Merge Algorithm

fn rrf_merge(vector: Vec<SearchResult>, fts: Vec<SearchResult>, k: u32 = 60) -> Vec<SearchResult> {
    // Standard RRF: score = 1/(k + rank)
    // Each result gets score from both channels, summed
}

4. Config

[recall]
strategy = "hybrid"    # "hybrid" | "vector" | "fts5"
rrf_k = 60             # RRF constant
fts5_weight = 1.0      # FTS5 channel weight
vector_weight = 1.0    # Vector channel weight

5. Schema Migration

  • Add FTS5 virtual table + triggers in schema.rs
  • Existing search_content (LIKE-based) → upgrade to FTS5
  • recall command auto-routes: hybrid when FTS5 exists, vector-only otherwise

Scope

  • New module: uteke-core/src/memory/fts5.rs
  • Modify: store.rs (FTS5 table creation + triggers)
  • Modify: operations.rs (hybrid recall logic)
  • Modify: config.rs (recall strategy config)
  • Modify: schema.rs (migration for existing DBs)

Acceptance Criteria

  • FTS5 virtual table auto-created on init
  • recall uses hybrid by default when FTS5 exists
  • Config toggle: hybrid / vector-only / fts5-only
  • Backward compatible: existing DBs get FTS5 table on next open
  • Benchmark: hybrid recall >= vector-only on semantic queries, >> vector-only on exact match

References

Activity

  1. added
    enhancement
    scope:core
    priority:high
    next-up
    on Jun 9, 2026
  2. added a commit that references this issue on Jun 10, 2026
  3. added a commit that references this issue on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementnext-uppriority:highscope:core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions