Skip to content

Conversation

@zhanluxianshen
Copy link

@zhanluxianshen zhanluxianshen commented Aug 31, 2025

Purpose

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

@mergify mergify bot added the frontend label Aug 31, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request optimizes two loops by using list slicing, which is a good improvement for conciseness and performance. However, this change introduced a critical issue by removing a None check on the embeddings list. This could lead to runtime errors. I've added a review comment with a suggested fix to re-introduce the check in a Pythonic way.

Comment on lines +132 to +133
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This optimization is a good idea, but it removes the crucial assert ... is not None check. The embeddings list is of type list[Optional[PoolingRequestOutput]] and can contain None if an embedding generation fails. Removing the check can lead to a runtime AttributeError in _cosine_similarity when accessing emb.outputs.data.

I suggest re-introducing the assertion in a more Pythonic way that keeps the slicing optimization.

Note that static type checkers might still complain about the types of emb_texts_1 and emb_texts_2 after this change. You may need to add a # type: ignore or use typing.cast if you are using a strict type checking setup.

Suggested change
emb_texts_1 = embeddings[:len(texts_1)]
emb_texts_2 = embeddings[len(texts_1):]
emb_texts_1, emb_texts_2 = embeddings[:len(texts_1)], embeddings[len(texts_1):]
assert all(e is not None for e in emb_texts_1) and all(e is not None for e in emb_texts_2), "Embedding generation failed, resulting in None values."

@zhanluxianshen zhanluxianshen force-pushed the optimize-serving_score-loops branch 2 times, most recently from fcb3aef to 74c9b14 Compare August 31, 2025 07:34
Signed-off-by: zhanluxianshen <[email protected]>
@zhanluxianshen zhanluxianshen force-pushed the optimize-serving_score-loops branch from 74c9b14 to d883a5c Compare August 31, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant