fix(embedding): request float encoding_format on openai embedding calls - #938
fix(embedding): request float encoding_format on openai embedding calls#938Vansh-Sharma27 wants to merge 2 commits into
Conversation
… paths The openai SDK defaults encoding_format to base64 when it is not passed. OpenAI-compatible providers that don't support base64 embeddings (e.g. OpenRouter with nvidia/nemotron-3-embed-1b:free) return HTTP 200 with empty data, and every embedding call fails with 'No embedding data received'.
The openai SDK defaults encoding_format to base64 when the caller does not pass one. OpenAI-compatible providers that don't support base64 embeddings (e.g. OpenRouter hosting nvidia/nemotron-3-embed-1b:free) answer HTTP 200 with empty embedding data, and every embedding call fails with 'No embedding data received', breaking conclusions, semantic search, and the deriver. Pass encoding_format='float' explicitly on both the single-query and batch call paths.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughOpenAI-compatible embedding requests now explicitly request floating-point vectors in both single-query and batch paths. Tests update existing payload assertions and add coverage for the new request field. ChangesEmbedding request format
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Every embedding call fails when
EMBEDDING_MODEL_CONFIG__TRANSPORT=openaipoints at an OpenAI-compatible provider that doesn't support base64 embeddings (e.g. OpenRouter hostingnvidia/nemotron-3-embed-1b:free):Blast radius:
create_conclusions,search_messages/ semantic search, and the deriver's queued observations all fail.Root cause
The
openaiSDK (v2.36.0, the version inuv.lock) defaultsencoding_formatto"base64"when the caller does not pass one:src/embedding_client.pypassed nothing on either call path, so every request asked for base64. OpenRouter answers HTTP 200 with empty embedding data for models that don't support base64, and the SDK raises.Fix
Pass
encoding_format="float"explicitly on both openai call paths:_EmbeddingClient.embed()_EmbeddingClient._process_batch()These are the only two
embeddings.createcall sites in the codebase; the Gemini path is unaffected. Behavior against real OpenAI is unchanged apart from a slightly larger response payload: the SDK base64-decodes to the same float vectors today, so stored embeddings are identical. A side benefit of passing the format explicitly is that the SDK skips its base64-decode post-parser entirely.Closes #932 — the issue's diagnosis was exact; this implements the fix it points to.
Testing
KeyError: 'encoding_format'before the fix, pass afterpgvector/pgvector:pg15maincheckouttests/crud/test_document.pydedup tests), in full runs and in isolationruff check/ruff format --check/basedpyrightnvidia/nemotron-3-embed-1b:free(the model from the issue)encoding_format:ValueError: No embedding data received, reproducing the report exactly; with"float": real 2048-dim embeddings; the patched_EmbeddingClientpointed at OpenRouter embeds end-to-endThe 3 failing
test_documenttests reproduce identically onmainand are unrelated to this change: the branch adds exactly 2 tests (1560 collected vs 1558 onmain) and touches only the embedding client kwargs.The existing exact-kwargs assertions in
tests/llm/test_embedding_client.pywere updated to include the new key, since the added parameter is intentional behavior.Summary by CodeRabbit