Skip to content

fix(retrieval): make corpus.grep an exact string search (escape LIKE wildcards) - #497

Open
Ayush7614 wants to merge 1 commit into
Ontos-AI:mainfrom
Ayush7614:fix/ayush7614/corpus-grep-exact-string
Open

Ayush7614 wants to merge 1 commit into
Ontos-AI:mainfrom
Ayush7614:fix/ayush7614/corpus-grep-exact-string

Conversation

@Ayush7614

Copy link
Copy Markdown

Problem

corpus.grep interpolated user search terms raw into SQL
LIKE '%...%'. Because LIKE treats %, _, and backslash as wildcards,
a term like 30% matched 30X-style prefixes instead of a literal
30% — contradicting the tool's advertised exact-string-search contract.

Fix

Added _escape_like_literal which escapes backslash, percent, and underscore,
and attached an ESCAPE '\' clause to the LIKE predicate so user terms match
literally.

Verification

  • make lint passes on shared-python
  • pyright typecheck: 0 errors
  • shared/tests/test_agent_tools_grep.py: 22 passed (added escaping tests +
    fixed two grep fakes that under-provisioned the scanned-page OCR probe the
    empty-result path now runs)
  • Two other shared tests (recall blank-query, outline/read) fail on pristine
    main for reasons unrelated to this change (pre-existing, CI-excluded)

Base: upstream/main. Head: Ayush7614/knowhere fix/ayush7614/corpus-grep-exact-string

…wildcards)

corpus.grep interpolated user search terms raw into LIKE '%...%', so
percent, underscore and backslash acted as wildcards despite the exact
string search contract (a term like 30% matched 30X-style prefixes).
Escape LIKE metacharacters and attach an escape character so terms match
literally. Adds escaping unit tests and provisions the grep fakes for the
scanned-page OCR probe the empty-result path now runs.
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