# RAGFlow

RAGFlow is an open-source engine that answers questions from your own documents. Add the exchange as an OpenAI-API-Compatible provider. RAGFlow then buys its chat answers and its embeddings from the exchange. The exchange auctions each request, sets a cap before the job starts and charges for the measured use.

## Before you start

- A workspace with a balance and a `spend` key. See [API keys](https://inference.ai.exchange/docs/keys.md).
- A RAGFlow server that you can configure.
- A chat model and an embedding model from the book. See [Market data](https://inference.ai.exchange/docs/market.md) and [Embeddings](https://inference.ai.exchange/docs/embeddings.md).

## 1. Add a provider

Open **User settings → Model providers**. Add the **OpenAI-API-Compatible** provider and create an instance. Enter:

```
https://router.inference.ai.exchange/v1
```

The URL ends in `/v1`.

## 2. Paste the key

```
sk-liquid-...
```

## 3. Add the chat model

Add a model to the instance. Set the model type to **chat**. The model name must be an exact name from `GET /v1/models`.

```
liquid.auto
```

Turn on **Tool calling** only for a model that supports tools. To list those models, use `GET /v1/models?feature=tools`.

## 4. Add the embedding model

Add a second model to the same instance. Set the model type to **embedding**. Use a name from `GET /v1/models?kind=embedding`.

```
text-embedding-3-small
```

## 5. Set the defaults

In **Set default models**, choose the chat model and the embedding model. RAGFlow needs both. Then use **Verify** on each model. Verify sends a real request, so each check is a small purchase.

## Notes

- Keep one embedding model for one dataset. RAGFlow ties the vectors of a dataset to the model that made them. Choose the model before you parse documents. A change of model needs a new dataset. See [Embeddings](https://inference.ai.exchange/docs/embeddings.md).
- Name the embedding model. The exchange does not choose one for you, and [Auto Router](https://inference.ai.exchange/docs/auto.md) cannot choose one.
- The exchange has no rerank endpoint. Leave the rerank model empty, or use the rerank model of another provider.
- Parsing a large set of documents makes many embedding requests. A request can have up to 2,048 texts.
- The exchange sets a cap on each request. It is in the `x-liquid-cap-usd` response header. To limit total spend, set a spending limit on the key. See [API keys](https://inference.ai.exchange/docs/keys.md).
- Use a preset for other purchasing rules. See [Purchasing rules](https://inference.ai.exchange/docs/rules.md).

## Troubleshooting

| Symptom                                 | Cause and fix                                                                  |
| --------------------------------------- | ------------------------------------------------------------------------------ |
| `401`                                   | The key is wrong, revoked or expired. Paste it again.                          |
| `404`                                   | Keep `/v1` at the end of the base URL.                                         |
| `model_not_found`                       | The model is not on the book. Use an exact name from `GET /v1/models`.         |
| A request is refused for lack of funds. | The workspace balance cannot cover the cap. Add funds on the **Credits** page. |
| Verify fails for the embedding model.   | The name is not an embedding model. Use a name from `?kind=embedding`.         |

See [Errors](https://inference.ai.exchange/docs/errors.md) for the error codes.

## Next steps

- [Embeddings](https://inference.ai.exchange/docs/embeddings.md): the request, the price and the limits.
- [LlamaIndex](https://inference.ai.exchange/docs/connect-llamaindex.md): the same task in code.
- [Purchasing rules](https://inference.ai.exchange/docs/rules.md): models, strategy and limits, and presets.
