Skip to content

add support for fts in mm grep using bm25 - #180

Open
nwaughachukwuma wants to merge 6 commits into
mainfrom
feat/hybrid-retrieval
Open

add support for fts in mm grep using bm25#180
nwaughachukwuma wants to merge 6 commits into
mainfrom
feat/hybrid-retrieval

Conversation

@nwaughachukwuma

Copy link
Copy Markdown
Collaborator

Summary

BM25 (Best Match 25) is the standard ranking function used by full-text search (fts) engines to score and rank documents by relevance to a query. This PR allows using fts with bm25 when --semantic/-s flag is specified and falls back to a %LIKE% query.

  flowchart LR                                                                                          
      A["search_chunks_fts()"] --> B{"FTS5?"}                                                   
      B -- yes --> C["search_chunks_bm25"]                                                              
      B -- no --> F["LIKE fallback"]                                                                    
      C --> D{"query ≥ 3 chars?"}                                                                       
      D -- no --> E["return []"]                                                                
      D -- yes --> G["build filters + phrase"]                                                          
      G --> I["FTS5 MATCH + bm25&#40;&#41;<br/>ORDER BY bm25 LIMIT ?"]                                  
      I --> J{"non-empty?"}                                                                             
      J -- yes --> L["return BM25 rows"]                                                                
      J -- no --> F                                                                                     
      F --> N["LIKE %q% scan<br/>→ return rows"]                                                        
Loading

@nwaughachukwuma
nwaughachukwuma requested a review from spillai July 11, 2026 12:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces FTS5 full-text search capabilities over the chunks table using a trigram tokenizer and BM25 ranking, including automatic trigger-based synchronization and idempotent backfilling of legacy data. The reviewer feedback highlights two key improvements: first, avoiding a redundant and expensive fallback to a LIKE scan when FTS5 is available but returns no results; second, using the more robust pragma module_list instead of pragma compile_options to detect FTS5 support and prevent false negatives on certain SQLite builds.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/mm/store/db.py Outdated
Comment thread python/mm/store/db.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

1 participant