fix(ts): request float OpenAI embeddings (#5170)

Co-authored-by: Kartik <kartik.labhshetwar@mem0.ai>
This commit is contained in:
Pragnyan Ramtha
2026-06-04 20:29:53 +05:30
committed by GitHub
co-authored by Kartik
parent 866888df41
commit 64b9646e7d
2 changed files with 8 additions and 1 deletions
+2
View File
@@ -20,6 +20,7 @@ export class OpenAIEmbedder implements Embedder {
const response = await this.openai.embeddings.create({
model: this.model,
input: text,
encoding_format: "float",
...(this.embeddingDims !== undefined && {
dimensions: this.embeddingDims,
}),
@@ -35,6 +36,7 @@ export class OpenAIEmbedder implements Embedder {
const response = await this.openai.embeddings.create({
model: this.model,
input: chunk,
encoding_format: "float",
...(this.embeddingDims !== undefined && {
dimensions: this.embeddingDims,
}),
@@ -2,7 +2,8 @@
/**
* OpenAI Embedder — unit tests (mocked OpenAI client).
* Verifies that the `dimensions` parameter is only passed to the API
* when the user explicitly configures `embeddingDims`.
* when the user explicitly configures `embeddingDims`, and that
* embeddings are requested as floats for OpenAI-compatible proxies.
*/
const mockEmbeddingsCreate = jest.fn();
@@ -42,6 +43,7 @@ describe("OpenAIEmbedder (unit)", () => {
expect(callArgs).toEqual({
model: "text-embedding-3-small",
input: "hello",
encoding_format: "float",
});
});
@@ -58,6 +60,7 @@ describe("OpenAIEmbedder (unit)", () => {
expect(callArgs).toEqual({
model: "text-embedding-3-small",
input: "hello",
encoding_format: "float",
dimensions: 1024,
});
});
@@ -87,6 +90,7 @@ describe("OpenAIEmbedder (unit)", () => {
const callArgs = mockEmbeddingsCreate.mock.calls[0][0];
expect(callArgs).not.toHaveProperty("dimensions");
expect(callArgs).toHaveProperty("encoding_format", "float");
});
it("passes dimensions in embedBatch when embeddingDims is explicitly set", async () => {
@@ -105,6 +109,7 @@ describe("OpenAIEmbedder (unit)", () => {
expect(callArgs).toEqual({
model: "text-embedding-3-small",
input: ["hello", "world"],
encoding_format: "float",
dimensions: 512,
});
});