Postgres Chat Memory
Postgres Chat Memory is a component that keeps a record of all the messages exchanged in a chat session. It stores each message in a PostgreSQL database so that the conversation can be retrieved later, allowing the system to remember past interactions.
How it Works
When you add this component to your workflow, it connects to a PostgreSQL database using a connection string you provide. Each chat session has a unique Session ID. The component writes every message that belongs to that session into a table in the database. Later, when the same session ID is used again, the component reads the stored messages and makes them available for the next part of the workflow. This way, the conversation history is preserved across different runs of the automation.
The component does not call any external APIs; it only talks to the PostgreSQL database you have set up.
Inputs
Before you can use the component, you must set up a Postgres SQL credential in Nappai’s credential manager.
- Go to the Credentials section of Nappai and create a new credential of type Postgres SQL.
- Enter the PostgreSQL Server Connection URL (this is the password‑protected URL that lets Nappai reach your database).
- In the component, select that credential in the Credential field.
Input Fields
The following field is available to configure this component.
- Session ID: A unique identifier for the chat session. The component uses this ID to store and retrieve messages that belong to the same conversation.
Outputs
- Memory: An object that represents the chat history for the given session. This output can be passed to other components that need to read or write messages in the conversation.
Usage Example
- Create a Postgres SQL credential in the Credentials section of Nappai.
- Add the Postgres Chat Memory component to your workflow.
- Select the credential you just created in the component’s Credential field.
- Enter a Session ID (e.g.,
chat_12345
). - Connect the Memory output to a component that needs the conversation history, such as a language‑model component that continues the chat.
When the workflow runs, the component will store every message from the session in the PostgreSQL database and provide the full history back to the next component.
Related Components
- InMemory Chat Memory – Keeps chat history only in memory (no database).
- Redis Chat Memory – Stores chat history in a Redis cache.
- OpenAI Chat Memory – Uses OpenAI’s embeddings to retrieve relevant past messages.
Tips and Best Practices
- Use a unique Session ID for each conversation to avoid mixing messages from different users.
- Keep the PostgreSQL database secure and restrict access to only the Nappai service.
- If you need to archive old conversations, set up a scheduled job to clean up old rows in the database.
Security Considerations
- The PostgreSQL connection string contains sensitive credentials. Store it in a secure credential store and never expose it in logs or UI.
- Ensure that the database user has only the necessary permissions (e.g., read/write to the chat history table, no superuser rights).
- Use SSL/TLS when connecting to the database to protect data in transit.