Postgres Chat Memory
AI-generatedOverview
This node implements a Postgres-backed chat memory store for AI chat applications. It stores chat messages in a specified Postgres table and retrieves the most recent messages for a given chat session. It supports automatic table creation, limiting the number of retrieved messages to reduce token usage, and optionally filtering messages based on a summary prefix to anchor compacted context summaries. It can operate in read-only mode to prevent writes to the chat memory.
Use Case Examples
- Storing and retrieving chat history for a customer support chatbot, ensuring only the last 10 messages are fetched to optimize token usage.
- Using a summary prefix to anchor a compacted summary in the chat history, improving context management in long conversations.
- Running in read-only mode to fetch chat history without modifying the database, useful for audit or analysis scenarios.
Properties
| Name | Meaning |
|---|---|
| Table Name | The name of the Postgres table to store chat history. The table is created automatically if it does not exist. |
| Session ID | The identifier used for the chat session to segregate chat histories. |
| Context Window Length | The number of most recent messages to retrieve from the database per request, controlling token usage. |
| Summary Prefix | A string prefix to filter messages, skipping all messages before the most recent user or system message starting with this prefix. Useful for anchoring compacted-context summaries. |
| Keep Messages Before Prefix | The number of messages immediately before the matched prefix message to retain when the summary prefix is used. |
| Read Only | Whether to prevent writes to the chat memory, making the node operate in read-only mode. |
Output
JSON
responsechat_history- Array of chat messages retrieved from the Postgres table, respecting the context window length and summary prefix filtering.
Dependencies
- Postgres database connection with credentials
Troubleshooting
- Invalid table name error if the table name contains characters other than letters, digits, or underscores, or does not start with a letter or underscore. Use only valid characters to resolve.
- Error if Session ID is empty; ensure a non-empty session key is provided.
- Database connection errors if Postgres credentials are incorrect or the database is unreachable.
- Potential errors if the Postgres table does not exist; the node attempts to auto-create the table but may fail if permissions are insufficient.