fix(search): match multi-word FTS queries#306
Merged
Conversation
Replace blanket phrase-wrapping in _sanitize_fts5_query with tokenize -> drop stopwords/operators -> quote each term -> OR. Multi-word queries (every query the agent sends for papers/discussions/FAQ/docstrings) were exact-phrase matched and returned nothing despite populated databases. Still injection-safe (each term individually quoted); results ordered by existing BM25 rank. Affects all 6 knowledge-search call sites. Closes #305
Address PR review: - strengthen test_sanitize_fts5_operators to assert every term is individually quoted (no bare operator can reach MATCH) - drop 'list' and 'use' from stopwords (meaningful EEGLAB/MATLAB nouns) so multi-word queries like 'list channels' don't silently lose a term
Member
Author
Review (Sonnet, pr-review-toolkit) + resolutionsPasses: FTS5 injection safety sound (regex strips all operator chars, each term individually quoted); fallback branch correct for all-stopword/all-symbol input; single-term stopword queries fall back safely; regression genuinely fixed with real SQLite (no mocks); no new OperationalError paths. Important findings addressed:
No critical issues. |
BEP keyword search is OR-based and rank-ordered after the FTS fix, so the
old phrase-only no-match query ('...data type...') now matches BEPs that
mention 'data'. Use a genuinely non-matching query to keep the
no-results path covered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Papers (and all knowledge sources) were synced but never found at query time. Root cause:
_sanitize_fts5_query()wrapped the entire query in quotes, forcing an exact consecutive-phrase FTS5 match. Every multi-word query the agent sends returned zero rows.Proven on the live dev
eeglab.db(1940 papers):ICA EEGLABpapers about ICA artifact removalChange
_sanitize_fts5_querynow: tokenize -> drop stopwords + operator chars -> quote each term individually -> OR them. Results keep the existing BM25rankordering, so the best matches surface first.pop_runica,clean_rawdata) are preserved as adjacency phrases.Tests
TestFTS5Sanitizationfor the new OR-of-terms output + injection safety.293 passedacross knowledge + tool suites; ruff clean.Closes #305