{"record":{"id":"74fca0024b1793a8","repo":"janhq/jan","slug":"embedding-dimension-not-available","errorCode":null,"errorMessage":"Embedding dimension not available","messagePattern":"Embedding dimension not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"extensions/vector-db-extension/src/index.ts","lineNumber":118,"sourceCode":"    const collectionDimension = dimension > 0 ? dimension : 384\n    await this.createCollectionForProject(projectId, collectionDimension)\n\n    // Now check for duplicates\n    const existingFiles = await vecdb.listAttachments(this.collectionForProject(projectId)).catch(() => [])\n    const duplicate = existingFiles.find((f: any) => f.name === file.name && f.path === file.path)\n    if (duplicate) {\n      throw new Error(`File '${file.name}' has already been attached to this project`)\n    }\n\n    if (!chunks.length) {\n      const fi = await vecdb.createFile(this.collectionForProject(projectId), file)\n      return fi\n    }\n\n    // Re-embed if we got dimension from createCollection\n    const embeddings = await embedTexts(chunks)\n    const finalDimension = embeddings[0]?.length || 0\n    if (finalDimension <= 0) throw new Error('Embedding dimension not available')\n\n    // Ensure collection has correct dimension\n    if (finalDimension !== collectionDimension) {\n      await this.deleteCollectionForProject(projectId)\n      await this.createCollectionForProject(projectId, finalDimension)\n    }\n\n    const fi = await vecdb.createFile(this.collectionForProject(projectId), file)\n    await vecdb.insertChunks(\n      this.collectionForProject(projectId),\n      fi.id,\n      chunks.map((t, i) => ({ text: t, embedding: embeddings[i] }))\n    )\n    const infos = await vecdb.listAttachments(this.collectionForProject(projectId))\n    const updated = infos.find((e) => e.id === fi.id)\n    return updated || { ...fi, chunk_count: chunks.length }\n  }\n","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/extensions/vector-db-extension/src/index.ts#L100-L136","documentation":"After re-embedding the chunks, ingestFileForProject derives the embedding dimension from embeddings[0].length. If the embedding result is empty or the first vector has zero length, no valid dimension can be determined, so the method throws rather than creating a mismatched collection.","triggerScenarios":"embedTexts returns an empty array or the first embedding is empty — e.g. embedding provider unreachable/misconfigured, empty chunk list reaching the embed step, or an embedding API returning malformed output.","commonSituations":"Missing/invalid embedding API key; embedding extension not configured; empty documents producing no chunks; provider outage returning empty responses.","solutions":["Verify the embedding provider/extension is configured with a valid API key and reachable","Ensure the file yields non-empty chunks before calling ingestFileForProject","Log/inspect embedTexts output to catch providers returning empty vectors","Catch the error and fall back to a default embedding dimension or notify the user"],"exampleFix":"// before\nawait vecdb.ingestFileForProject(projectId, file, chunks)\n// after\nif (!chunks.length) throw new Error('No chunks to embed')\nconst emb = await embedTexts(chunks)\nif (!emb[0]?.length) throw new Error('Embedding provider returned empty vectors')\nawait vecdb.ingestFileForProject(projectId, file, chunks)","handlingStrategy":"try-catch","validationCode":"if (!chunks.length) throw new Error('Nothing to embed')\nconst probe = await embedTexts(chunks.slice(0, 1))\nif (!probe[0]?.length) throw new Error('Embedding provider returned empty vectors')","typeGuard":"const hasValidEmbedding = (e: unknown): e is number[] =>\n  Array.isArray(e) && e.length > 0 && e.every(n => typeof n === 'number' && Number.isFinite(n))","tryCatchPattern":"try {\n  await vecdb.ingestFileForProject(projectId, file, chunks)\n} catch (e) {\n  if (e.message === 'Embedding dimension not available') {\n    // check embedding provider config/API key, retry or notify user\n  } else throw e\n}","preventionTips":["Validate embedding provider configuration (API key, endpoint) before ingestion","Reject empty documents early so no empty chunk sets reach the embed step","Monitor embedding API responses and alert on empty/malformed results"],"tags":["embedding","vector-db","empty-value"],"backgroundTag":"empty-result-set","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}