fix(embeddings): handle compatible endpoints that return float arrays - #2150
Open
anishesg wants to merge 1 commit into
Open
fix(embeddings): handle compatible endpoints that return float arrays#2150anishesg wants to merge 1 commit into
anishesg wants to merge 1 commit into
Conversation
## Changes being requested Signed-off-by: anish <anishesg@users.noreply.github.com>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes being requested
src/resources/embeddings.tsto detect when embeddings are already returned as float arraysencoding_formatparameterAdditional context & links
Some OpenAI-compatible endpoints like ollama and LM Studio ignore the
encoding_formatparameter and always return embeddings as float arrays instead of base64-encoded strings. The SDK was attempting to decode these arrays as base64, which caused Buffer.from() to interpret the array as bytes rather than a base64 string. For a 1024-element float array, this created a 1024-byte buffer, which when divided by 4 (Float32Array.BYTES_PER_ELEMENT) resulted in exactly 256 dimensions.The fix adds an Array.isArray() check before attempting base64 decoding. If the embedding is already an array, it's used directly. Otherwise, it's decoded from base64 as before. This preserves backward compatibility with the official OpenAI API while supporting endpoints that return float arrays.
Fixes #1542