If my cutoff window for chat is 10, when the user hits chat 11, it means chat #1 is no longer in the context window. Essentially I’m working with a sliding window. Is there an example using a summarization technique with n8n on how to keep a longer chat history running knowing, the chat memory module will only keep the last 10 chats. Its kind of starts to get expensive if you are having to summarize after every chat once you get past 10
Hello SpencerB, thank you for asking! I’ll try to help yaa.
You’re right, with Postgres Memory Chat (or any chat memory) a cutoff of 10 gives you a sliding window. The fix is a hybrid memory, keep last 10 turns as short term, plus a rolling long-term summary you refresh only sometimes (not every turn).
How to set it up?
Load short-term: Postgres Memory Chat (limit it to 10).
Fetch long-term summary from Supabase table thread_summaries (by conversation_id)
Build prompt to the model for system: “You have a running summary: <summary_so_far>”, context: last 10 turns from memory
Answer normally.
Occasionally summarize (every N turns or when tokens high), then upsert the new summary back to thread_summaries.
When to summarize? (so its not every turn)
Use a tiny Code node right after Memory to decide: