Home Explore Blog CI



ragit

docs/multi_turn.md
a79a55b22d1c350a7271063d3202b88713fabb4f6d8e74a300000003000007dd
# Multi-turn Queries

What is a "multi-turn" query? It's one of ragit's strength, but it seems like nobody knows what the term "multi-turn" means. To be honest, I'm not sure whether I'm using the correct term. Anyway, let me explain here what "multi-turn query" is, and why it makes ragit very powerful.

I'll assume that readers have basic knowledge about RAG and ragit.

## Example

Multi-turn query is, basically asking a further question. See very simple example below.

```
<|user|>

How do I create a knowledge-base in ragit?

<|assistant|>

Based on the documents, ... blah blah

...

There are commands like `rag add`, `rag build`, and `rag ii-build`.

<|user|>

Tell me more about the `add` command.
```

It's very natural for users to ask a further question. In order to answer the second question, "Tell me more about the `add` command", ragit has to go through another RAG pipeline. But the problem is that the second question has no context. Without context, you cannot tell whether the `add` command is `git add`, `cargo add` or `rag add`. With typical RAG pipeline, you cannot retrieve chunks related to ragit from the query. If you put the entire conversation into the pipeline, the context would be contaminated.

## Solution

So, ragit implements a simple query-rewrite prompt. It asks an LLM to rephrase the user query so that the rephrased query includes all the context. Below is how the rephrased query looks like.

> Can you provide more information about the `rag add` command and how it is used to create a knowledge-base in Ragit?

Ragit runs a typical pipeline with this rephrased query!

## How to use

If you're using ragit cli, the only way to use multi-turn query is to `rag query --interactive`. There's no other handy way to use it. There must be one.

If you're building an application on top of ragit's Rust API, use [`Index::query`](https://docs.rs/ragit/latest/ragit/struct.Index.html#method.query) function. It takes outputs from the result of previous `Index::query` calls.

Chunks
67139bbc (1st chunk of `docs/multi_turn.md`)
Title: Understanding Multi-Turn Queries in Ragit
Summary
A multi-turn query refers to asking a further question based on a previous query, requiring context to be understood, and ragit addresses this by implementing a query-rewrite prompt that rephrases the user query to include necessary context.