FlowiseAI/Flowise · error · Error

Error inserting: ${chunk[0].pageContent}

Error message

Error inserting: ${chunk[0].pageContent}

What it means

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.

Source

Thrown at packages/components/nodes/vectorstores/Postgres/driver/TypeORM.ts:148

                    id: documentOptions?.ids?.length ? documentOptions.ids[idx] : uuid(),
                    pageContent: sanitizedDocs[idx].pageContent,
                    embedding: embeddingString,
                    metadata: sanitizedDocs[idx].metadata
                }
                return documentRow
            })

            const documentRepository = instance.appDataSource.getRepository(instance.documentEntity)
            const _batchSize = this.nodeData.inputs?.batchSize
            const chunkSize = _batchSize ? parseInt(_batchSize, 10) : 500

            for (let i = 0; i < rows.length; i += chunkSize) {
                const chunk = rows.slice(i, i + chunkSize)
                try {
                    await documentRepository.save(chunk)
                } catch (e) {
                    console.error(e)
                    throw new Error(`Error inserting: ${chunk[0].pageContent}`)
                }
            }
        }

        instance.addDocuments = async (documents: Document[], options?: { ids?: string[] }): Promise<void> => {
            const texts = documents.map(({ pageContent }) => pageContent)
            // Ensure table exists before adding documents (this will create the table if it does not exist)
            await this.ensureTableInDatabase(instance, effectiveTablePath)
            return (instance.addVectors as any)(await this.getEmbeddings().embedDocuments(texts), documents, options)
        }

        return instance
    }

    get computedOperatorString() {
        const { distanceStrategy = 'cosine' } = this.nodeData.inputs || {}

        switch (distanceStrategy) {

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Check server/console logs for the `console.error(e)` output — the real DB error is there, not in the thrown message.
  2. Verify the vector column dimension matches the embedding model output.
  3. Confirm NOT NULL / unique constraints are satisfied by every row in the chunk.
  4. Reduce `batchSize` to narrow down which row fails and to avoid statement timeouts.
  5. Ensure `pgvector` extension is installed and the table schema matches the document shape.

Example fix

// before
} catch (e) {
    console.error(e)
    throw new Error(`Error inserting: ${chunk[0].pageContent}`)
}
// after — propagate the underlying DB reason
} catch (e) {
    throw new Error(`Error inserting chunk starting with "${chunk[0].pageContent.slice(0, 80)}": ${e instanceof Error ? e.message : String(e)}`)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight: dimension + NOT NULL checks
const dim = (await this.getEmbeddings().embedDocuments([rows[0].content ?? rows[0].pageContent])[0]).length
if (columnDim && dim !== columnDim) throw new Error(`vector dim ${dim} != column ${columnDim}`)
for (const r of rows) {
  for (const nnCol of notNullColumns) {
    if (r[nnCol] === undefined || r[nnCol] === null) throw new Error(`NULL in NOT NULL column '${nnCol}'`)
  }
}

Type guard

function isTypeORMQueryError(e: unknown): boolean {
  const msg = e instanceof Error ? e.message : String(e)
  return /duplicate key|violates|invalid input syntax|different vector dimension/i.test(msg)
}

Try / catch

try {
  await documentRepository.save(chunk)
} catch (e) {
  const reason = e instanceof Error ? e.message : String(e)
  throw new Error(`Error inserting chunk (size ${chunk.length}) starting with "${chunk[0].pageContent.slice(0, 80)}": ${reason}`)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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