Skip to main content

Conversation History

Overview

RAGLight supports full multi-turn conversations across all LLM providers. User and assistant messages from previous turns are automatically injected into each new request — the model sees the full context of the conversation. This works identically for generate() and generate_streaming(), and is compatible with all providers: Ollama, OpenAI, Mistral, Gemini, LMStudio, and AWS Bedrock.

How it works

Each call to generate() or generate_streaming() accepts an optional history field — a list of {"role": ..., "content": ...} messages. RAGLight injects them into the LLM prompt before the current question. RAGPipeline manages this history automatically. You just call generate() repeatedly and history is accumulated for you.

Usage

Automatic history with RAGPipeline

Capping history length

To limit memory usage in long conversations, set max_history in RAGConfig:
When the cap is reached, the oldest messages are dropped automatically.

Resetting history

Manual history with the Builder API

When using the RAG object directly, pass history explicitly:

History in the REST API

The /generate and /generate/stream endpoints accept a history field:
The Streamlit chat UI (raglight serve --ui) manages this automatically.

Summary

  • RAGPipeline accumulates history automatically across generate() calls
  • Use max_history in RAGConfig to cap the number of messages kept
  • Use pipeline.reset_history() to start a fresh conversation
  • All providers support history — same behavior regardless of backend
  • Works identically with generate() and generate_streaming()