FlowiseAI/Flowise · error · Error
Vectors must have the same length as the number of dimension
Error message
Vectors must have the same length as the number of dimensions (${this.numDimensions}) What it means
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.
Source
Thrown at packages/components/nodes/vectorstores/Chroma/core.ts:143
* 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'] = {
...metadata,
...(locFrom !== undefined && { locFrom }),
...(locTo !== undefined && { locTo })View on GitHub (pinned to abe4a8601a)
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.
Example fix
// before
// first batch: openai ada-002 -> 1536d
// second batch: sentence-transformers -> 384d -> throws
await store.addVectors(batch2Vecs, batch2Docs)
// after
const EXPECTED = 1536
if (batch2Vecs[0].length !== EXPECTED) throw new Error('dimension drift')
// or create a new collection with its own dim and reindex Defensive patterns
Strategy: validation
Validate before calling
const EXPECTED_DIM = 1536 // set per model
if (vectors.length && vectors[0].length !== EXPECTED_DIM) {
throw new Error(`Embedding dimension ${vectors[0].length} != expected ${EXPECTED_DIM}`)
}
await store.addVectors(vectors, documents) Type guard
function allSameDimension(vectors: number[][], dim: number): boolean {
return vectors.every(v => Array.isArray(v) && v.length === dim)
} Try / catch
try {
await store.addVectors(vectors, documents)
} catch (e) {
if (/number of dimensions/i.test(String(e))) {
throw new Error(`Dimension drift detected — use a new collection or the original model (${EXPECTED_DIM}d)`, { cause: e })
}
throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Vectors and metadatas must have the same length
- Model ID is required
- Input Type must be selected for Cohere models.
- Invalid JSON in the OpenAIEmbedding's BaseOptions:
- Invalid JSON in the ChatOpenAI's BaseOptions:
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/395f90fb84eef655.
Report an issue: GitHub.