FlowiseAI/Flowise · error · Error

If provided, "options.ids" must be an array with the same le

Error message

If provided, "options.ids" must be an array with the same length as "vectors".

What it means

Thrown by `MongoDBAtlasVectorSearch.addVectors` when the caller supplies `options.ids` whose length does not equal `vectors.length`. When ids are provided, the store upserts each document keyed by id, so a length mismatch would silently misalign documents and ids — the guard refuses this rather than corrupt data.

Source

Thrown at packages/components/nodes/vectorstores/MongoDBAtlas/core.ts:83

    }

    async closeConnection(client: MongoClient) {
        await client.close()
    }

    async addVectors(vectors: number[][], documents: Document[], options?: { ids?: string[] }) {
        const client = await this.getClient()
        const collection = client.db(this.connectionDetails.databaseName).collection(this.connectionDetails.collectionName)
        const docs = vectors.map((embedding, idx) => ({
            [this.textKey]: documents[idx].pageContent,
            [this.embeddingKey]: embedding,
            ...documents[idx].metadata
        }))
        if (options?.ids === undefined) {
            await collection.insertMany(docs)
        } else {
            if (options.ids.length !== vectors.length) {
                throw new Error(`If provided, "options.ids" must be an array with the same length as "vectors".`)
            }
            const { ids } = options
            for (let i = 0; i < docs.length; i += 1) {
                await this.caller.call(async () => {
                    await collection.updateOne(
                        { [this.primaryKey]: ids[i] },
                        { $set: { [this.primaryKey]: ids[i], ...docs[i] } },
                        { upsert: true }
                    )
                })
            }
        }
        await this.closeConnection(client)
        return options?.ids ?? docs.map((doc) => doc[this.primaryKey])
    }

    async addDocuments(documents: Document[], options?: { ids?: string[] }) {
        const texts = documents.map(({ pageContent }) => pageContent)

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Ensure `options.ids.length === documents.length === vectors.length` before calling.
  2. If only some documents have ids, omit `options.ids` entirely to use insertMany, or split into id-bearing and id-less batches.
  3. Regenerate ids from the current documents array immediately before the call.
  4. Add a unit assertion on the three lengths.

Example fix

// before
await store.addVectors(vectors, docs, { ids: someKeys })
// after — guard lengths up front
if (ids && ids.length !== docs.length) {
    throw new Error(`ids length ${ids.length} != docs length ${docs.length}`)
}
await store.addVectors(vectors, docs, ids ? { ids } : undefined)
Defensive patterns

Strategy: type-guard

Validate before calling

function assertIdsAligned(vectors: unknown[], docs: unknown[], ids?: string[]) {
  if (vectors.length !== docs.length) throw new Error(`vectors (${vectors.length}) != docs (${docs.length})`)
  if (ids !== undefined && ids.length !== vectors.length) {
    throw new Error(`ids (${ids.length}) != vectors (${vectors.length})`)
  }
}

Type guard

function idsMatchLength(ids: string[] | undefined, n: number): ids is string[] {
  return Array.isArray(ids) && ids.length === n
}

Try / catch

try {
  assertIdsAligned(vectors, documents, options?.ids)
  await store.addVectors(vectors, documents, options)
} catch (e) {
  throw e instanceof Error ? e : new Error(String(e))
}

Prevention

When it happens

Trigger: Passing a partial `ids` array (e.g. from a record manager that only tracked some documents), reusing an old ids array after the document list changed length, or off-by-one slicing of ids.

Common situations: Record-manager-driven upsert where `listKeys` returned fewer keys than the documents being re-indexed; caller computed ids from a filtered subset; concurrency added/removed documents between computing ids and calling addVectors.

Related errors


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