Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: Use Milvus/Zilliz to build RAG on Arm Architecture
title: Build a Retrieval-Augmented Generation (RAG) application using Zilliz Cloud on Arm servers

minutes_to_complete: 20

who_is_this_for: This is an introductory topic for engineers who want to create a RAG application on Arm machines.
who_is_this_for: This is an introductory topic for software developers who want to create a RAG application on Arm servers.

learning_objectives:
- Create a simple RAG application using Milvus/Zilliz
- Launch LLM service on Arm machines
- Create a simple RAG application using Zilliz Cloud
- Launch a LLM service on Arm servers

prerequisites:
- Basic understand of RAG pipeline.
- An [AWS account](/learning-paths/servers-and-cloud-computing/csp/aws/) to access instance types with different AWS Graviton processors.
- A [Zilliz account](https://zilliz.com/cloud), which you can sign up for a free trial.
- Basic understanding of a RAG pipeline.
- An AWS Graviton3 c7g.2xlarge instance, or any [Arm based instance](/learning-paths/servers-and-cloud-computing/csp) from a cloud service provider or an on-premise Arm server.
- A [Zilliz account](https://zilliz.com/cloud), which you can sign up for with a free trial.

author_primary: Chen Zhang

Expand All @@ -23,6 +23,8 @@ armips:
- Cortex-A
tools_software_languages:
- Python
- GenAI
- RAG
operatingsystems:
- Linux

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
next_step_guidance: Thank you for completing the Milvus RAG tutorial.
next_step_guidance: Thank you for completing the RAG with Zilliz Cloud Learning Path. You might be interested in learning how to run the Llama 3.1 8B model with KleidiAI optimizations on Arm servers.

recommended_path: /learning-paths/servers-and-cloud-computing/llama-cpu/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
review:
- questions:
question: >
Can Milvus run on Arm systems?
Can Milvus run on Arm?
answers:
- "Yes"
- "No"
Expand All @@ -12,13 +12,23 @@ review:

- questions:
question: >
Can Llama3.1 model run on Arm systems?
Can Llama3.1 model run on Arm?
answers:
- "Yes"
- "No"
correct_answer: 1
explanation: >
The Llama-3.1-8B model from Meta can be used on an AWS Arm-based server CPU with the llama.cpp tool.
The Llama-3.1-8B model from Meta can be used on Arm-based servers with llama.cpp.

- questions:
question: >
Which of the following is true about about Zilliz Cloud?
answers:
- "It is a fully-managed version of Milvus vector database"
- "It is a self-hosted version of Milvus vector database"
correct_answer: 1
explanation: >
Zilliz Cloud is a fully-managed version of Milvus.



Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: Launch LLM Service on Arm
title: Launch LLM Server
weight: 4

### FIXED, DO NOT MODIFY
layout: learningpathall
---

In this section, we will build and launch the `llama.cpp` service on the Arm-based CPU.
In this section, you will build and run the `llama.cpp` server program using an OpenAI-compatible API on your running AWS Arm-based server instance.

### Llama 3.1 model & llama.cpp

Expand Down Expand Up @@ -69,32 +69,33 @@ The GGUF model format, introduced by the llama.cpp team, uses compression and qu

### Re-quantize the model weights

To re-quantize, run
To re-quantize the model, run:

```bash
./llama-quantize --allow-requantize dolphin-2.9.4-llama3.1-8b-Q4_0.gguf dolphin-2.9.4-llama3.1-8b-Q4_0_8_8.gguf Q4_0_8_8
```

This will output a new file, `dolphin-2.9.4-llama3.1-8b-Q4_0_8_8.gguf`, which contains reconfigured weights that allow `llama-cli` to use SVE 256 and MATMUL_INT8 support.

> This requantization is optimal specifically for Graviton3. For Graviton2, the optimal requantization should be performed in the `Q4_0_4_4` format, and for Graviton4, the `Q4_0_4_8` format is the most suitable for requantization.
This requantization is optimal specifically for Graviton3. For Graviton2, the optimal requantization should be performed in the `Q4_0_4_4` format, and for Graviton4, the `Q4_0_4_8` format is the most suitable for requantization.

### Start the LLM Service
You can utilize the llama.cpp server program and send requests via an OpenAI-compatible API. This allows you to develop applications that interact with the LLM multiple times without having to repeatedly start and stop it. Additionally, you can access the server from another machine where the LLM is hosted over the network.
### Start the LLM Server
You can utilize the `llama.cpp` server program and send requests via an OpenAI-compatible API. This allows you to develop applications that interact with the LLM multiple times without having to repeatedly start and stop it. Additionally, you can access the server from another machine where the LLM is hosted over the network.

Start the server from the command line, and it listens on port 8080:

```shell
```bash
./llama-server -m dolphin-2.9.4-llama3.1-8b-Q4_0_8_8.gguf -n 2048 -t 64 -c 65536 --port 8080
```
```text

The output from this command should look like:

```output
'main: server is listening on 127.0.0.1:8080 - starting the main loop
```

You can also adjust the parameters of the launched LLM to adapt it to your server hardware to obtain ideal performance. For more parameter information, see the `llama-server --help` command.

If you struggle to perform this step, you can refer to the [this documents](https://learn.arm.com/learning-paths/servers-and-cloud-computing/llama-cpu/llama-chatbot/) for more information.

You have started the LLM service on your Arm-based CPU. Next, we directly interact with the service using the OpenAI SDK.
You have started the LLM service on your AWS Graviton instance with an Arm-based CPU. In the next section, you will directly interact with the service using the OpenAI SDK.


Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,66 @@ weight: 3
layout: learningpathall
---

In this section, we will show you how to load private knowledge in our RAG.
In this section, you will learn how to setup a cluster on Zilliz Cloud. You will then learn how to load your private knowledge database into the cluster.

### Create a dedicated cluster

You will need to [register](https://docs.zilliz.com/docs/register-with-zilliz-cloud) for a free account on Zilliz Cloud.

After you register, [create a cluster](https://docs.zilliz.com/docs/create-cluster) on Zilliz Cloud. In this Learning Path, you will create a dedicated cluster deployed in AWS using Arm-based machines to store and retreive the vector data as shown:

![cluster](create_cluster.png)

When you select the `Create Cluster` Button, you should see the cluster running in your Default Project.

![running](running_cluster.png)

{{% notice Note %}}
You can use self-hosted Milvus as an alternative to Zilliz Cloud. This option is more complicated to set up. We can also deploy [Milvus Standalone](https://milvus.io/docs/install_standalone-docker-compose.md) and [Kubernetes](https://milvus.io/docs/install_cluster-milvusoperator.md) on Arm-based machines. For more information about Milvus installation, please refer to the [installation documentation](https://milvus.io/docs/install-overview.md).
{{% /notice %}}

### Create the Collection
We use [Zilliz Cloud](https://zilliz.com/cloud) deployed on AWS with Arm-based machines to store and retrieve the vector data. To quick start, simply [register an account](https://docs.zilliz.com/docs/register-with-zilliz-cloud) on Zilliz Cloud for free.

> In addition to Zilliz Cloud, self-hosted Milvus is also a (more complicated to set up) option. We can also deploy [Milvus Standalone](https://milvus.io/docs/install_standalone-docker-compose.md) and [Kubernetes](https://milvus.io/docs/install_cluster-milvusoperator.md) on ARM-based machines. For more information about Milvus installation, please refer to the [installation documentation](https://milvus.io/docs/install-overview.md).
With the dedicated cluster running in Zilliz Cloud, you are now ready to create a collection in your cluster.

Within your activated python `venv`, start by creating a file named `zilliz-llm-rag.py` and copy the contents below into it:

We set the `uri` and `token` as the [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud.
```python
from pymilvus import MilvusClient

milvus_client = MilvusClient(
uri="<your_zilliz_public_endpoint>", token="<your_zilliz_api_key>"
)

collection_name = "my_rag_collection"

```
Check if the collection already exists and drop it if it does.
Replace <your_zilliz_public_endpoint> and <your zilliz_api_key> with the `URI` and `Token` for your running cluster. Refer to [Public Endpoint and Api key](https://docs.zilliz.com/docs/on-zilliz-cloud-console#free-cluster-details) in Zilliz Cloud for more details.

Now, append the following code to `zilliz-llm-rag.py` and save the contents:

```python
collection_name = "my_rag_collection"
embedding_dim = "384"

if milvus_client.has_collection(collection_name):
milvus_client.drop_collection(collection_name)
```
Create a new collection with specified parameters.

If we don't specify any field information, Milvus will automatically create a default `id` field for primary key, and a `vector` field to store the vector data. A reserved JSON field is used to store non-schema-defined fields and their values.
```python
milvus_client.create_collection(
collection_name=collection_name,
dimension=embedding_dim,
metric_type="IP", # Inner product distance
consistency_level="Strong", # Strong consistency level
)
```
We use inner product distance as the default metric type. For more information about distance types, you can refer to [Similarity Metrics page](https://milvus.io/docs/metric.md?tab=floating)
This code checks if a collection already exists and drops it if it does. You then, create a new collection with the specified parameters.

If you don't specify any field information, Milvus will automatically create a default `id` field for primary key, and a `vector` field to store the vector data. A reserved JSON field is used to store non-schema-defined fields and their values.
You will use inner product distance as the default metric type. For more information about distance types, you can refer to [Similarity Metrics page](https://milvus.io/docs/metric.md?tab=floating)

You can now prepare the data to use in this collection.

### Prepare the data

We use the FAQ pages from the [Milvus Documentation 2.4.x](https://github.com/milvus-io/milvus-docs/releases/download/v2.4.6-preview/milvus_docs_2.4.x_en.zip) as the private knowledge in our RAG, which is a good data source for a simple RAG pipeline.
In this example, you will use the FAQ pages from the [Milvus Documentation 2.4.x](https://github.com/milvus-io/milvus-docs/releases/download/v2.4.6-preview/milvus_docs_2.4.x_en.zip) as the private knowledge that is loaded in your RAG dataset/collection.

Download the zip file and extract documents to the folder `milvus_docs`.

Expand All @@ -53,8 +74,9 @@ wget https://github.com/milvus-io/milvus-docs/releases/download/v2.4.6-preview/m
unzip -q milvus_docs_2.4.x_en.zip -d milvus_docs
```

We load all markdown files from the folder `milvus_docs/en/faq`. For each document, we just simply use "# " to separate the content in the file, which can roughly separate the content of each main part of the markdown file.
You will load all the markdown files from the folder `milvus_docs/en/faq` into your data collection. For each document, use "# " to separate the content in the file, which can roughly separate the content of each main part of the markdown file.

Open `zilliz-llm-rag.py` and append the following code to it:

```python
from glob import glob
Expand All @@ -69,17 +91,17 @@ for file_path in glob("milvus_docs/en/faq/*.md", recursive=True):
```

### Insert data
We prepare a simple but efficient embedding model [all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) that can convert text into embedding vectors.
You will now prepare a simple but efficient embedding model [all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) that can convert the loaded text into embedding vectors.

You will iterate through the text lines, create embeddings, and then insert the data into Milvus.

Append and save the code shown below into `zilliz-llm-rag.py`:

```python
from langchain_huggingface import HuggingFaceEmbeddings

embedding_model = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
```

Iterate through the text lines, create embeddings, and then insert the data into Milvus.

Here is a new field `text`, which is a non-defined field in the collection schema. It will be automatically added to the reserved JSON dynamic field, which can be treated as a normal field at a high level.
```python
from tqdm import tqdm

data = []
Expand All @@ -93,6 +115,14 @@ for i, (line, embedding) in enumerate(

milvus_client.insert(collection_name=collection_name, data=data)
```
```text
Creating embeddings: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 72/72 [00:18<00:00, 3.91it/s]
Run the python script, to check that you have successfully created the embeddings on the data you loaded into the RAG collection:

```bash
python3 python3 zilliz-llm-rag.py
```

The output should look like:
```
Creating embeddings: 72it [00:00, 700672.59it/s]
```

Loading