fix: UniversalAPIEmbedder now passes embedding_dims to API calls - #2180
fix: UniversalAPIEmbedder now passes embedding_dims to API calls#2180RerankerGuo wants to merge 1 commit into
Conversation
Closes MemTensor#2177 The UniversalAPIEmbedder previously silently ignored the embedding_dims config field when making embeddings.create() calls. This caused models like text-embedding-3-large to always return the full default dimension embedding, making it impossible to use the dimensions parameter for reduced-dimensional embeddings. Changes: - Added _build_embedding_kwargs() helper that conditionally includes the 'dimensions' parameter when embedding_dims is set - Extracted _call_embeddings_api() method that handles both primary and backup client paths with unified dimension support - Added graceful fallback: if the API rejects the dimensions parameter (e.g. older model versions), automatically retries without it - Both primary and backup client paths now use the same dimensions-aware calling logic - Added comprehensive unit tests in test_universal_api.py Test: python3 -m py_compile src/memos/embedders/universal_api.py Test: python3 -m py_compile tests/embedders/test_universal_api.py
🤖 Open Code ReviewTarget: PR #2180 🔍 OpenCodeReview found 5 issue(s) in this PR. 1.
|
|
Description
Fixes #2177
The
UniversalAPIEmbedderpreviously silently ignored theembedding_dimsconfig field when makingembeddings.create()calls. This caused models liketext-embedding-3-largeto always return the full default dimension embedding (e.g. 3072), making it impossible to use thedimensionsparameter for reduced-dimensional embeddings.Changes
_build_embedding_kwargs()helper — conditionally includes thedimensionsparameter whenembedding_dimsis set in config_call_embeddings_api()method — handles both primary and backup client paths with unified dimension supportdimensionsparameter (e.g. older model versions or non-Ollama providers), automatically retries without ittests/embedders/test_universal_api.pyType of change
How Has This Been Tested?
python3 -m py_compile src/memos/embedders/universal_api.pypassespython3 -m py_compile tests/embedders/test_universal_api.pypasses_build_embedding_kwargs(no dims / with dims / zero dims / empty list / batch)embedding_dims=None(backward compatible)Checklist