fix: Uploaded document is not retrievable/searchable using its unique content. #1183
Merged
Conversation
Improve hybrid search quality with a default score threshold, short-query threshold relaxation, prefix matching support, and exact-file preference for unique query text. Made-with: Cursor
Contributor
There was a problem hiding this comment.
Pull request overview
Improves Knowledge search precision for unique/partial queries by tightening keyword matching, adding prefix matching support, and adjusting default score-threshold behavior to reduce low-relevance results.
Changes:
- Backend: tune hybrid keyword queries (AND + stricter fuzziness + bool_prefix) and post-filter results to prefer files containing the query verbatim.
- Backend: adjust
totalto reflect the post-filtered result set size. - Frontend: introduce a default score threshold (with dynamic relaxation for short single-token queries) and apply it when
scoreThresholdis not provided.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/services/search_service.py | Tightens OpenSearch hybrid keyword behavior, adds exact-match file preference filtering, and changes total semantics. |
| frontend/lib/constants.ts | Adds a default score threshold constant for Knowledge search. |
| frontend/app/api/queries/useGetSearchQuery.ts | Applies the new default threshold and dynamically relaxes it for short single-token queries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ) | ||
| } | ||
| if exact_files: | ||
| chunks = [chunk for chunk in chunks if chunk.get("filename") in exact_files] |
ricofurtado
requested changes
Mar 19, 2026
Use safer prefix fallback behavior for current index mappings and keep aggregations aligned with post-filtered exact file results. Made-with: Cursor
ricofurtado
approved these changes
Mar 21, 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.
issue: #1138
Improved Knowledge search relevance and partial-query handling by tuning frontend threshold defaults and backend hybrid query behavior.
Before:
Default scoreThreshold was effectively 0 when not provided, so low-relevance files were often included.
Short partial queries (like vita) often returned nothing.
Unique terms could still return unrelated files due to semantic spillover.
Returned total could reflect raw backend hits instead of post-filtered displayed results.
https://github.com/user-attachments/assets/47b4ff45-62a4-473d-b440-e1b82720be9e
Now:
Default scoreThreshold is 1.25 (frontend), with dynamic relaxation to 1.0 for short single-token queries (<=4 chars).
Backend keyword branch is stricter (operator: and, fuzziness: AUTO:4,7) and includes bool_prefix support for partials.
Added exact-text file preference: if query appears verbatim in specific files, results are narrowed to those files.
Fixed exact-file filtering robustness (only valid string filenames considered).
total now matches the actual filtered results shown (len(chunks)).
https://github.com/user-attachments/assets/7d073caf-c00d-41ee-aaa7-6a3735d86a91