@@ -8,6 +8,17 @@ const logger = createLogger('EmbeddingUtils')
88
99const MAX_TOKENS_PER_REQUEST = 8000
1010const 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
1223export class EmbeddingAPIError extends Error {
1324 public status : number
@@ -93,15 +104,19 @@ async function getEmbeddingConfig(
93104async 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