Fix exclude file filters leaking into query in FileFilter.defilter - #1345
Open
JSap0914 wants to merge 1 commit into
Open
Fix exclude file filters leaking into query in FileFilter.defilter#1345JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
FileFilter.defilter only stripped include file filters (file:"...") because file_filter_regex carries a (?<!-) lookbehind. Exclude filters (-file:"...") were left behind, leaking filter syntax into the defiltered query sent to search and chat models. Strip the excluded file filter regex as well, mirroring WordFilter which removes both required and blocked terms.
This was referenced Aug 4, 2026
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.
Bug
FileFilter.defilter()only removes include file filters (file:"...") from a query. Itsfile_filter_regexcarries a(?<!-)negative lookbehind, so exclude filters of the form-file:"..."are never matched and stay in the query.defilter_query()(khoj/processor/conversation/utils.py) runs every filter'sdefilter()to strip filter syntax before the query is sent to search and the chat model. Because exclude file filters aren't stripped, raw filter syntax like-file:"notes.org"leaks into the search/LLM query. This is inconsistent withWordFilter.defilter(), which removes both required (+"...") and blocked (-"...") terms.Fix
Strip the excluded file filter regex in addition to the include regex, so both
file:"..."and-file:"..."are removed from the defiltered query.Verification
Added unit tests covering include, exclude, and mixed file filters in
tests/test_file_filter.py, then ran them offline:Before the fix the two new exclude/mixed cases failed (
'head -file:"file 1.org" tail' != 'head tail'); after the fix all 13 pass.