wenjin272 commented on code in PR #1391:
URL: https://github.com/apache/flink-agents/pull/1391#discussion_r4704061911
##########
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:
Thanks for catching this. Fixed in 62f98bbdb: Python now preserves
`prompt_eval_count`, including zero, and keeps `token_usage=None` when the SDK
reports no count. Java also forwards the count exposed by its SDK, retaining
its zero default.
Added single-input and batch tests for positive, zero, and omitted counts.
All 7 Java Ollama tests and 6 Python usage tests passed.
##########
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:
Thanks, agreed. Fixed in 4e186caca by adding a batch adapter method: Python
passes the entire list once, and Java converts the blocks in input order.
Single-input calls retain their existing path.
Tests cover empty, singleton, mixed, and 128-input batches, including an
assertion that batch conversion uses one adapter call. The real Pemja bridge
and synchronous/asynchronous Flink E2E tests passed in both language directions.
--
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]