Skip to content

fix(search): quote underscored terms in FTS5 query sanitization - #16827

Closed
crayfish-ai wants to merge 1 commit into
NousResearch:mainfrom
crayfish-ai:fix-fts5-v3
Closed

fix(search): quote underscored terms in FTS5 query sanitization#16827
crayfish-ai wants to merge 1 commit into
NousResearch:mainfrom
crayfish-ai:fix-fts5-v3

Conversation

@crayfish-ai

Copy link
Copy Markdown
Contributor

Summary

Fix FTS5 query sanitization to properly quote underscored terms.

Problem

_sanitize_fts5_query Step 5 regex [.-] was missing underscore, so underscored terms like sp_new were NOT quoted and FTS5 split them into AND tokens (sp AND new), causing searches to return 0 results even when matching content exists.

Fix

Change Step 5 regex from [.-] to [._-] so underscored terms are properly quoted as "sp_new" and matched as prefix search.

Files: 2 changed, +26/-2 lines

FTS5 default tokenizer splits 'sp_new1' into tokens 'sp' and 'new1'.
Without quoting, a search for 'sp_new' becomes an AND query
('sp AND new') that fails to match rows indexed as 'sp_new1'.

Fix: add underscore to the character class in Step 5 regex
([.-] -> [._-]) so underscored terms are wrapped in double quotes.

Also adds test_sanitize_fts5_quotes_underscored_terms.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Apr 28, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Note: this is the third attempt at this fix (after closed #16755 and #16765). Prior PRs were closed due to scope creep (12-16 files changed vs 2 described). This version looks clean — 2 files changed as described.

@teknium1

Copy link
Copy Markdown
Contributor

Salvaged via #16915 — your commit was cherry-picked onto current main with your authorship preserved. Thanks for the fix!

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants