{"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 this.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/fad3f12a147d138388a66f0d92a02b2675f65294/extensions/vector-db-extension/src/index.ts#L100-L136","documentation":"Thrown by VectorDBExtension.ingestFileForProject() after re-embedding chunks when the resulting embedding vectors have length 0 (finalDimension <= 0). This means the embedding engine returned empty/malformed vectors even though chunks exist. It surfaces an upstream embed() failure that did not throw but produced no usable vector data.","triggerScenarios":"Embedding model loaded but returning empty vectors; embed() resolves with an empty/short data array so embeddings[0]?.length is 0; embedding dimensionality could not be derived from the response shape.","commonSituations":"Embedding model partially loaded or corrupted; llamacpp embed() returned an error object treated as data; mismatch between requested text count and returned indices.","solutions":["Verify an embedding model is fully loaded and embed() returns vectors (test embedTexts on a sample).","Restart/reload the llamacpp extension and embedding model.","Reinstall or pick a different embedding model whose output dimension is non-zero.","Inspect llamacpp logs for the embed() call to see why vectors are empty."],"exampleFix":"// before\nawait vecdbExt.ingestFileForProject(projectId, file, opts)\n\n// after\nconst probe = await vecdbExt.embedTexts?.(['probe']) ?? await rag.embed(['probe'])\nif (!probe?.[0]?.length) {\n  throw new Error('Embedding model returned no vectors; reload the embedding model')\n}\nawait vecdbExt.ingestFileForProject(projectId, file, opts)","handlingStrategy":"try-catch","validationCode":"const probe = await rag.embed(['dimension probe']).catch(() => [])\nif (!probe?.[0]?.length) {\n  // embedding model not ready; do not ingest\n}","typeGuard":null,"tryCatchPattern":"try {\n  await vecdbExt.ingestFileForProject(projectId, file, opts)\n} catch (e) {\n  if (e instanceof Error && e.message === 'Embedding dimension not available') {\n    await reloadEmbeddingModel()\n    return vecdbExt.ingestFileForProject(projectId, file, opts)\n  }\n  throw e\n}","preventionTips":["Probe embed() on a sample before bulk ingestion.","Ensure the embedding model is fully loaded.","Reload the embedding model if vectors come back empty."],"tags":["vector-db","embeddings","model-loading","project"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}