bugfix: allow optional embedding dimensions in OpenAITextEmbedding to…#2113
bugfix: allow optional embedding dimensions in OpenAITextEmbedding to…#2113Asaduddin18 wants to merge 3 commits into
Conversation
… support open-source models
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
Changes OpenAITextEmbedding.dimensions from int to Integer (nullable), making dimensions optional for OpenAI-API-compatible models that reject this parameter. Good backward compatibility. Note: Builder default changed silently from 1536 to null; getDimensions() returns hardcoded 1024 when unset.
…low explicit null to omit parameter
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
All previously raised review comments have been addressed.
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Makes embedding dimensions optional in OpenAITextEmbedding to support models that do not require explicit dimension configuration.
Findings
- [Info] Constructor changes allow null dimensions. Correct.
- [Info] Tests verify both scenarios (with and without dimensions). Good coverage.
Verdict
Useful flexibility for different embedding models. LGTM.
Automated review by github-manager
AgentScope-Java Version
2.0.1-SNAPSHOT
Description
Background:
OpenAITextEmbeddingalways sent adimensionsparameter to the embeddings API and required it to be a positiveint. This works for OpenAI's own models (text-embedding-3-small/large), which support matryoshka representation learning, but breaks for OpenAI-API-compatible open-source models (e.g.BAAI/bge-large-zh-v1.5) that don't support this parameter — they return a 400 error when it's included.Changes:
dimensionsfield frominttoIntegerso it can be left unset (null).Integer dimensions(null-safe); kept the originalint-based constructor for binary compatibility, now delegating to the new one.Builder.dimensions(...)is now optional — omitting it no longer throws, and thedimensionsrequest field is simply left off the API call.dimensionsvalidation (must be positive) only runs when a value is actually provided.getDimensions()falls back to aDEFAULT_DIMENSIONS = 1024constant when no explicit value was configured, to satisfy theEmbeddingModelinterface contract.dimensionswasn't explicitly configured.How to test:
mvn test -pl agentscope-extensions/agentscope-extensions-rag/agentscope-extensions-rag-simple -am -Dtest=OpenAITextEmbeddingTest,OpenAITextEmbeddingEmbedTestCovers: building without
dimensions(),getDimensions()default fallback, embedding calls with the parameter omitted from the request, and validation for both the deprecatedintconstructor and the newIntegerconstructor when given non-positive values.Fixes #1095
Checklist
mvn spotless:applymvn test)