i’ve created a db locally in postgres and when i try uploading the data into the db it errors, i figured its because the data the postgres pgvector store sends is only 4 fields which are id, embedding, content and metadata.
I dont want all my data in a document to be inside a metadata field but in a normnal field in my db. i cant figure it out, tried for a day.
Hi @michael13 Welcome!
The PGVector node writes only the four columns it maps, and the Column Names option renames those four rather than adding any, so chunk_index and every other column on document_chunks stays null on insert. Put the fields you want as real columns into the Default Data Loader’s Metadata option, then let Postgres copy them out of the metadata jsonb with a before-insert trigger. chunk_index is per chunk rather than per document, so the loader can’t supply it, number it in the trigger instead:
create or replace function document_chunks_fill()
returns trigger as $$
begin
NEW.chunk_index := coalesce(
(select max(chunk_index) + 1 from document_chunks
where metadata->>'doc_id' = NEW.metadata->>'doc_id'), 0);
return NEW;
end;
$$ language plpgsql;
create trigger document_chunks_before_ins
before insert on document_chunks
for each row execute function document_chunks_fill();
Set doc_id in the loader Metadata so the counter has something to group on, and add one NEW.<column> := NEW.metadata->>'<key>'; line for every other column you want filled.
The existing reply is right that the native PGVector node writes only its mapped ID, vector, content, and metadata columns. That means your document_chunks schema is not compatible with this writer while chunk_index or any other unmapped column is NOT NULL without a database default.
I would not use the max(chunk_index) + 1 trigger as written. Two inserts for the same document can read the same maximum before either commits and choose the same next value. A unique constraint can detect that collision, but it will still fail one insert.
For the design you described, keep ordinary business fields in a normal documents table. Store the embeddings and chunk text in the vector table, and keep only a stable doc_id in vector metadata so you can join the retrieved chunks back to the relational row. That avoids copying every business field into metadata.
Then choose chunk_index semantics explicitly. If it only needs to be globally unique, use a database-generated identity or sequence. If it must be numbered separately inside each document, use a custom writer that populates real doc_id and chunk_index columns, serializes assignment per document, and enforces UNIQUE (doc_id, chunk_index). Do not apply exact ALTER TABLE SQL until you inspect the current table DDL.
If you require zero metadata, including no doc_id link, the native PGVector node is the wrong writer for this schema; use a custom Postgres insert path instead.