2024-05-21 20:53:55 +08:00
---
2025-03-03 15:42:39 +08:00
sidebar_position: 2
2024-05-21 20:53:55 +08:00
slug: /deploy_local_llm
---
2025-04-10 20:09:46 +08:00
# Deploy local models
2024-07-18 11:20:15 +08:00
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
2024-05-21 20:53:55 +08:00
2025-04-10 20:09:46 +08:00
Deploy and run local models using Ollama, Xinference, or other frameworks.
2024-11-26 18:11:39 +08:00
2024-12-18 15:46:31 +08:00
---
2024-09-03 11:18:10 +08:00
RAGFlow supports deploying models locally using Ollama, Xinference, IPEX-LLM, or jina. If you have locally deployed models to leverage or wish to enable GPU or CUDA for inference acceleration, you can bind Ollama or Xinference into RAGFlow and use either of them as a local "server" for interacting with your local models.
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
RAGFlow seamlessly integrates with Ollama and Xinference, without the need for further environment configurations. You can use them to deploy two types of local models in RAGFlow: chat models and embedding models.
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
:::tip NOTE
This user guide does not intend to cover much of the installation or configuration details of Ollama or Xinference; its focus is on configurations inside RAGFlow. For the most current information, you may need to check out the official site of Ollama or Xinference.
:::
2024-05-21 20:53:55 +08:00
2024-12-02 17:28:30 +08:00
## Deploy local models using Ollama
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
[Ollama](https://github.com/ollama/ollama) enables you to run open-source large language models that you deployed locally. It bundles model weights, configurations, and data into a single package, defined by a Modelfile, and optimizes setup and configurations, including GPU usage.
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
:::note
- For information about downloading Ollama, see [here](https://github.com/ollama/ollama?tab=readme-ov-file#ollama).
- For a complete list of supported models and variants, see the [Ollama model library](https://ollama.com/library).
:::
2025-04-07 09:33:55 +08:00
### 1. Deploy Ollama using Docker
2024-06-07 09:06:46 +08:00
2025-05-06 07:57:39 +02:00
Ollama can be [installed from binaries](https://ollama.com/download) or [deployed with Docker](https://hub.docker.com/r/ollama/ollama). Here are the instructions to deploy with Docker:
2024-12-02 17:28:30 +08:00
```bash
2025-05-06 03:47:19 +02:00
$ sudo docker run --name ollama -p 11434:11434 ollama/ollama
> time=2024-12-02T02:20:21.360Z level=INFO source=routes.go:1248 msg="Listening on [::]:11434 (version 0.4.6)"
> time=2024-12-02T02:20:21.360Z level=INFO source=common.go:49 msg="Dynamic LLM libraries" runners="[cpu cpu_avx cpu_avx2 cuda_v11 cuda_v12]"
2024-12-02 17:28:30 +08:00
```
2024-06-07 09:06:46 +08:00
2025-04-07 09:33:55 +08:00
Ensure Ollama is listening on all IP address:
2024-12-02 17:28:30 +08:00
```bash
2025-05-06 03:47:19 +02:00
$ sudo ss -tunlp | grep 11434
> tcp LISTEN 0 4096 0.0.0.0:11434 0.0.0.0:* users:(("docker-proxy",pid=794507,fd=4))
> tcp LISTEN 0 4096 [::]:11434 [::]:* users:(("docker-proxy",pid=794513,fd=4))
2024-12-02 17:28:30 +08:00
```
2025-04-07 09:33:55 +08:00
Pull models as you need. We recommend that you start with `llama3.2` (a 3B chat model) and `bge-m3` (a 567M embedding model):
2024-06-07 09:06:46 +08:00
```bash
2025-05-06 03:47:19 +02:00
$ sudo docker exec ollama ollama pull llama3.2
> pulling dde5aa3fc5ff... 100% ▕████████████████▏ 2.0 GB
> success
2024-06-07 09:06:46 +08:00
```
2024-12-02 17:28:30 +08:00
```bash
2025-05-06 03:47:19 +02:00
$ sudo docker exec ollama ollama pull bge-m3
> pulling daec91ffb5dd... 100% ▕████████████████▏ 1.2 GB
> success
2024-12-02 17:28:30 +08:00
```
2025-05-06 07:57:39 +02:00
### 2. Find Ollama URL and ensure it is accessible
2024-06-07 09:06:46 +08:00
2025-05-06 07:57:39 +02:00
- If RAGFlow runs in Docker, the localhost is mapped within the RAGFlow Docker container as `host.docker.internal`. If Ollama runs on the same host machine, the right URL to use for Ollama would be `http://host.docker.internal:11434/' and you should check that Ollama is accessible from inside the RAGFlow container with:
2024-06-07 09:06:46 +08:00
```bash
2025-05-06 03:47:19 +02:00
$ sudo docker exec -it ragflow-server bash
2025-05-06 07:57:39 +02:00
$ curl http://host.docker.internal:11434/
2025-05-06 03:47:19 +02:00
> Ollama is running
2024-06-07 09:06:46 +08:00
```
2025-04-07 09:33:55 +08:00
- If RAGFlow is launched from source code and Ollama runs on the same host machine as RAGFlow, check if Ollama is accessible from RAGFlow's host machine:
2024-06-07 09:06:46 +08:00
```bash
2025-05-06 07:57:39 +02:00
$ curl http://localhost:11434/
2025-05-06 03:47:19 +02:00
> Ollama is running
2024-06-07 09:06:46 +08:00
```
2025-04-07 09:33:55 +08:00
- If RAGFlow and Ollama run on different machines, check if Ollama is accessible from RAGFlow's host machine:
2024-12-02 17:28:30 +08:00
```bash
2025-05-06 07:57:39 +02:00
$ curl http://${IP_OF_OLLAMA_MACHINE}:11434/
2025-05-06 03:47:19 +02:00
> Ollama is running
2024-12-02 17:28:30 +08:00
```
2024-06-07 09:06:46 +08:00
2025-05-06 03:47:19 +02:00
### 3. Add Ollama
2024-06-07 09:06:46 +08:00
2024-12-07 11:04:36 +08:00
In RAGFlow, click on your logo on the top right of the page **>** **Model providers** and add Ollama to RAGFlow:
2024-06-07 09:06:46 +08:00

2025-05-06 03:47:19 +02:00
### 4. Complete basic Ollama settings
2024-06-07 09:06:46 +08:00
In the popup window, complete basic settings for Ollama:
2025-04-07 09:33:55 +08:00
1. Ensure that your model name and type match those been pulled at step 1 (Deploy Ollama using Docker). For example, (`llama3.2` and `chat`) or (`bge-m3` and `embedding`).
2025-05-06 07:57:39 +02:00
2. In Ollama base URL, put the URL you found in step 2 followed by `/v1`, i.e. `http://host.docker.internal:11434/v1`, `http://localhost:11434/v1` or `http://${IP_OF_OLLAMA_MACHINE}:11434/v1`.
2024-12-02 17:28:30 +08:00
3. OPTIONAL: Switch on the toggle under **Does it support Vision?** if your model includes an image-to-text model.
2024-06-07 09:06:46 +08:00
:::caution WARNING
Improper base URL settings will trigger the following error:
2024-05-21 20:53:55 +08:00
```bash
2024-06-07 09:06:46 +08:00
Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xffff98b81ff0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2024-05-21 20:53:55 +08:00
```
2024-06-07 09:06:46 +08:00
:::
2024-05-21 20:53:55 +08:00
2025-05-06 03:47:19 +02:00
### 5. Update System Model Settings
2024-05-21 20:53:55 +08:00
2024-12-07 11:04:36 +08:00
Click on your logo **>** **Model providers** **>** **System Model Settings** to update your model:
2024-06-07 09:06:46 +08:00
2025-04-07 09:33:55 +08:00
- *You should now be able to find **llama3.2** from the dropdown list under **Chat model**, and **bge-m3** from the dropdown list under **Embedding model**.*
- _If your local model is an embedding model, you should find it under **Embedding model**._
2024-05-21 20:53:55 +08:00
2025-05-06 03:47:19 +02:00
### 6. Update Chat Configuration
2024-05-21 20:53:55 +08:00
2025-04-07 09:33:55 +08:00
Update your model(s) accordingly in **Chat Configuration**.
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
## Deploy a local model using Xinference
2024-05-21 20:53:55 +08:00
2024-07-18 11:20:15 +08:00
Xorbits Inference ([Xinference](https://github.com/xorbitsai/inference)) enables you to unleash the full potential of cutting-edge AI models.
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
:::note
- For information about installing Xinference Ollama, see [here](https://inference.readthedocs.io/en/latest/getting_started/).
- For a complete list of supported models, see the [Builtin Models](https://inference.readthedocs.io/en/latest/models/builtin/).
:::
2024-06-07 14:08:59 +08:00
To deploy a local model, e.g., **Mistral**, using Xinference:
2024-06-07 09:06:46 +08:00
2024-06-07 14:08:59 +08:00
### 1. Check firewall settings
Ensure that your host machine's firewall allows inbound connections on port 9997.
### 2. Start an Xinference instance
2024-05-21 20:53:55 +08:00
```bash
$ xinference-local --host 0.0.0.0 --port 9997
```
2024-06-07 14:08:59 +08:00
### 3. Launch your local model
2024-06-07 09:06:46 +08:00
2024-07-18 11:20:15 +08:00
Launch your local model (**Mistral**), ensuring that you replace `${quantization}` with your chosen quantization method:
2024-05-21 20:53:55 +08:00
```bash
$ xinference launch -u mistral --model-name mistral-v0.1 --size-in-billions 7 --model-format pytorch --quantization ${quantization}
```
2024-06-07 14:08:59 +08:00
### 4. Add Xinference
2024-06-07 09:06:46 +08:00
2024-12-07 11:04:36 +08:00
In RAGFlow, click on your logo on the top right of the page **>** **Model providers** and add Xinference to RAGFlow:
2024-06-07 09:06:46 +08:00

2024-06-07 14:08:59 +08:00
### 5. Complete basic Xinference settings
2024-06-07 09:06:46 +08:00
Enter an accessible base URL, such as `http://<your-xinference-endpoint-domain>:9997/v1`.
2024-07-17 12:29:33 +08:00
> For rerank model, please use the `http://<your-xinference-endpoint-domain>:9997/v1/rerank` as the base URL.
2024-06-07 09:06:46 +08:00
2024-06-07 14:08:59 +08:00
### 6. Update System Model Settings
2024-05-21 20:53:55 +08:00
2024-12-07 11:04:36 +08:00
Click on your logo **>** **Model providers** **>** **System Model Settings** to update your model.
2024-06-07 09:06:46 +08:00
*You should now be able to find **mistral** from the dropdown list under **Chat model**.*
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
> If your local model is an embedding model, you should find your local model under **Embedding model**.
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
### 7. Update Chat Configuration
2024-05-21 20:53:55 +08:00
2024-06-07 09:06:46 +08:00
Update your chat model accordingly in **Chat Configuration**:
2024-05-21 20:53:55 +08:00
2024-11-28 20:09:20 +08:00
> If your local model is an embedding model, update it on the configuration page of your knowledge base.
2024-07-02 18:55:24 +08:00
## Deploy a local model using IPEX-LLM
2024-07-18 11:20:15 +08:00
[IPEX-LLM](https://github.com/intel-analytics/ipex-llm) is a PyTorch library for running LLMs on local Intel CPUs or GPUs (including iGPU or discrete GPUs like Arc, Flex, and Max) with low latency. It supports Ollama on Linux and Windows systems.
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
To deploy a local model, e.g., **Qwen2**, using IPEX-LLM-accelerated Ollama:
2024-07-02 18:55:24 +08:00
### 1. Check firewall settings
Ensure that your host machine's firewall allows inbound connections on port 11434. For example:
```bash
sudo ufw allow 11434/tcp
```
2024-07-18 11:20:15 +08:00
### 2. Launch Ollama service using IPEX-LLM
2024-07-02 18:55:24 +08:00
#### 2.1 Install IPEX-LLM for Ollama
2024-07-18 11:20:15 +08:00
:::tip NOTE
IPEX-LLM's supports Ollama on Linux and Windows systems.
:::
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
For detailed information about installing IPEX-LLM for Ollama, see [Run llama.cpp with IPEX-LLM on Intel GPU Guide](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/llama_cpp_quickstart.md):
- [Prerequisites](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/llama_cpp_quickstart.md#0-prerequisites)
- [Install IPEX-LLM cpp with Ollama binaries](https://github.com/intel-analytics/ipex-llm/blob/main/docs/mddocs/Quickstart/llama_cpp_quickstart.md#1-install-ipex-llm-for-llamacpp)
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
*After the installation, you should have created a Conda environment, e.g., `llm-cpp`, for running Ollama commands with IPEX-LLM.*
2024-07-02 18:55:24 +08:00
#### 2.2 Initialize Ollama
2024-07-18 11:20:15 +08:00
1. Activate the `llm-cpp` Conda environment and initialize Ollama:
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
<Tabs
defaultValue="linux"
values={[
{label: 'Linux', value: 'linux'},
{label: 'Windows', value: 'windows'},
]}>
<TabItem value="linux">
2024-07-02 18:55:24 +08:00
```bash
conda activate llm-cpp
init-ollama
```
2024-07-18 11:20:15 +08:00
</TabItem>
<TabItem value="windows">
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
Run these commands with *administrator privileges in Miniforge Prompt*:
2024-07-02 18:55:24 +08:00
```cmd
conda activate llm-cpp
init-ollama.bat
```
2024-07-18 11:20:15 +08:00
</TabItem>
</Tabs>
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
2. If the installed `ipex-llm[cpp]` requires an upgrade to the Ollama binary files, remove the old binary files and reinitialize Ollama using `init-ollama` (Linux) or `init-ollama.bat` (Windows).
*A symbolic link to Ollama appears in your current directory, and you can use this executable file following standard Ollama commands.*
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
#### 2.3 Launch Ollama service
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
1. Set the environment variable `OLLAMA_NUM_GPU` to `999` to ensure that all layers of your model run on the Intel GPU; otherwise, some layers may default to CPU.
2. For optimal performance on Intel Arc™ A-Series Graphics with Linux OS (Kernel 6.2), set the following environment variable before launching the Ollama service:
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
```bash
export SYCL_PI_LEVEL_ZERO_USE_IMMEDIATE_COMMANDLISTS=1
```
3. Launch the Ollama service:
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
<Tabs
defaultValue="linux"
values={[
{label: 'Linux', value: 'linux'},
{label: 'Windows', value: 'windows'},
]}>
<TabItem value="linux">
2024-07-02 18:55:24 +08:00
```bash
export OLLAMA_NUM_GPU=999
export no_proxy=localhost,127.0.0.1
export ZES_ENABLE_SYSMAN=1
source /opt/intel/oneapi/setvars.sh
export SYCL_CACHE_PERSISTENT=1
./ollama serve
```
2024-07-18 11:20:15 +08:00
</TabItem>
<TabItem value="windows">
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
Run the following command *in Miniforge Prompt*:
2024-07-02 18:55:24 +08:00
```cmd
set OLLAMA_NUM_GPU=999
set no_proxy=localhost,127.0.0.1
set ZES_ENABLE_SYSMAN=1
set SYCL_CACHE_PERSISTENT=1
ollama serve
```
2024-07-18 11:20:15 +08:00
</TabItem>
</Tabs>
2024-07-02 18:55:24 +08:00
2024-07-08 19:30:29 +08:00
2024-07-18 11:20:15 +08:00
:::tip NOTE
To enable the Ollama service to accept connections from all IP addresses, use `OLLAMA_HOST=0.0.0.0 ./ollama serve` rather than simply `./ollama serve`.
:::
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
*The console displays messages similar to the following:*
2024-07-02 18:55:24 +08:00
2024-07-08 19:30:29 +08:00

2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
### 3. Pull and Run Ollama model
#### 3.1 Pull Ollama model
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
With the Ollama service running, open a new terminal and run `./ollama pull <model_name>` (Linux) or `ollama.exe pull <model_name>` (Windows) to pull the desired model. e.g., `qwen2:latest`:
2024-07-02 18:55:24 +08:00
2024-07-08 19:30:29 +08:00

2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
#### 3.2 Run Ollama model
<Tabs
defaultValue="linux"
values={[
{label: 'Linux', value: 'linux'},
{label: 'Windows', value: 'windows'},
]}>
<TabItem value="linux">
2024-07-02 18:55:24 +08:00
```bash
./ollama run qwen2:latest
```
2024-07-18 11:20:15 +08:00
</TabItem>
<TabItem value="windows">
2024-07-02 18:55:24 +08:00
```cmd
ollama run qwen2:latest
```
2024-07-18 11:20:15 +08:00
</TabItem>
</Tabs>
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
### 4. Configure RAGflow
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
To enable IPEX-LLM accelerated Ollama in RAGFlow, you must also complete the configurations in RAGFlow. The steps are identical to those outlined in the *Deploy a local model using Ollama* section:
2024-07-02 18:55:24 +08:00
2024-07-18 11:20:15 +08:00
1. [Add Ollama](#4-add-ollama)
2. [Complete basic Ollama settings](#5-complete-basic-ollama-settings)
3. [Update System Model Settings](#6-update-system-model-settings)
4. [Update Chat Configuration](#7-update-chat-configuration)
2024-09-03 11:18:10 +08:00
## Deploy a local model using jina
To deploy a local model, e.g., **gpt2**, using jina:
### 1. Check firewall settings
Ensure that your host machine's firewall allows inbound connections on port 12345.
```bash
sudo ufw allow 12345/tcp
```
### 2. Install jina package
```bash
pip install jina
```
### 3. Deploy a local model
Step 1: Navigate to the **rag/svr** directory.
```bash
cd rag/svr
```
Step 2: Run **jina_server.py**, specifying either the model's name or its local directory:
```bash
python jina_server.py --model_name gpt2
```
2025-05-06 03:47:19 +02:00
> The script only supports models downloaded from Hugging Face.