Skip to main content

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:
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

  1. Condenses the chat history + new message into a standalone question
  2. Queries the index with the condensed question
  3. 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

Next Steps