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

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

Key Considerations