Skip to content

Postgres Chat Memory Node Returns Full Table Instead of Limited Context Window #12958

Description

@mdaviesnz

Bug Description

I am encountering an issue with the Postgres Chat Memory node in n8n where the query to the PostgreSQL database does not respect the "Context Window Length" setting. Despite setting this value to a low number, the query retrieves the full table rather than limiting the amount of historical chat data being returned.
This issue significantly impacts performance when using persistent chat memory, as the full history is unnecessarily loaded.

To Reproduce

  1. Configure the Postgres Chat Memory node in a workflow.
  2. Set "Context Window Length" to a low number (e.g., 5 or 10).
  3. Use a fixed session key to ensure chat memory persists across sessions.
  4. Observe the query execution and response time.
  5. Check the node output and see that all rows are being returned instead of only the expected limited number.

Expected behavior

The query should retrieve only the specified number of recent chat history entries based on the "Context Window Length" setting, improving performance and reducing response time.

Operating System

Docker Image: docker.n8n.io/n8nio/n8n

n8n Version

1.76.1

Node.js Version

20.18.2

Database

PostgreSQL

Execution mode

main (default)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions