Problem
When a user query contains FTS5 metacharacters (e.g. apostrophe ', double quotes "), text_search() passes the raw string to FTS5, producing:
_fathomdb.SqliteError: fts5: syntax error near "'"
This was hit in production when Memex's retrieval layer searched for User's name — the apostrophe broke the FTS5 query parser.
Reproduction
engine = Engine.open("test.db")
# ... register a collection with text_search support ...
q = engine.nodes("some_kind").text_search("User's name", limit=10)
q.execute() # -> SqliteError: fts5: syntax error near "'"
Expected behavior
text_search() should escape FTS5 metacharacters in the query string before passing it to the FTS5 MATCH expression. At minimum, double any embedded double-quotes and wrap each token in double quotes, e.g. "User's" "name".
Context
- Discovered via Memex service logs (
fathom_store.py:2544 → _query.py:254)
- The calling code has no way to pre-escape since the query goes through the AST builder
- Affects any
text_search() call where the query originates from user input
Problem
When a user query contains FTS5 metacharacters (e.g. apostrophe
', double quotes"),text_search()passes the raw string to FTS5, producing:This was hit in production when Memex's retrieval layer searched for
User's name— the apostrophe broke the FTS5 query parser.Reproduction
Expected behavior
text_search()should escape FTS5 metacharacters in the query string before passing it to the FTS5 MATCH expression. At minimum, double any embedded double-quotes and wrap each token in double quotes, e.g."User's" "name".Context
fathom_store.py:2544 → _query.py:254)text_search()call where the query originates from user input