{"record":{"id":"395f90fb84eef655","repo":"FlowiseAI/Flowise","slug":"vectors-must-have-the-same-length-as-the-number-of","errorCode":null,"errorMessage":"Vectors must have the same length as the number of dimensions (${this.numDimensions})","messagePattern":"Vectors must have the same length as the number of dimensions \\((.+?)\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/vectorstores/Chroma/core.ts","lineNumber":143,"sourceCode":"     * 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'] = {\n                ...metadata,\n                ...(locFrom !== undefined && { locFrom }),\n                ...(locTo !== undefined && { locTo })","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/vectorstores/Chroma/core.ts#L125-L161","documentation":"addVectors pins the collection dimension on the first batch (this.numDimensions = vectors[0].length) and rejects any subsequent vector whose element count differs. Embedding dimension must be invariant for the collection's lifetime; switching embedding models produces this error.","triggerScenarios":"A second addVectors call uses a different embedding model, a mixed batch where some vectors come from a different model, or a corrupt/truncated embedding.","commonSituations":"Switching from text-embedding-ada-002 (1536d) to a smaller model (e.g. 384d) on the same collection, mixing providers, or a custom embedder returning padded/truncated arrays.","solutions":["Use a single embedding model for the entire collection lifetime.","If you must change models, create a new collection and reindex — do not reuse the existing one.","Validate vector length equals the configured model dimension before each addVectors call."],"exampleFix":"// before\n// first batch: openai ada-002 -> 1536d\n// second batch: sentence-transformers -> 384d -> throws\nawait store.addVectors(batch2Vecs, batch2Docs)\n\n// after\nconst EXPECTED = 1536\nif (batch2Vecs[0].length !== EXPECTED) throw new Error('dimension drift')\n// or create a new collection with its own dim and reindex","handlingStrategy":"validation","validationCode":"const EXPECTED_DIM = 1536 // set per model\nif (vectors.length && vectors[0].length !== EXPECTED_DIM) {\n  throw new Error(`Embedding dimension ${vectors[0].length} != expected ${EXPECTED_DIM}`)\n}\nawait store.addVectors(vectors, documents)","typeGuard":"function allSameDimension(vectors: number[][], dim: number): boolean {\n  return vectors.every(v => Array.isArray(v) && v.length === dim)\n}","tryCatchPattern":"try {\n  await store.addVectors(vectors, documents)\n} catch (e) {\n  if (/number of dimensions/i.test(String(e))) {\n    throw new Error(`Dimension drift detected — use a new collection or the original model (${EXPECTED_DIM}d)`, { cause: e })\n  }\n  throw e\n}","preventionTips":["Use one embedding model per collection for its lifetime.","Store the model name + dimension in the collection metadata at creation.","Add a CI assertion that the configured model's dim matches the collection's first-batch dim."],"tags":["chroma","embeddings","dimension","validation"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}