janhq/jan · error · Error

Embedding dimension not available

Error message

Embedding dimension not available

What it means

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.

Solutions

  1. Verify the embedding provider/extension is configured with a valid API key and reachable
  2. Ensure the file yields non-empty chunks before calling ingestFileForProject
  3. Log/inspect embedTexts output to catch providers returning empty vectors
  4. Catch the error and fall back to a default embedding dimension or notify the user

Example fix

// before
await vecdb.ingestFileForProject(projectId, file, chunks)
// after
if (!chunks.length) throw new Error('No chunks to embed')
const emb = await embedTexts(chunks)
if (!emb[0]?.length) throw new Error('Embedding provider returned empty vectors')
await vecdb.ingestFileForProject(projectId, file, chunks)
Defensive patterns

Strategy: try-catch

Validate before calling

if (!chunks.length) throw new Error('Nothing to embed')
const probe = await embedTexts(chunks.slice(0, 1))
if (!probe[0]?.length) throw new Error('Embedding provider returned empty vectors')

Type guard

const hasValidEmbedding = (e: unknown): e is number[] =>
  Array.isArray(e) && e.length > 0 && e.every(n => typeof n === 'number' && Number.isFinite(n))

Try / catch

try {
  await vecdb.ingestFileForProject(projectId, file, chunks)
} catch (e) {
  if (e.message === 'Embedding dimension not available') {
    // check embedding provider config/API key, retry or notify user
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: Missing/invalid embedding API key; embedding extension not configured; empty documents producing no chunks; provider outage returning empty responses.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17). Data as JSON: /api/errors/74fca0024b1793a8. Report an issue: GitHub.

Appendix: source

Thrown at extensions/vector-db-extension/src/index.ts:118

    const collectionDimension = dimension > 0 ? dimension : 384
    await this.createCollectionForProject(projectId, collectionDimension)

    // Now check for duplicates
    const existingFiles = await vecdb.listAttachments(this.collectionForProject(projectId)).catch(() => [])
    const duplicate = existingFiles.find((f: any) => f.name === file.name && f.path === file.path)
    if (duplicate) {
      throw new Error(`File '${file.name}' has already been attached to this project`)
    }

    if (!chunks.length) {
      const fi = await vecdb.createFile(this.collectionForProject(projectId), file)
      return fi
    }

    // Re-embed if we got dimension from createCollection
    const embeddings = await embedTexts(chunks)
    const finalDimension = embeddings[0]?.length || 0
    if (finalDimension <= 0) throw new Error('Embedding dimension not available')

    // Ensure collection has correct dimension
    if (finalDimension !== collectionDimension) {
      await this.deleteCollectionForProject(projectId)
      await this.createCollectionForProject(projectId, finalDimension)
    }

    const fi = await vecdb.createFile(this.collectionForProject(projectId), file)
    await vecdb.insertChunks(
      this.collectionForProject(projectId),
      fi.id,
      chunks.map((t, i) => ({ text: t, embedding: embeddings[i] }))
    )
    const infos = await vecdb.listAttachments(this.collectionForProject(projectId))
    const updated = infos.find((e) => e.id === fi.id)
    return updated || { ...fi, chunk_count: chunks.length }
  }

View on GitHub (pinned to 7205d770c1)