{"record":{"id":"04e0994bd045311f","repo":"FlowiseAI/Flowise","slug":"the-collection-s-primaryfield-is-configured-with-a","errorCode":null,"errorMessage":"The Collection's primaryField is configured with autoId=false, thus its value must be provided through metadata.","messagePattern":"The Collection's primaryField is configured with autoId=false, thus its value must be provided through metadata\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/vectorstores/Milvus/Milvus.ts","lineNumber":436,"sourceCode":"            return\n        }\n        await this.ensureCollection(vectors, documents)\n\n        const insertDatas: InsertRow[] = []\n\n        for (let index = 0; index < vectors.length; index++) {\n            const vec = vectors[index]\n            const doc = documents[index]\n            const data: InsertRow = {\n                [this.textField]: doc.pageContent,\n                [this.vectorField]: vec\n            }\n            this.fields.forEach((field) => {\n                switch (field) {\n                    case this.primaryField:\n                        if (!this.autoId) {\n                            if (doc.metadata[this.primaryField] === undefined) {\n                                throw new Error(\n                                    `The Collection's primaryField is configured with autoId=false, thus its value must be provided through metadata.`\n                                )\n                            }\n                            data[field] = doc.metadata[this.primaryField]\n                        }\n                        break\n                    case this.textField:\n                        data[field] = doc.pageContent\n                        break\n                    case this.vectorField:\n                        data[field] = vec\n                        break\n                    default: // metadata fields\n                        if (doc.metadata[field] === undefined) {\n                            throw new Error(`The field \"${field}\" is not provided in documents[${index}].metadata.`)\n                        } else if (typeof doc.metadata[field] === 'object') {\n                            data[field] = JSON.stringify(doc.metadata[field])\n                        } else {","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/vectorstores/Milvus/Milvus.ts#L418-L454","documentation":"Thrown during Milvus upsert/insert when the collection's primary key field is configured with `autoId=false` but the document's metadata does not contain a value under the `primaryField` key. Milvus requires an explicit primary key value when auto-ID generation is disabled, and this node sources that value exclusively from `doc.metadata[primaryField]`.","triggerScenarios":"Adding documents via `addVectors`/upsert to a Milvus collection whose schema declares the primary field as a non-auto-generated ID, while the supplied `Document.metadata` object lacks the primary-field key. Also triggered when the field name is misconfigured (e.g. `id` vs `pk`) so the lookup misses.","commonSituations":"User created a collection with an explicit-ID primary key in Milvus and then pointed Flowise at it without injecting IDs into document metadata; primary field was renamed in the schema but the node config still references the old name; documents ingested from a loader that strips metadata.","solutions":["Set `doc.metadata[this.primaryField]` to a unique value for every document before calling addVectors.","Enable `autoId=true` on the Milvus collection so IDs are generated server-side and this branch is skipped.","Verify the configured primary field name exactly matches the collection schema field (case-sensitive).","If using a loader/upstream node, ensure it preserves or injects the primary-key metadata."],"exampleFix":"// before — metadata lacks the primary key\nconst docs = texts.map(t => new Document({ pageContent: t, metadata: {} }))\n// after — inject a unique primary key for each doc\nconst docs = texts.map((t, i) => new Document({\n    pageContent: t,\n    metadata: { [primaryField]: `doc-${i}-${Date.now()}` }\n}))","handlingStrategy":"validation","validationCode":"function validatePrimaryKeys(docs: Document[], primaryField: string, autoId: boolean) {\n  if (autoId) return\n  const missing = docs\n    .map((d, i) => (d.metadata?.[primaryField] === undefined ? i : -1))\n    .filter(i => i >= 0)\n  if (missing.length) throw new Error(`Missing '${primaryField}' in metadata for docs at indices: ${missing.join(', ')}`)\n}","typeGuard":"function hasPrimaryKey(doc: Document, primaryField: string): boolean {\n  const v = doc.metadata?.[primaryField]\n  return v !== undefined && v !== null && v !== ''\n}","tryCatchPattern":"try {\n  validatePrimaryKeys(documents, this.primaryField, this.autoId)\n  await store.addVectors(vectors, documents)\n} catch (e) {\n  throw e instanceof Error ? e : new Error(String(e))\n}","preventionTips":["If autoId=false, inject a unique primary key into every document's metadata before insert.","Use a consistent id-generator (e.g. uuid) to avoid collisions.","Validate the primary field name matches the collection schema (case-sensitive).","Add a preflight check listing documents missing the key."],"tags":["milvus","upsert","validation","metadata"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}