Smart Memory

Configuration-driven memory management for chatbots

Overview

The "Smart Memory" node provides configuration-driven memory management for chatbot sessions. It allows storing, retrieving, and clearing conversational memory associated with unique session IDs. This is useful in scenarios where chatbots need to maintain context over multiple messages or interactions, enabling more coherent and context-aware responses.

Typical use cases include:

  • Keeping track of recent user and bot messages within a session to provide context for follow-up questions.
  • Retrieving the stored conversation history to feed into language models or other processing nodes.
  • Clearing session memory when a conversation ends or resets.

For example, you can insert new messages into memory as users interact with your chatbot, then retrieve the last N messages to provide context for generating replies.

Properties

Name Meaning
Session ID Unique identifier for the session. Required to distinguish different conversation contexts.
Memory Window Size Number of messages to keep in memory (range: 5 to 70). Controls how much recent history is stored.
Storage Backend Where to store the memory. Currently supports only "In-Memory".
Memory Settings Collection of options affecting memory output:
- Include Timestamp Whether to include timestamps in the returned messages.
- Include Token Estimate Whether to include an estimate of token count in the output.

Note: The above properties are relevant for the "Get Memory" operation.

Output

The node outputs JSON data representing the memory state for the specified session. The structure includes:

  • chatInfo: Metadata about the chat session.
  • messages: An array of message objects representing the stored conversation history.
  • messageCount: The number of messages currently stored in memory.

If enabled, the output also contains:

  • tokenEstimate: An estimated token count of the stored memory content.

If no memory exists for the given session, the output will contain an error message indicating that no memory was found.

The node does not output binary data.

Dependencies

  • The node uses an internal in-memory storage backend for managing memory.
  • No external services or API keys are required.
  • No special environment variables or n8n configurations are necessary beyond standard node setup.

Troubleshooting

  • Empty or missing Session ID: The node requires a non-empty Session ID. If omitted or empty, it throws an error "Session ID is required and cannot be empty".
  • Unsupported storage backend: Currently, only the in-memory backend is supported. Specifying any other backend results in an error listing supported backends.
  • No memory found: When attempting to get memory for a session with no stored data, the node returns an error message in the output JSON indicating no memory was found.
  • Invalid Memory Window Size: Values outside the allowed range (5 to 70) may cause unexpected behavior; ensure the value is within this range.

Links and References

Discussion