feat(search): add configurable file-level deduplication#188
Open
Don-Yin wants to merge 1 commit intoyoanbernabeu:mainfrom
Open
feat(search): add configurable file-level deduplication#188Don-Yin wants to merge 1 commit intoyoanbernabeu:mainfrom
Don-Yin wants to merge 1 commit intoyoanbernabeu:mainfrom
Conversation
when multiple chunks from the same file match a query, the result list can contain several entries that all point to the same file. this crowds out results from other relevant files and reduces the effective diversity of the top-N list. this commit introduces a `search.dedup.enabled` config option (default: true) that retains only the highest-scoring chunk per file path after boost scoring. when enabled, the internal fetch limit is doubled (from 2x to 4x the requested limit) so that enough unique files survive the filter. changes: - add DedupConfig struct and wire it into SearchConfig - condition dedup and fetch-limit scaling on the config flag - add DeduplicateByFile helper with unit tests
110dff6 to
8c14033
Compare
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.
problem
when a search query matches several chunks from the same file, the result list fills up with duplicate file entries. this crowds out results from other relevant files and reduces the effective diversity of the top-N list. in practice, a user who asks for 10 results may receive 4 or 5 entries that all point to the same file, which leaves fewer slots for other files that would otherwise rank highly.
solution
this PR adds a
search.dedup.enabledoption (default:true) that retains only the highest-scoring chunk per file path. deduplication runs after boost scoring, so the best chunk is selected with structural penalties and bonuses already applied.when dedup is enabled, the internal fetch limit increases from
limit * 2tolimit * 4so that enough unique files survive the filter. users can disable it inconfig.yamlif they prefer the original behaviour:changes
config/config.goDedupConfigstruct, wire it intoSearchConfig, set the default totruesearch/search.gofetchLimitconditionally, callDeduplicateByFilewhen enabledsearch/dedup.goDeduplicateByFile(keeps the first occurrence per file path from a pre-sorted slice)search/dedup_test.gotest plan
go test ./search/passes (all 20 tests, including 3 new dedup tests)go test ./config/passesgo build ./...succeeds with no warningsgrepai search <query> --jsonand confirm that each file path appears at most once in the outputsearch.dedup.enabled: falseinconfig.yamland confirm that duplicate file entries reappearnote
this branch will remain open for additional work (e.g. wiring dedup into the workspace search path). further commits may follow.