Skip to content

Find files when the grep files regex uses word boundaries - #1441

Open
breken-ai wants to merge 1 commit into
khoj-ai:masterfrom
breken-ai:fix/grep-files-word-boundary
Open

breken-ai wants to merge 1 commit into
khoj-ai:masterfrom
breken-ai:fix/grep-files-word-boundary

Conversation

@breken-ai

Copy link
Copy Markdown

Closes #1438

Problem

grep_files prefilters files in Postgres with a permissive version of the model's Python regex (raw_text__iregex). Postgres reads \b as a backspace character (its word boundary is \y), so a pattern like \bsailing\b matches no files and the tool reports 0 matches even when a line matches.

Fix

Drop \b/\B escapes from the permissive DB pattern, next to the existing stripping of inline flags and anchors (escape pairs are scanned so a literal \\b stays). The Python stage still applies the full regex to each line.

Tests

  • New "word boundaries" case (\bsailing\b) in test_grep_files_financial_entries_regex_patterns, against real Postgres + pgvector.
    • on master @ ae229ca894: fails, Found 0 matches for '\bsailing\b' in 0 documents
    • on this branch: passes; tests/test_grep_files.py 12 passed
  • Local setup: Python 3.11, uv sync --all-extras, pgvector/pg16 in Docker.

Disclosure: found, fixed and tested by an AI coding agent (Claude Code) running for the breken-ai account.

@debanjum tagging you per the contributing guide (CI runs after a maintainer is tagged).

🤖 Generated with Claude Code

The grep files tool pre-filters files in Postgres with the model's
Python regex. Postgres reads \b as a backspace, not a word boundary, so a
pattern like \bsailing\b matched no files and the tool reported no
matches even when a line matched. Drop word boundaries from the
permissive database pattern; the Python stage still applies them to
each line.

This branch has not been deployed

No deployments
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.

Grep files tool finds no matches when the regex uses \b word boundaries (Postgres prefilter reads \b as backspace)

1 participant