fix(ts): request float OpenAI embeddings (#5170)
Co-authored-by: Kartik <kartik.labhshetwar@mem0.ai>
This commit is contained in:
co-authored by
Kartik
parent
866888df41
commit
64b9646e7d
@@ -20,6 +20,7 @@ export class OpenAIEmbedder implements Embedder {
|
|||||||
const response = await this.openai.embeddings.create({
|
const response = await this.openai.embeddings.create({
|
||||||
model: this.model,
|
model: this.model,
|
||||||
input: text,
|
input: text,
|
||||||
|
encoding_format: "float",
|
||||||
...(this.embeddingDims !== undefined && {
|
...(this.embeddingDims !== undefined && {
|
||||||
dimensions: this.embeddingDims,
|
dimensions: this.embeddingDims,
|
||||||
}),
|
}),
|
||||||
@@ -35,6 +36,7 @@ export class OpenAIEmbedder implements Embedder {
|
|||||||
const response = await this.openai.embeddings.create({
|
const response = await this.openai.embeddings.create({
|
||||||
model: this.model,
|
model: this.model,
|
||||||
input: chunk,
|
input: chunk,
|
||||||
|
encoding_format: "float",
|
||||||
...(this.embeddingDims !== undefined && {
|
...(this.embeddingDims !== undefined && {
|
||||||
dimensions: this.embeddingDims,
|
dimensions: this.embeddingDims,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
/**
|
/**
|
||||||
* OpenAI Embedder — unit tests (mocked OpenAI client).
|
* OpenAI Embedder — unit tests (mocked OpenAI client).
|
||||||
* Verifies that the `dimensions` parameter is only passed to the API
|
* 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();
|
const mockEmbeddingsCreate = jest.fn();
|
||||||
@@ -42,6 +43,7 @@ describe("OpenAIEmbedder (unit)", () => {
|
|||||||
expect(callArgs).toEqual({
|
expect(callArgs).toEqual({
|
||||||
model: "text-embedding-3-small",
|
model: "text-embedding-3-small",
|
||||||
input: "hello",
|
input: "hello",
|
||||||
|
encoding_format: "float",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ describe("OpenAIEmbedder (unit)", () => {
|
|||||||
expect(callArgs).toEqual({
|
expect(callArgs).toEqual({
|
||||||
model: "text-embedding-3-small",
|
model: "text-embedding-3-small",
|
||||||
input: "hello",
|
input: "hello",
|
||||||
|
encoding_format: "float",
|
||||||
dimensions: 1024,
|
dimensions: 1024,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -87,6 +90,7 @@ describe("OpenAIEmbedder (unit)", () => {
|
|||||||
|
|
||||||
const callArgs = mockEmbeddingsCreate.mock.calls[0][0];
|
const callArgs = mockEmbeddingsCreate.mock.calls[0][0];
|
||||||
expect(callArgs).not.toHaveProperty("dimensions");
|
expect(callArgs).not.toHaveProperty("dimensions");
|
||||||
|
expect(callArgs).toHaveProperty("encoding_format", "float");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes dimensions in embedBatch when embeddingDims is explicitly set", async () => {
|
it("passes dimensions in embedBatch when embeddingDims is explicitly set", async () => {
|
||||||
@@ -105,6 +109,7 @@ describe("OpenAIEmbedder (unit)", () => {
|
|||||||
expect(callArgs).toEqual({
|
expect(callArgs).toEqual({
|
||||||
model: "text-embedding-3-small",
|
model: "text-embedding-3-small",
|
||||||
input: ["hello", "world"],
|
input: ["hello", "world"],
|
||||||
|
encoding_format: "float",
|
||||||
dimensions: 512,
|
dimensions: 512,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user