Skip to content

fix(vertex_ai): populate document text in rerank response when return_documents is true - #38277

Open
somuai wants to merge 1 commit into
BerriAI:mainfrom
somuai:fix/vertex-rerank-return-documents
Open

somuai wants to merge 1 commit into
BerriAI:mainfrom
somuai:fix/vertex-rerank-return-documents

Conversation

@somuai

@somuai somuai commented Aug 25, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #38239

When calling litellm.rerank() with Vertex AI semantic ranker models and return_documents=True (the default), the response transformer previously discarded the returned content field from each record.

This change:

  1. In transform_rerank_response, checks whether return_documents is true (via optional_params, request_data, litellm_params, or default True) and populates document={"text": record["content"]} when record.get("content") is present.
  2. If return_documents=False, the document field is omitted from results as expected.
  3. Adds unit and integration tests verifying vertex rerank response transformation with return_documents=True and return_documents=False.

@CLAassistant

CLAassistant commented Aug 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR restores Vertex AI rerank document text in normalized results when documents are requested and omits it when record details are disabled.

  • Derives document-return behavior from the available request parameters.
  • Maps each returned Vertex record’s content into the shared rerank document shape.
  • Adds unit and integration assertions for enabled and disabled document returns.

Confidence Score: 4/5

The PR appears safe to merge functionally, with a non-blocking source-convention cleanup needed in the response transformer.

The document mapping follows the shared rerank response shape and the request’s effective return_documents setting; the only accepted issue is the newly introduced mutable, non-Final implementation style and unnecessary explanatory comment.

Files Needing Attention: litellm/llms/vertex_ai/rerank/transformation.py

Important Files Changed

Filename Overview
litellm/llms/vertex_ai/rerank/transformation.py Correctly maps Vertex record content into normalized rerank documents, but the implementation violates repository immutability, Final-annotation, and comment conventions.
tests/test_litellm/llms/vertex_ai/rerank/test_vertex_ai_rerank_transformation.py Adds focused coverage for document inclusion, omission, and transformed request behavior without weakening existing assertions.
tests/test_litellm/llms/vertex_ai/rerank/test_vertex_ai_rerank_integration.py Extends the mocked integration flow to verify returned document text and omission when record details are disabled.

Reviews (1): Last reviewed commit: "fix(vertex_ai): populate document text i..." | Re-trigger Greptile

Comment on lines 175 to +176

# Determine whether to return documents (defaults to True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Avoid mutable response construction

The new response path reassigns return_documents and result_item, mutates intermediate dictionaries, and adds a straightforward explanatory comment, violating the repository’s immutable, Final-annotated source conventions and making the response construction harder to reason about.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing somuai:fix/vertex-rerank-return-documents (fcf23a1) with main (1e6c983)

Open in CodSpeed

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:45
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@somuai

somuai commented Sep 22, 2026

Copy link
Copy Markdown
Author

Gentle follow-up for @krrishdholakia / @ishaan-jaff — all 77 CI checks are passing green with no merge conflicts. Happy to address any feedback if needed, otherwise ready for review/merge. Thank you!

@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:55
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 14:55
@somuai
somuai force-pushed the fix/vertex-rerank-return-documents branch from e441d38 to fcf23a1 Compare September 26, 2026 10:05
@somuai

somuai commented Oct 13, 2026

Copy link
Copy Markdown
Author

Gentle follow-up for @krrishdholakia and @ishaan-jaff. All CI checks are passing green, and the branch is cleanly mergeable with full unit and integration test coverage for Vertex AI rerank response document mapping. Ready for review whenever convenient. Thank you!

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.

[Bug]: vertex_ai rerank drops document text from response even when return_documents is true

3 participants