Skip to content

Commit d26c8f2

Browse files
committed
updated kb to support 1536 dimension vectors for models other than text embedding 3 small
1 parent 399e632 commit d26c8f2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

apps/sim/lib/knowledge/embeddings.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ const logger = createLogger('EmbeddingUtils')
88

99
const MAX_TOKENS_PER_REQUEST = 8000
1010
const MAX_CONCURRENT_BATCHES = env.KB_CONFIG_CONCURRENCY_LIMIT || 50
11+
const EMBEDDING_DIMENSIONS = 1536
12+
13+
/**
14+
* Check if the model supports custom dimensions.
15+
* text-embedding-3-* models support the dimensions parameter.
16+
* Checks for 'embedding-3' to handle Azure deployments with custom naming conventions.
17+
*/
18+
function supportsCustomDimensions(modelName: string): boolean {
19+
const name = modelName.toLowerCase()
20+
return name.includes('embedding-3') && !name.includes('ada')
21+
}
1122

1223
export class EmbeddingAPIError extends Error {
1324
public status: number
@@ -93,15 +104,19 @@ async function getEmbeddingConfig(
93104
async function callEmbeddingAPI(inputs: string[], config: EmbeddingConfig): Promise<number[][]> {
94105
return retryWithExponentialBackoff(
95106
async () => {
107+
const useDimensions = supportsCustomDimensions(config.modelName)
108+
96109
const requestBody = config.useAzure
97110
? {
98111
input: inputs,
99112
encoding_format: 'float',
113+
...(useDimensions && { dimensions: EMBEDDING_DIMENSIONS }),
100114
}
101115
: {
102116
input: inputs,
103117
model: config.modelName,
104118
encoding_format: 'float',
119+
...(useDimensions && { dimensions: EMBEDDING_DIMENSIONS }),
105120
}
106121

107122
const response = await fetch(config.apiUrl, {

0 commit comments

Comments
 (0)