Skip to content

Commit b13b9a8

Browse files
committed
Merge PR zilliztech#197 from zilliztech/claude-context
2 parents a9b1755 + 932cf6a commit b13b9a8

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

packages/core/src/embedding/openai-embedding.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ export class OpenAIEmbedding extends Embedding {
2020
apiKey: config.apiKey,
2121
baseURL: config.baseURL,
2222
});
23+
24+
// Set dimension and context length based on model
25+
this.updateModelSettings(config.model || 'text-embedding-3-small');
26+
}
27+
28+
private updateModelSettings(model: string): void {
29+
const supportedModels = OpenAIEmbedding.getSupportedModels();
30+
const modelInfo = supportedModels[model];
31+
32+
if (modelInfo) {
33+
this.dimension = modelInfo.dimension;
34+
this.maxTokens = modelInfo.contextLength;
35+
} else {
36+
// Use default dimension and context length for unknown models
37+
this.dimension = 1536;
38+
this.maxTokens = 8192;
39+
}
2340
}
2441

2542
async detectDimension(testText: string = "test"): Promise<number> {
@@ -143,8 +160,11 @@ export class OpenAIEmbedding extends Embedding {
143160
const knownModels = OpenAIEmbedding.getSupportedModels();
144161
if (knownModels[model]) {
145162
this.dimension = knownModels[model].dimension;
163+
this.maxTokens = knownModels[model].contextLength;
146164
} else {
147165
this.dimension = await this.detectDimension();
166+
// Use default maxTokens for unknown models
167+
this.maxTokens = 8192;
148168
}
149169
}
150170

@@ -158,19 +178,37 @@ export class OpenAIEmbedding extends Embedding {
158178
/**
159179
* Get list of supported models
160180
*/
161-
static getSupportedModels(): Record<string, { dimension: number; description: string }> {
181+
static getSupportedModels(): Record<string, { dimension: number; contextLength: number; description: string }> {
162182
return {
163183
'text-embedding-3-small': {
164184
dimension: 1536,
185+
contextLength: 8192,
165186
description: 'High performance and cost-effective embedding model (recommended)'
166187
},
167188
'text-embedding-3-large': {
168189
dimension: 3072,
190+
contextLength: 8192,
169191
description: 'Highest performance embedding model with larger dimensions'
170192
},
171193
'text-embedding-ada-002': {
172194
dimension: 1536,
195+
contextLength: 8192,
173196
description: 'Legacy model (use text-embedding-3-small instead)'
197+
},
198+
'Qwen/Qwen3-Embedding-8B': {
199+
dimension: 4096,
200+
contextLength: 32000,
201+
description: 'Qwen3 8B embedding model with 4096 dimensions (32k context)'
202+
},
203+
'Qwen/Qwen3-Embedding-4B': {
204+
dimension: 2560,
205+
contextLength: 32000,
206+
description: 'Qwen3 4B embedding model with 2560 dimensions (32k context)'
207+
},
208+
'Qwen/Qwen3-Embedding-0.6B': {
209+
dimension: 1024,
210+
contextLength: 32000,
211+
description: 'Qwen3 0.6B embedding model with 1024 dimensions (32k context)'
174212
}
175213
};
176214
}

0 commit comments

Comments
 (0)