{"record":{"id":"c9f70dd53bee92df","repo":"FlowiseAI/Flowise","slug":"vectors-and-metadatas-must-have-the-same-length","errorCode":null,"errorMessage":"Vectors and metadatas must have the same length","messagePattern":"Vectors and metadatas must have the same length","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/vectorstores/Chroma/core.ts","lineNumber":140,"sourceCode":"    }\n\n    /**\n     * Adds vectors to the Chroma database. The vectors are associated with\n     * the provided documents.\n     * @param vectors An array of vectors to be added to the database.\n     * @param documents An array of `Document` instances associated with the vectors.\n     * @param options Optional. An object containing an array of `ids` for the vectors.\n     * @returns A promise that resolves with an array of document IDs when the vectors have been added to the database.\n     */\n    async addVectors(vectors: number[][], documents: Document[], options?: { ids?: string[] }) {\n        if (vectors.length === 0) {\n            return []\n        }\n        if (this.numDimensions === undefined) {\n            this.numDimensions = vectors[0].length\n        }\n        if (vectors.length !== documents.length) {\n            throw new Error(`Vectors and metadatas must have the same length`)\n        }\n        if (vectors[0].length !== this.numDimensions) {\n            throw new Error(`Vectors must have the same length as the number of dimensions (${this.numDimensions})`)\n        }\n\n        const documentIds = options?.ids ?? Array.from({ length: vectors.length }, () => uuid.v1())\n        const collection = await this.ensureCollection()\n\n        const mappedMetadatas: Metadata[] = documents.map(({ metadata }) => {\n            let locFrom\n            let locTo\n\n            if (metadata?.loc) {\n                if (metadata.loc.lines?.from !== undefined) locFrom = metadata.loc.lines.from\n                if (metadata.loc.lines?.to !== undefined) locTo = metadata.loc.lines.to\n            }\n\n            const newMetadata: Document['metadata'] = {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/vectorstores/Chroma/core.ts#L122-L158","documentation":"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.","triggerScenarios":"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).","commonSituations":"Custom document splitter that filters blanks after embedding, batch embedding that silently skips failed items, or manual array slicing that goes out of sync.","solutions":["Before calling addVectors, assert `vectors.length === documents.length` and log both lengths.","Inspect the embedDocuments call to ensure it returns one vector per input document with no internal filtering.","Avoid mutating the documents array between embedding and addVectors."],"exampleFix":"// before\nconst vectors = await embedder.embedDocuments(texts)\n// texts filtered after embedding -> length mismatch\nawait store.addVectors(vectors, docs)\n\n// after\nconst docs = docs.filter(d => d.pageContent)\nconst vectors = await embedder.embedDocuments(docs.map(d => d.pageContent))\nawait store.addVectors(vectors, docs)","handlingStrategy":"validation","validationCode":"function assertParity(vectors: number[][], documents: Document[]) {\n  if (vectors.length !== documents.length) {\n    throw new Error(`Length mismatch: ${vectors.length} vectors vs ${documents.length} documents`)\n  }\n}\n// run before addVectors\nassertParity(vectors, documents)","typeGuard":"function sameLength(a: unknown[], b: unknown[]): boolean {\n  return Array.isArray(a) && Array.isArray(b) && a.length === b.length\n}","tryCatchPattern":"try {\n  await store.addVectors(vectors, documents)\n} catch (e) {\n  if (/same length/i.test(String(e))) {\n    throw new Error(`Embedding/document count drifted. Got ${vectors.length} vectors for ${documents.length} docs.`)\n  }\n  throw e\n}","preventionTips":["Never filter or dedupe the documents array between embedDocuments and addVectors.","Treat embedDocuments as opaque: assume exactly one vector per input.","Add a unit test asserting parity after your pipeline's embed step."],"tags":["chroma","validation","embeddings","addvectors"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}