eemario commented on code in PR #1391:
URL: https://github.com/apache/flink-agents/pull/1391#discussion_r4703239364
##########
python/flink_agents/integrations/embedding_models/local/ollama_embedding_model.py:
##########
@@ -99,7 +100,7 @@ def embed(
)
embeddings = [list(embedding) for embedding in response.embeddings]
- return embeddings[0] if isinstance(text, str) else embeddings
+ return EmbeddingResult(embeddings[0] if isinstance(text, str) else
embeddings)
Review Comment:
Could we preserve `response.prompt_eval_count` when building the result? I
tried an Ollama response with `prompt_eval_count=7` and got `token_usage=None`.
A small test could cover both a reported count (including zero) and a response
that omits it.
##########
python/flink_agents/plan/resource/java/java_embedding_model.py:
##########
@@ -35,39 +35,29 @@ def _call_java_embedding(
adapter: JavaResourceAdapter,
content: EmbeddingContent,
kwargs: Dict[str, Any],
- *,
- with_usage: bool,
) -> EmbeddingResult[list[float] | list[list[float]]]:
"""Call the Java model and adapt its result to the Python input shape."""
single = isinstance(content, str | TextBlock | MediaBlock)
inputs = [content] if single else list(content)
- argument = content if single else inputs
- j_result = None
-
- if any(isinstance(item, TextBlock | MediaBlock) for item in inputs):
+ if single and isinstance(content, str):
+ j_result = resource.embed(content, kwargs)
+ else:
blocks = [
TextBlock(text=item) if isinstance(item, str) else item for item
in inputs
]
java_blocks = [
adapter.fromPythonDataContentBlock(block.model_dump(mode="json"))
Review Comment:
Non-blocking: could we convert the whole batch in one adapter call? For 128
strings, this loop crosses from Python to Java 128 times before the single
`embed` call. Passing the batch to the adapter at once would keep the
`DataContentBlock` API and avoid those per-input crossings.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]