From d26c8f236954cff84151f0799e3cdfbe513a8bdc Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sun, 25 Jan 2026 10:11:34 -0800 Subject: [PATCH] updated kb to support 1536 dimension vectors for models other than text embedding 3 small --- apps/sim/lib/knowledge/embeddings.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/sim/lib/knowledge/embeddings.ts b/apps/sim/lib/knowledge/embeddings.ts index 2b57b34c5..1171065c7 100644 --- a/apps/sim/lib/knowledge/embeddings.ts +++ b/apps/sim/lib/knowledge/embeddings.ts @@ -8,6 +8,17 @@ const logger = createLogger('EmbeddingUtils') const MAX_TOKENS_PER_REQUEST = 8000 const MAX_CONCURRENT_BATCHES = env.KB_CONFIG_CONCURRENCY_LIMIT || 50 +const EMBEDDING_DIMENSIONS = 1536 + +/** + * Check if the model supports custom dimensions. + * text-embedding-3-* models support the dimensions parameter. + * Checks for 'embedding-3' to handle Azure deployments with custom naming conventions. + */ +function supportsCustomDimensions(modelName: string): boolean { + const name = modelName.toLowerCase() + return name.includes('embedding-3') && !name.includes('ada') +} export class EmbeddingAPIError extends Error { public status: number @@ -93,15 +104,19 @@ async function getEmbeddingConfig( async function callEmbeddingAPI(inputs: string[], config: EmbeddingConfig): Promise { return retryWithExponentialBackoff( async () => { + const useDimensions = supportsCustomDimensions(config.modelName) + const requestBody = config.useAzure ? { input: inputs, encoding_format: 'float', + ...(useDimensions && { dimensions: EMBEDDING_DIMENSIONS }), } : { input: inputs, model: config.modelName, encoding_format: 'float', + ...(useDimensions && { dimensions: EMBEDDING_DIMENSIONS }), } const response = await fetch(config.apiUrl, {