Chat Memory Manager node allways returns all the chat history with Postgres Chat Memory

When using the Chat memory manager node with the Postgres Chat memory, the option in the latter node to limit the Context Window Length, say to 1 or 5, doesnt do anything. Whatever value I put the Chat Memory Manager will return all the messages in the postgres database for that id. I can still filter them later on, but I pressume this is not how it is supposed to work.

anyway, thanks a lot for you hard work. loving n8n so far.
cheers

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.75.2
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

This is a known issue where the Chat Memory Manager node returns all messages from the Postgres Chat Memory regardless of the Context Window Length setting. I found two workarounds. 1)Use a function node limiting up 20 items, or 2)Limit node. One of those could be placed after the Chat Memory node.

Using Function Node
Set a custom node and insert the custom script.

Use a Limit node
Use the Limit node after the Chat Memory Manager node.

  • Set “Max Items” to 20
  • Set “Keep” to “Last Items” to retain the most recent messages

These are workarounds until it’s fixed. I read somewhere that the n8n is aware of this issue and there’s an ongoing discussion about fixing the Context Window Length functionality in the Postgres Chat Memory node.

2 Likes

thanks, if the team is aware I will just wait for an update

1 Like

While the approach suggested (limiting the number after the fact) is a good temporary solution, I don’t think this is a forever-solution. The chat history for my 1 user keeps growing. Right now loading all of the interactions only loads a few hundred messages. But over time this will grow beyond thousands. Obviously this will become a huge memory pain.

Hence my question: Is there work being done so we can enter a ilmit value in the Get Many operation?

Thanks!

EDIT: My bad, i hadn’t correctly read that and realized this is not a missing feature but an actual bug :sweat_smile: Sorry guys! Hope this gets resolved soon!

1 Like

same issue here, I think this needs to be fixed from the team.

I presume the developers have better things to do than solve this small thing. Hence, in order to avoid unnecessary problems in the future as mentioned by @noCreativity, I decided that is better to use a standard Postgres node to the table n8n_chat_histories to only get what is needed. Can also use Code node with the pg library or similar.

I created a new table with the n number of messages i wanted, and it works now.