Browser-based chatbots face a fundamental constraint: no server means no persistent memory. Everything must fit in the client's RAM and survive only for the session. ReLU.chat's SessionMemory class solves this with a multi-layered approach.
Turn Storage
Each turn records: query, response, entities, topics, fragments used, ambiguity flag, and timestamp. History is capped at 30 turns with importance-based eviction — the 5 most recent turns are always protected.
Importance-Based Eviction
When the buffer is full, the system doesn't just drop the oldest turn. It computes an importance score for each non-protected turn based on:
- Whether the turn had entities (topic richness)
- Whether the turn was ambiguous (needs context)
- Fragment diversity (how many different fragments were shown)
The least important turn is evicted. This preserves conversation threads that are contextually valuable.
Response Compression
After 5 turns, full response text is compressed to 120-character summaries. This reduces memory pressure without losing the gist of old exchanges. The compression is irreversible — it's a deliberate trade of fidelity for longevity.
EMA Summary Vector
The most powerful mechanism is the Exponential Moving Average (EMA) summary vector. After each turn, the query embedding (384-dimensional) is blended into a running average:
ema_new = α ema_old + (1 - α) new_embedding
With α = 0.75, the vector retains 75% of historical context and 25% of the current turn. This 384-d vector is passed to the policy network as dense multi-turn context — no additional feature extraction needed.
Entity Decay
Entity mentions are tracked with a half-life of 5 turns. An entity mentioned 10 turns ago has ~25% of its original relevance weight. This prevents stale topics from dominating while keeping recent context alive.
Fragment Diversity
The system tracks how many times each knowledge fragment has been shown. After 2 presentations, a quadratic penalty score increases — preventing the chatbot from repeating the same explanations.
Engagement Tracking
Each follow-up is classified as one of: deepening, challenging, clarifying, acknowledging, new_topic, or redirecting. The last 5 signals determine the engagement trend (deepening, broadening, or neutral), which influences the policy's response strategy.
Key Takeaway
Rich session memory doesn't require a server. With importance-based eviction, response compression, EMA vectors, and entity decay, a browser chatbot can maintain coherent 30-turn conversations entirely in client-side memory.