FlowiseAI/Flowise · error · Error

Vectors and metadatas must have the same length

Error message

Vectors and metadatas must have the same length

What it means

In addVectors, the library asserts vectors.length === documents.length. Each embedding vector must pair with exactly one Document; a mismatch means the embedding step produced a different count than the document batch — a programming or pipeline bug, not a runtime/config issue.

Source

Thrown at packages/components/nodes/vectorstores/Chroma/core.ts:140

    }

    /**
     * Adds vectors to the Chroma database. The vectors are associated with
     * the provided documents.
     * @param vectors An array of vectors to be added to the database.
     * @param documents An array of `Document` instances associated with the vectors.
     * @param options Optional. An object containing an array of `ids` for the vectors.
     * @returns A promise that resolves with an array of document IDs when the vectors have been added to the database.
     */
    async addVectors(vectors: number[][], documents: Document[], options?: { ids?: string[] }) {
        if (vectors.length === 0) {
            return []
        }
        if (this.numDimensions === undefined) {
            this.numDimensions = vectors[0].length
        }
        if (vectors.length !== documents.length) {
            throw new Error(`Vectors and metadatas must have the same length`)
        }
        if (vectors[0].length !== this.numDimensions) {
            throw new Error(`Vectors must have the same length as the number of dimensions (${this.numDimensions})`)
        }

        const documentIds = options?.ids ?? Array.from({ length: vectors.length }, () => uuid.v1())
        const collection = await this.ensureCollection()

        const mappedMetadatas: Metadata[] = documents.map(({ metadata }) => {
            let locFrom
            let locTo

            if (metadata?.loc) {
                if (metadata.loc.lines?.from !== undefined) locFrom = metadata.loc.lines.from
                if (metadata.loc.lines?.to !== undefined) locTo = metadata.loc.lines.to
            }

            const newMetadata: Document['metadata'] = {

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Before calling addVectors, assert `vectors.length === documents.length` and log both lengths.
  2. Inspect the embedDocuments call to ensure it returns one vector per input document with no internal filtering.
  3. Avoid mutating the documents array between embedding and addVectors.

Example fix

// before
const vectors = await embedder.embedDocuments(texts)
// texts filtered after embedding -> length mismatch
await store.addVectors(vectors, docs)

// after
const docs = docs.filter(d => d.pageContent)
const vectors = await embedder.embedDocuments(docs.map(d => d.pageContent))
await store.addVectors(vectors, docs)
Defensive patterns

Strategy: validation

Validate before calling

function assertParity(vectors: number[][], documents: Document[]) {
  if (vectors.length !== documents.length) {
    throw new Error(`Length mismatch: ${vectors.length} vectors vs ${documents.length} documents`)
  }
}
// run before addVectors
assertParity(vectors, documents)

Type guard

function sameLength(a: unknown[], b: unknown[]): boolean {
  return Array.isArray(a) && Array.isArray(b) && a.length === b.length
}

Try / catch

try {
  await store.addVectors(vectors, documents)
} catch (e) {
  if (/same length/i.test(String(e))) {
    throw new Error(`Embedding/document count drifted. Got ${vectors.length} vectors for ${documents.length} docs.`)
  }
  throw e
}

Prevention

When it happens

Trigger: Caller invokes addVectors with parallel arrays of differing lengths, or an upstream embedDocuments call dropped/added elements (e.g. empty-string filtering, dedup, or a custom Embeddings implementation returning fewer vectors).

Common situations: Custom document splitter that filters blanks after embedding, batch embedding that silently skips failed items, or manual array slicing that goes out of sync.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/c9f70dd53bee92df. Report an issue: GitHub.