Overview
Chat engines enable conversational interactions with your data, maintaining chat history and context across multiple turns.BaseChatEngine
Abstract base class for all chat engines.Properties
ChatMessage[] | Promise<ChatMessage[]>
The conversation history
Methods
method
Send a message and get a responseNon-streaming:Streaming:
SimpleChatEngine
Basic chat engine without retrieval, just conversational LLM.Example
ContextChatEngine
Chat engine with retrieval - retrieves relevant context for each message.Constructor Options
BaseRetriever
required
Retriever for fetching relevant context
LLM
Language model (defaults to Settings.llm)
ChatMessage[]
Initial chat history
string
System prompt for the chat
string
Template for injecting retrieved context
Example
Streaming Chat
Multi-modal Chat
Chat engines support images and other media:Custom Chat History
Using ChatMemoryBuffer
Manual Chat History
System Prompts
Setting System Prompt
Custom Context Template
Chat History Management
Accessing Chat History
Resetting Chat History
Retrieval Configuration
Custom Chat Engine
Best Practices
- Use context chat engine for RAG: Retrieves relevant information for each turn
- Manage token limits: Use ChatMemoryBuffer to prevent context overflow
- Provide clear system prompts: Guide the assistant’s behavior
- Stream long responses: Better user experience for lengthy answers
- Reset history periodically: Prevent context from becoming too large or stale
- Include source nodes: Track which documents informed the response