Repository navigation
fix(rag): rerank image candidates for text queries - #45229
Open
Zhi-Xiang-Guo wants to merge 1 commit into
Open
Zhi-Xiang-Guo wants to merge 1 commit into
Zhi-Xiang-Guo wants to merge 1 commit into
Conversation
Use multimodal reranking for vision-capable models when image candidates are present, preserving the text-only invocation otherwise. Fixes langgenius#45227
6 tasks done
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.
Summary
Fixes #45227
A text query against a multimodal knowledge base could recall an image, then lose it when a vision-capable reranker was enabled: the text-query branch filtered image candidates before scoring. With real CLIP inference and Qdrant, the same HTTP retrieval returned one image without reranking and zero with reranking.
When prepared candidates include an image, invoke the multimodal reranker with a TEXT query and the mixed candidate list. Text-only candidate sets retain the existing text invocation, and non-vision models keep their current behavior. The same API reproduction now returns one image with reranking enabled, and the model endpoint logs confirm actual image inference.
Replace the fallback-encoding test with five parameterized behavior cases covering image preservation and result identity, duplicate suppression, threshold/top-k filtering, vision-capable models with text-only candidates, and non-vision models. Existing image-query tests remain in the suite.
This change does not address the independent missing-upload index-alignment problem in #41480; no missing UploadFile rows are used here. No schema, configuration or dependency changes.
Testing
Baseline:
170dbaeb34789365131a7723f1f33063c4e58558; patch commit:0ae37f3ecd3fdfb90fec78e55a8a11975eab4ae3.UV_NO_SYNC=1 make test TARGET_TESTS='./api/tests/unit_tests/core/rag/rerank --no-cov -q': 53 passed on the fix.UV_NO_SYNC=1 make lint: passed, including 78 import contracts; Ruff andgit diff --checkalso passed. The sparse checkout's trackedweb/.env.examplewas materialized to complete the lint target.make type-checkwas attempted and failed with missing optional VDB/tracing dependencies and other diagnostics; it is not reported as passing. The full failure set has not been isolated against a clean baseline.action_requiredand await maintainer approval; no CI pass is claimed.Screenshots
Backend API change; reproducible request/response and model logs instead of UI screenshots.
Model log after the fix:
The query remains text at the provider endpoint, as intended; the image is now present among the candidates. This does not claim every commercial provider's behavior or final LLM answer-quality improvements.
Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint godsNo frontend changes. Lint passed; the final checklist item remains unchecked because full type-check did not pass. AI assistance was used for investigation, implementation, test execution and drafting; the recorded results are actual runs, not a claim of human review.