fix(openai): honor embedding output dimensions · openclaw/openclaw@ea116ca
steipete
·
2026-05-07
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -85,4 +85,22 @@ describe("OpenAI embedding provider", () => {
|
85 | 85 | }), |
86 | 86 | ); |
87 | 87 | }); |
| 88 | + |
| 89 | +it("sends outputDimensionality as OpenAI dimensions", async () => { |
| 90 | +const { provider } = await createOpenAiEmbeddingProvider( |
| 91 | +createOptions({ outputDimensionality: 512 }), |
| 92 | +); |
| 93 | + |
| 94 | +await provider.embedBatch(["doc"]); |
| 95 | + |
| 96 | +expect(mocks.fetchRemoteEmbeddingVectors).toHaveBeenCalledWith( |
| 97 | +expect.objectContaining({ |
| 98 | +body: { |
| 99 | +model: "text-embedding-3-small", |
| 100 | +input: ["doc"], |
| 101 | +dimensions: 512, |
| 102 | +}, |
| 103 | +}), |
| 104 | +); |
| 105 | +}); |
88 | 106 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ export type OpenAiEmbeddingClient = {
|
16 | 16 | inputType?: string; |
17 | 17 | queryInputType?: string; |
18 | 18 | documentInputType?: string; |
| 19 | +outputDimensionality?: number; |
19 | 20 | }; |
20 | 21 | |
21 | 22 | const DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1"; |
@@ -59,6 +60,9 @@ export async function createOpenAiEmbeddingProvider(
|
59 | 60 | body: { |
60 | 61 | model: client.model, |
61 | 62 | input, |
| 63 | + ...(typeof client.outputDimensionality === "number" |
| 64 | + ? { dimensions: client.outputDimensionality } |
| 65 | + : {}), |
62 | 66 | ...(inputType ? { input_type: inputType } : {}), |
63 | 67 | }, |
64 | 68 | errorPrefix: "openai embeddings failed", |
@@ -96,5 +100,6 @@ async function resolveOpenAiEmbeddingClient(
|
96 | 100 | inputType: options.inputType, |
97 | 101 | queryInputType: options.queryInputType, |
98 | 102 | documentInputType: options.documentInputType, |
| 103 | +outputDimensionality: options.outputDimensionality, |
99 | 104 | }; |
100 | 105 | } |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,7 @@ describe("OpenAI memory embedding adapter", () => {
|
37 | 37 | model: "text-embedding-3-small", |
38 | 38 | inputType: "passage", |
39 | 39 | documentInputType: "document", |
| 40 | +outputDimensionality: 512, |
40 | 41 | }, |
41 | 42 | }); |
42 | 43 | }); |
@@ -66,6 +67,7 @@ describe("OpenAI memory embedding adapter", () => {
|
66 | 67 | body: { |
67 | 68 | model: "text-embedding-3-small", |
68 | 69 | input: "doc one", |
| 70 | +dimensions: 512, |
69 | 71 | input_type: "document", |
70 | 72 | }, |
71 | 73 | }), |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,7 @@ export const openAiMemoryEmbeddingProviderAdapter: MemoryEmbeddingProviderAdapte
|
32 | 32 | provider: "openai", |
33 | 33 | baseUrl: client.baseUrl, |
34 | 34 | model: client.model, |
| 35 | +outputDimensionality: client.outputDimensionality, |
35 | 36 | documentInputType: client.documentInputType ?? client.inputType, |
36 | 37 | headers: sanitizeEmbeddingCacheHeaders(client.headers, ["authorization"]), |
37 | 38 | }, |
@@ -47,6 +48,9 @@ export const openAiMemoryEmbeddingProviderAdapter: MemoryEmbeddingProviderAdapte
|
47 | 48 | body: { |
48 | 49 | model: client.model, |
49 | 50 | input: chunk.text, |
| 51 | + ...(typeof client.outputDimensionality === "number" |
| 52 | + ? { dimensions: client.outputDimensionality } |
| 53 | + : {}), |
50 | 54 | ...(inputType ? { input_type: inputType } : {}), |
51 | 55 | }, |
52 | 56 | })), |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。