{"record":{"id":"51801a99966a3531","repo":"Mintplex-Labs/anything-llm","slug":"no-embedding-model-preference-defined","errorCode":null,"errorMessage":"No Embedding Model preference defined.","messagePattern":"No Embedding Model preference defined\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/azureOpenAi/index.js","lineNumber":44,"sourceCode":"    this.maxConcurrentChunks = 16;\n\n    // https://learn.microsoft.com/en-us/answers/questions/1188074/text-embedding-ada-002-token-context-length\n    this.embeddingMaxChunkLength = 2048;\n  }\n\n  log(text, ...args) {\n    console.log(`\\x1b[36m[${this.className}]\\x1b[0m ${text}`, ...args);\n  }\n\n  async embedTextInput(textInput) {\n    const result = await this.embedChunks(\n      Array.isArray(textInput) ? textInput : [textInput]\n    );\n    return result?.[0] || [];\n  }\n\n  async embedChunks(textChunks = []) {\n    if (!this.model) throw new Error(\"No Embedding Model preference defined.\");\n\n    this.log(`Embedding ${textChunks.length} chunks...`);\n    // Because there is a limit on how many chunks can be sent at once to Azure OpenAI\n    // we concurrently execute each max batch of text chunks possible.\n    // Refer to constructor maxConcurrentChunks for more info.\n    const embeddingRequests = [];\n    let chunksProcessed = 0;\n    for (const chunk of toChunks(textChunks, this.maxConcurrentChunks)) {\n      embeddingRequests.push(\n        new Promise((resolve) => {\n          this.openai.embeddings\n            .create({\n              model: this.model,\n              input: chunk,\n            })\n            .then((res) => {\n              chunksProcessed += chunk.length;\n              reportEmbeddingProgress(chunksProcessed, textChunks.length);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/azureOpenAi/index.js#L26-L62","documentation":"Thrown at the start of embedChunks when this.model is falsy. this.model is set to process.env.EMBEDDING_MODEL_PREF in the constructor, which the code comments explicitly note cannot be defaulted because Azure uses deployment names rather than model names. Unlike the key/endpoint checks, this guard is deferred to embed time, not construction.","triggerScenarios":"Calling embedChunks/embedTextInput when EMBEDDING_MODEL_PREF was never set; the var was set for the LLM path but not for the Azure embedding engine; deployment name left blank in the embedding config UI.","commonSituations":"Mixing up the model-preference var for chat vs embeddings; selecting Azure OpenAI embeddings without naming the deployment; renaming a deployment in Azure but not updating EMBEDDING_MODEL_PREF.","solutions":["Set EMBEDDING_MODEL_PREF to the Azure deployment name (not the underlying model name) used for embeddings.","Verify the deployment exists on the resource referenced by AZURE_OPENAI_ENDPOINT.","Check the var at startup since the constructor does not throw for a missing model preference — only embedChunks does.","Restart the process after setting it."],"exampleFix":"// before\nthis.model = process.env.EMBEDDING_MODEL_PREF; // undefined -> throws later in embedChunks\n\n// after (fail fast at construction)\nconstructor() {\n  // ...existing checks...\n  this.model = process.env.EMBEDDING_MODEL_PREF;\n  if (!this.model) throw new Error(\"No Embedding Model preference defined.\");\n}","handlingStrategy":"validation","validationCode":"function assertAzureEmbedModel() {\n  if (!process.env.EMBEDDING_MODEL_PREF) {\n    throw new Error('EMBEDDING_MODEL_PREF (Azure deployment name) is required for embeddings');\n  }\n}\nassertAzureEmbedModel();","typeGuard":null,"tryCatchPattern":"try {\n  await embedder.embedChunks(chunks);\n} catch (e) {\n  if (/No Embedding Model preference/i.test(e.message)) { /* set EMBEDDING_MODEL_PREF */ }\n  throw e;\n}","preventionTips":["Set EMBEDDING_MODEL_PREF to the Azure deployment name (case-sensitive), not the base model name.","Fail fast at construction since embedChunks defers this check.","Verify the deployment exists on the resource before embedding."],"tags":["azure","openai","embeddings","config","deployment-name"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}