Skip to main content
View source

Persistent Memory

View as Markdown

A RocketRide filter node that gives a pipeline cross-session memory keyed by session_id.

What it does

Sits in the pipeline as a pass-through filter on the questions and answers lanes and keeps session state between pipeline runs.

When a question arrives with a session_id in its metadata, the node resumes (or creates) that session and attaches all stored keys to the question as metadata['memory_context'] before forwarding, so downstream nodes such as LLMs can use prior conversation state. Answers for the same session are saved back: the answer text is stored under the key last_answer and an answer_count counter is incremented atomically. An answer without its own session_id falls back to the session of the question currently being processed. Questions and answers with no session_id pass through untouched.

Storage uses a pluggable backend: Redis (via the redis Python client, >=6.4.0,<7.0.0) for production, or a thread-safe in-memory backend for testing. The store is created once per pipe and the backend connection is closed when the pipe ends. The node is marked experimental. All operations deep-copy entries before enrichment so originals are never mutated.


Configuration

Lanes

Lane inLane outDescription
questionsquestionsEnriched with session memory context in metadata, then forwarded
answersanswersStored in session memory, then passed through

Fields

FieldTypeDescription
backendstringDefault "memory". Storage backend: redis (production) or memory (testing)
redis_hoststringDefault "localhost". Redis server hostname
redis_portnumberDefault 6379. Redis server port
redis_passwordstringRedis server password (leave empty for no auth)
session_ttl_hoursnumberDefault 0. How long sessions persist before auto-expiry (0 = no expiry)
max_historynumberDefault 100. Maximum history entries per session before auto-summarization
auto_summarizebooleanDefault true. Automatically summarize older history entries when limit is reached

Profiles

ProfileBehaviour
memoryDefault. In-process backend, no setup needed; no TTL (session_ttl_hours: 0)
redisRedis at localhost:6379, 24-hour session TTL
customRedis backend with an empty host for you to fill in; no TTL

The memory backend is in-process and intended for testing: its contents live only as long as the engine process. For production, select the redis backend and point it at a reachable Redis instance.


Sessions

Sessions are identified by the session_id value in question or answer metadata. A valid session_id is 1-128 characters of alphanumerics, hyphens, or underscores; this is enforced to prevent injection into Redis key names. A malformed session_id does not fail the pipeline: the node logs a debug message and forwards the entry unchanged.

Memory keys (for example last_answer) follow the same character rules but also allow dots and may be up to 256 characters long.

  • TTL: with session_ttl_hours > 0, every key belonging to a session expires together. In Redis this uses native key expiry kept aligned across data, key-set, history, and metadata keys. The in-memory backend prunes expired sessions lazily on access. A value of 0 means sessions never expire.
  • In-memory cap: the in-memory backend holds at most 1000 concurrent sessions; creating more returns an error.
  • Atomic counters: answer_count increments are atomic: native INCRBY in Redis, lock-protected in the in-memory backend.

History and auto-summarization

Every put, increment, and clear appends an operation record (op, key, timestamp) to the session's history. History records operations, not values. When auto_summarize is true and a session's history grows beyond max_history, older entries are compressed: the newest max_history // 2 entries are kept intact and everything older is replaced by a single summary entry recording how many entries were summarized, the counts per operation type, and which keys were touched.


Redis key layout

All Redis keys live under the rr:memory prefix:

KeyContents
rr:memory:{session_id}:{key}Stored values (JSON-serialized)
rr:memory:{session_id}:__keys__Set of keys in the session
rr:memory:{session_id}:__history__List of history entries
rr:memory:{session_id}:__meta__Hash with session metadata
rr:memory:__sessions__Set of all session IDs

Running the tests

# Store unit tests + node tests (in-memory backend, no Redis needed)
pytest nodes/test/memory_persistent -v

Schema

FieldTypeDescriptionDefault
auto_summarizebooleanAuto-Summarize
Automatically summarize older history entries when limit is reached
true
backendstringBackend
Storage backend: redis (production) or memory (testing)
"memory"
max_historynumberMax History Entries
Maximum history entries per session before auto-summarization
100
redis_hoststringRedis Host
Redis server hostname
"localhost"
redis_passwordstringRedis Password
Redis server password (leave empty for no auth)
redis_portnumberRedis Port
Redis server port
6379
session_ttl_hoursnumberSession TTL (hours)
How long sessions persist before auto-expiry (0 = no expiry)
0

Dependencies

  • redis