---
title: ChatEngine
---

The chat engine is a quick and simple way to chat with the data in your index.

```typescript
const retriever = index.asRetriever();
const chatEngine = new ContextChatEngine({ retriever });

// start chatting
const response = await chatEngine.chat({ message: query });
```

In short, you can use the chat engine by calling `index.asChatEngine()`. It will return a `ContextChatEngine` to start chatting.

```typescript
const chatEngine = index.asChatEngine();
```

You can also pass in options to the chat engine.

```typescript
const chatEngine = index.asChatEngine({
  similarityTopK: 5,
  systemPrompt: "You are a helpful assistant.",
});
```


The `chat` function also supports streaming, just add `stream: true` as an option:

```typescript
const chatEngine = index.asChatEngine();
const stream = await chatEngine.chat({ message: query, stream: true });
for await (const chunk of stream) {
  process.stdout.write(chunk.response);
}
```

## Api References

- [ContextChatEngine](/docs/api/classes/ContextChatEngine)
- [CondenseQuestionChatEngine](/docs/api/classes/CondenseQuestionChatEngine)
- [SimpleChatEngine](/docs/api/classes/SimpleChatEngine)
