How to Store user_id in PostgreSQL Chat Memory in n8n?

Hi @

Storing the userId like that is probably not valid via the postgres chat memory node. According to the Postgres Chat Memory node documentation:

… the node is primarily designed to store chat history, and it doesn’t mention capabilities for storing additional user-specific data.

A potential workaround you can try is to use the metadata field:

You can include additional information in the metadata. This example is for the Chat Trigger node but a similar approach might work for the PostgreSQL Chat Memory node.

You could try modifying your Code node to include the user_id in the metadata:

return {
sessionId: $json.sessionId,
question: $json.question,
metadata: {
userId: $json.userId
},
originalData: $json
};

Then, in the PostgreSQL Chat Memory node, you might be able to access this metadata when retrieving the chat history.

Can you try that?