What are Chat Engines?
Chat engines provide conversational interfaces over your data. Unlike query engines that handle single questions, chat engines:- Maintain chat history for context
- Support follow-up questions
- Enable streaming responses
- Handle multi-turn conversations
Chat Engine Types
LlamaIndex.TS provides several chat engine types:SimpleChatEngine
Basic chat without retrieval (just LLM conversation):ContextChatEngine
Chat with document retrieval for every message:CondenseQuestionChatEngine
Condenses chat history into standalone questions before retrieval:VectorStoreIndex Chat Engine (Recommended)
The easiest way to create a chat engine from an index:Complete Working Example
Here’s a full conversational RAG application:Chat History Management
Accessing Chat History
Get the conversation history:Custom Chat History
Provide initial chat context:Resetting Chat History
Clear the conversation:Streaming Responses
Stream tokens as they’re generated:Streaming with Different Indices
All index types support streaming:CondenseQuestionChatEngine Deep Dive
This engine is ideal for question-focused conversations:How It Works
- Condenses the chat history + new message into a standalone question
- Queries the index with the condensed question
- Returns the answer and updates chat history
Custom Condense Prompt
Customize how questions are condensed:When to Use CondenseQuestionChatEngine
- Questions build on previous context
- Queries are primarily questions (not commands)
- You want explicit question reformulation
When NOT to Use It
- Messages are conversational statements
- Heavy use of pronouns (“it”, “that”, “this”)
- Non-question interactions
Configuration Options
Retrieval Parameters
Control how many chunks to retrieve:Custom Settings
Global configuration:Choosing the Right Chat Engine
| Engine | Use Case | Pros | Cons |
|---|---|---|---|
| SimpleChatEngine | Pure conversation | Fast, no retrieval overhead | No document context |
| ContextChatEngine | General chat over docs | Simple, always has context | May retrieve irrelevant info |
| CondenseQuestionChatEngine | Q&A sessions | Better follow-ups | Only good for questions |
| Index.asChatEngine() | Quick start | Easy setup | Less customization |
Next Steps
- Build Agents with chat capabilities
- Explore Query Engines for single-turn Q&A
- Learn about RAG patterns