fix: UniversalAPIEmbedder now passes embedding_dims to API calls - #2180
fix: UniversalAPIEmbedder now passes embedding_dims to API calls#2180RerankerGuo wants to merge 4 commits into
Conversation
🤖 Open Code ReviewTarget: PR #2180 🔍 OpenCodeReview found 4 issue(s) in this PR. 1.
|
|
6bc3968 to
9f25415
Compare
|
|
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
…ck for universal_api fallback tests
…or can await it UniversalAPIEmbedder now awaits client.embeddings.create() via asyncio.wait_for, so the mock must be an async function (AsyncMock) rather than a plain MagicMock. Introduce _awaitable_response/_mock_embedding_response helpers and patch embeddings.create at the instance level instead of relying on the default MagicMock return-value.
dc3f4f4 to
b98b8e0
Compare
✅ Automated Test Results: PASSEDAll tests passed (9/9 executed). memos_python_core/changed-repo-python: 9/9. Duration: 5s Branch: |
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