Cross-Session Context
Category: Retrieval
Problem
Users interact with AI assistants across multiple sessions — sometimes hours apart, sometimes days. Without cross-session context, the assistant cannot reference previous conversations, leading to repetitive interactions and a feeling that the AI "doesn't know me."
Architecture
Use Dakera's session API to explicitly track session boundaries, and the recall API to pull relevant context from previous sessions into the current one. Each session's key decisions and outcomes are stored as memories, creating a queryable history.
Flow
- Start a new session when the user connects
- Recall relevant memories from all previous sessions based on the user's first message
- Inject recalled context into the system prompt
- Store key outcomes and decisions during the session
- End the session when the user disconnects
Implementation
from dakera import Dakera
client = Dakera(base_url="http://localhost:3300", api_key="dk-...")
# Start a new session
session = client.sessions.start(
namespace="user-bob",
metadata={"channel": "web", "topic": "project-planning"}
)
# When user sends their first message, recall cross-session context
def on_new_conversation(user_id: str, first_message: str):
# Recall relevant memories from ALL previous sessions
context = client.memory.recall(
query=first_message,
namespace=f"user-{user_id}",
top_k=10
)
return context["results"]
# During the session, store important information
client.memory.store(
content="Decided to use PostgreSQL instead of MongoDB for the project",
namespace="user-bob",
metadata={
"session_id": session["session_id"],
"type": "decision",
"importance": 0.85
}
)
# Store a project status update
client.memory.store(
content="API design phase completed. Moving to implementation next week.",
namespace="user-bob",
metadata={
"session_id": session["session_id"],
"type": "status",
"project": "backend-redesign"
}
)
# End the session
client.sessions.end(session_id=session["session_id"])
# Next session — weeks later:
new_session = client.sessions.start(namespace="user-bob")
# User says: "How's the backend project going?"
memories = client.memory.recall(
query="backend project status",
namespace="user-bob",
top_k=5
)
# Returns: "API design phase completed. Moving to implementation next week."
# "Decided to use PostgreSQL instead of MongoDB for the project"
When to Use This Pattern
- Any conversational AI that serves returning users
- Project management assistants tracking progress over time
- Customer support that needs conversation history
- Personal assistants that build context over weeks/months
Key Considerations
- Store decisions and outcomes, not raw conversation — raw chat is noisy for future recall
- Use metadata to tag by session_id for provenance tracking
- Combine with the summarization pattern to consolidate old sessions
- The recall API uses hybrid retrieval, so temporal phrases like "last meeting" and semantic queries both work