Session
ConceptsA session is a chat conversation with message history. When you chat with a knowledge base, each conversation is a session. Context from previous messages is preserved for multi-turn RAG chat, enabling follow-up questions like "What about the second one?" or "Summarize that."
Session Features
| Feature | Description |
|---|---|
| History | Past messages are retained; scroll back through conversation |
| Context | Follow-up questions use conversation context; the LLM understands "it" and "that" |
| Export | Download session content as text or markdown |
| Sharing | Share read-only links to sessions for collaboration |
Sessions are scoped to a knowledge base. When you start a chat, you select the knowledge base; the session searches only those documents.
Session Lifecycle
- Create — A new session is created when you start a chat without a
session_id, or when you explicitly create one via API - Continue — Pass
session_idin chat requests to continue an existing session - Archive — Sessions can be archived or deleted; history is retained until then
Create or continue a session by passing session_id in chat requests. If omitted, a new session is created. The API returns the session_id in responses so you can persist it and resume later.
Mem0 Compression
DocLD uses memory compression (Mem0) to summarize long conversations, keeping context relevant without exceeding LLM context limits. When a session grows long:
- Summarize — Older messages are summarized into a compact representation
- Retain — Recent messages and the summary are kept in context
- Generate — The LLM receives the summary + recent messages for coherent multi-turn chat
This improves quality for extended chats. Without compression, very long conversations would exceed the context window and lose early context.
API Usage
# Start a new session (omit session_id) POST /api/chat { "message": "What is the total amount?", "knowledge_base_id": "..." } # Continue a session POST /api/chat { "message": "What about the second invoice?", "session_id": "..." }
The response includes session_id for continuation. Sessions are tied to the knowledge base used when they were created.
Best Practices
- Persist session IDs — Store
session_idin your app (e.g., cookie, local storage) to resume conversations - Scope by use case — Create new sessions when the user switches topics or knowledge bases
- Export for compliance — Use session export for audit trails or compliance records
Related Concepts
Sessions enable multi-turn RAG chat. Knowledge bases scope which documents are searched. The LLM uses session context to generate coherent, contextual answers.