{"record":{"id":"dcb772b1305e132c","repo":"FlowiseAI/Flowise","slug":"error-inserting-chunk-0-pagecontent","errorCode":null,"errorMessage":"Error inserting: ${chunk[0].pageContent}","messagePattern":"Error inserting: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/vectorstores/Postgres/driver/TypeORM.ts","lineNumber":148,"sourceCode":"                    id: documentOptions?.ids?.length ? documentOptions.ids[idx] : uuid(),\n                    pageContent: sanitizedDocs[idx].pageContent,\n                    embedding: embeddingString,\n                    metadata: sanitizedDocs[idx].metadata\n                }\n                return documentRow\n            })\n\n            const documentRepository = instance.appDataSource.getRepository(instance.documentEntity)\n            const _batchSize = this.nodeData.inputs?.batchSize\n            const chunkSize = _batchSize ? parseInt(_batchSize, 10) : 500\n\n            for (let i = 0; i < rows.length; i += chunkSize) {\n                const chunk = rows.slice(i, i + chunkSize)\n                try {\n                    await documentRepository.save(chunk)\n                } catch (e) {\n                    console.error(e)\n                    throw new Error(`Error inserting: ${chunk[0].pageContent}`)\n                }\n            }\n        }\n\n        instance.addDocuments = async (documents: Document[], options?: { ids?: string[] }): Promise<void> => {\n            const texts = documents.map(({ pageContent }) => pageContent)\n            // Ensure table exists before adding documents (this will create the table if it does not exist)\n            await this.ensureTableInDatabase(instance, effectiveTablePath)\n            return (instance.addVectors as any)(await this.getEmbeddings().embedDocuments(texts), documents, options)\n        }\n\n        return instance\n    }\n\n    get computedOperatorString() {\n        const { distanceStrategy = 'cosine' } = this.nodeData.inputs || {}\n\n        switch (distanceStrategy) {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/vectorstores/Postgres/driver/TypeORM.ts#L130-L166","documentation":"Thrown by the TypeORM Postgres driver's chunked `documentRepository.save(chunk)` when the underlying TypeORM insert fails. The error message only includes the `pageContent` of the first document in the failed chunk — the original exception is logged via `console.error` but NOT propagated on the thrown error, so the precise DB reason is only in server logs.","triggerScenarios":"TypeORM save fails due to: vector dimension mismatch with the column, NOT NULL constraint violation, unique constraint duplicate, foreign key violation, column type coercion failure, connection drop mid-batch, or `pgvector` extension missing.","commonSituations":"Embedding model changed dimension without migrating the table; metadata field typed differently than the column; duplicate primary keys on retry; very large batch hitting statement timeout; transaction deadlock.","solutions":["Check server/console logs for the `console.error(e)` output — the real DB error is there, not in the thrown message.","Verify the vector column dimension matches the embedding model output.","Confirm NOT NULL / unique constraints are satisfied by every row in the chunk.","Reduce `batchSize` to narrow down which row fails and to avoid statement timeouts.","Ensure `pgvector` extension is installed and the table schema matches the document shape."],"exampleFix":"// before\n} catch (e) {\n    console.error(e)\n    throw new Error(`Error inserting: ${chunk[0].pageContent}`)\n}\n// after — propagate the underlying DB reason\n} catch (e) {\n    throw new Error(`Error inserting chunk starting with \"${chunk[0].pageContent.slice(0, 80)}\": ${e instanceof Error ? e.message : String(e)}`)\n}","handlingStrategy":"try-catch","validationCode":"// preflight: dimension + NOT NULL checks\nconst dim = (await this.getEmbeddings().embedDocuments([rows[0].content ?? rows[0].pageContent])[0]).length\nif (columnDim && dim !== columnDim) throw new Error(`vector dim ${dim} != column ${columnDim}`)\nfor (const r of rows) {\n  for (const nnCol of notNullColumns) {\n    if (r[nnCol] === undefined || r[nnCol] === null) throw new Error(`NULL in NOT NULL column '${nnCol}'`)\n  }\n}","typeGuard":"function isTypeORMQueryError(e: unknown): boolean {\n  const msg = e instanceof Error ? e.message : String(e)\n  return /duplicate key|violates|invalid input syntax|different vector dimension/i.test(msg)\n}","tryCatchPattern":"try {\n  await documentRepository.save(chunk)\n} catch (e) {\n  const reason = e instanceof Error ? e.message : String(e)\n  throw new Error(`Error inserting chunk (size ${chunk.length}) starting with \"${chunk[0].pageContent.slice(0, 80)}\": ${reason}`)\n}","preventionTips":["Keep the vector column dimension aligned with the embedding model.","Satisfy NOT NULL / unique constraints for every row.","Reduce batchSize to isolate failing rows and avoid statement timeouts.","Ensure pgvector is installed; propagate the DB reason in the thrown error."],"tags":["postgres","typeorm","insert","data-integrity","error-handling"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}