You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
AIGC practices
Deploying optimized RAG framework on g4i instances
Copy page
Download PDF
Deploying optimized RAG framework on g4i instances
This topic describes how to deploy an optimized Retrieval-Augmented Generation (RAG) framework on ECS instances of the ecs.g4i type to enhance RAG inference efficiency. The RAG framework consists of core components such as OCR, embedding models, and vector databases.​
Features​
This practice uses the 4th-generation ECS instances of VolcanoEngine, specifically the General-purpose g4i type. This instance type adopts the latest self-developed DPU architecture of VolcanoEngine and is equipped with the 6th-generation Intel® Xeon® Scalable processor (Granite Rapids). This instance type also leverages next-generation hardware AI acceleration instructions AMX-BF16 (Intel Advanced Matrix Extensions) with IPEX framework optimizations based on this technology. These features deliver system-level optimization and accelerate the inference of each core component of the RAG framework.​
Background​
RAG​
RAG is a technology that integrates information retrieval and text generation. It enhances the accuracy and reliability of generative AI models, such as large language models (LLMs), while mitigating model hallucinations.​
  • Information retrieval: Before generating an answer, RAG uses a retrieval system to search extensive text datasets, including local documents, Internet sources, and enterprise databases, for information relevant to the input question or prompt.​
  • Text generation: After obtaining the relevant retrieval results, RAG combines the retrieved document fragments with the user question as input to a generative AI model (for example, an LLM). The model incorporates this retrieved information as supplementary context, processes it alongside the input question or prompt, and then generates the corresponding answer or content.​
OCR​
Optical character recognition (OCR) is a technology that converts printed or handwritten text into machine-readable text. The technology identifies and extracts characters from images or documents, and then converts them into encoded text that can be processed by computers. This topic uses the deployed and optimized OCR tool MinerU as an example. This tool recognizes PDF text through the following steps, where the models used in each step are sourced from PDF-Extract-Kit and have all been fine-tuned using MinerU. The following table describes all steps and the models used in each step.​
​
Step​
Model​
Layout detection​
  • LayoutLMv3: Developed by Microsoft Research Asia, LayoutLMv3 is a general-purpose document AI pre-trained model capable of efficiently processing text and image multimodal information. This capability is achieved through simplified image representation, unified masked modeling, and token-aligned pre-training.​
  • You Only Look Once (YOLO): An object detection algorithm that leverages convolutional neural networks. YOLO is one of the fast object detection algorithms.​
Formula detection​
You Only Look Once (YOLO): An object detection algorithm that leverages convolutional neural networks. YOLO is one of the fast object detection algorithms.​
Table recognition​
  • TableMaster: This model breaks down a table recognition task into four subtasks: table structure recognition, text line detection, text line recognition, and box assignment.​
  • StructEqTable: This model performs table recognition tasks in an end-to-end manner, demonstrating stronger recognition performance and delivering favorable results even when handling complex tables.​
Formula recognition​
UniMERNet: A deep learning model specializing in mathematical formula recognition.​
OCR​
Paddle-OCR: An open-source OCR toolkit built on the deep learning framework PaddlePaddle, offering end-to-end capabilities such as text detection, recognition, and direction classification.​
​
Embedding & Rerank​
In a RAG system, Embedding and Rerank are two core stages for enhancing retrieval quality. Each serves a distinct function, and together they ensure the model can efficiently and accurately acquire relevant knowledge.​
​
Operation​
Description​
Embedding​
Embedding, which converts text such as questions and document segments into high-dimensional vectors (Embeddings). It measures the semantic relevance of text by calculating the "distance" (such as cosine similarity) between vectors, thereby quickly filtering out candidate content relevant to the question from a large volume of documents.​
Rerank​
Re-ranking, which performs a secondary sorting on the candidate documents (Top N) returned in the Embedding stage to further improve relevance.​
​
Vector database​
In the RAG framework, the vector database is a core component that connects information retrieval and text generation. It handles the efficient storage, management, and retrieval of semantic vector representations for unstructured data, directly influencing the accuracy, response speed, and scalability of the RAG system.​
OCR​
Install the optimized OCR​
  1. Purchase an ecs.g4i instance. In the example provided in this topic, the following instance configurations are used.​
  • Instance type: ecs.g4i.8xlarge​
  • Image: Ubuntu 24.04 64 bit​
  • Network: an assigned EIP​
  1. Execute the following command to install dependencies.​
  • ​
    apt update​
    apt install docker.io​
    ​
  1. Execute the following command to pull the OCR image optimized for the ecs.g4i instance type.​
  • ​
    docker pull cr-for-diting-nodelete-cn-beijing.cr.volces.com/practice-images/ai:ocr​
    ​
  1. Execute the following command to start the Docker image.​
  • ​
    docker run -it cr-for-diting-nodelete-cn-beijing.cr.volces.com/practice-images/ai:ocr bash​
    ​
  1. Execute the following command to run the demo pre-installed in the image.​
  • ​
    cd MinerU/demo/ && python3 demo_new.py​
    ​
  1. Perform related operations.​
  • View OCR results:​
  • The results of OCR operations performed on PDF files using the MinerU tool are stored in the /MinerU/demo/pdfs directory. You can check the corresponding results in this directory.​
  • Replace the OCR target:​
  1. Execute the following command to enter the directory containing the target PDF file for OCR processing.​
  • ​
    cd /MinerU/demo/pdfs​
    ​
tip​
Replace /MinerU/demo/pdfs with the actual directory where the PDF file is located.​
  1. Execute the following command to run the OCR demo.​
  • ​
    python3 demo_new.py​
    ​
Performance data​
This section presents the duration data for OCR operations before and after enabling AMX acceleration, using an optimized OCR model deployed on an ECS instance of the ecs.g4i.8xlarge type.​
​
Instance type​
Not accelerated​
AMX acceleration​
ecs.g4i.8xlarge​
49.42 s​
23.73s​
​
Embedding & Rerank​
Install the optimized Embedding and Rerank​
  1. Deploy Embedding & Rerank and start a Docker image.​
  • ​
    Use an image of a preset model for deployment
    Use a standard image for deployment
    ​
    1. Purchase an ecs.g4il instance. In the example provided in this topic, the following instance configurations are used.​
    • Instance type: ecs.g4i.16xlarge​
    • Image: Ubuntu 24.04 with LLM Knowledge Base 64 bit​
    • Network: an assigned EIP​
    1. Execute the following command to enable AMX-accelerated Embedding & Rerank operations.​
    • ​
      sed -i 's|ghcr.io/huggingface/text-embeddings-inference:cpu-1.6|iaas-cpu-inference-benchmark-cn-beijing.cr.volces.com/rag/tei-cpu:bytedance_fix|g' /root/opea_chatqna/compose.yaml​
      ​
    1. Execute the following command to start the knowledge base Docker image.​
    • ​
      cd opea_chatqna​
      docker compose up -d​
      ​
    1. Once all services show an available status (marked in green), your AI knowledge base is started successfully.​
    ​
  1. Start and run the demo that is pre-installed in the Docker container and used to demonstrate the two core operations of Embedding and Rerank.​
  1. In the directory where the nke-10k-2023.pdf file is located, execute the following command to upload the nke-10k-2023.pdf file to the dataprep service.​
  • ​
    curl -X POST -H "Content-Type: multipart/form-data" -F "files=@./nke-10k-2023.pdf" http://localhost:6007/v1/dataprep/ingest​
    ​
  • If the following output is displayed, the operation is successful.​
  • ​
    {"status":200,"message":"Data preparation succeeded"}​
    ​
  1. Create a benchmark test file.​
  1. Execute the following command to create the benchmark.yaml file.​
  • ​
    vim benchmark.yaml​
    ​
  1. Press the i key to enter edit mode, and then copy the following content into the file.​
  • Script content​
    ​
  1. Press the Esc key to exit the edit mode, enter :wq, and then press Enter to save and exit the file.​
  1. Execute the following command to start the performance testing demo.​
  • ​
    China (Beijing)
    China (Shanghai)
    China (Guangzhou)
    Asia Pacific (Johor)
    ​
    ​
    TOS_BUCKET="https://iaas-debug-beijing.tos-cn-beijing.ivolces.com"​
    if [ ! -d 'GenAIEval' ]; then​
    wget $TOS_BUCKET/tool/cpu-serving/GenAIEval.tar​
    tar -xf GenAIEval.tar​
    rm -f GenAIEval.tar​
    fi​
    cp benchmark.yaml GenAIEval/evals/benchmark​
    cd GenAIEval/evals/benchmark​
    python3 benchmark.py​
    ​
    ​
    ​
  1. Execute the following command to obtain performance data.​
  • ​
    cat /root/virt-benchmark-dev/ubuntu24.04/bin/rag/ragbench_out/chatqnafixed_20250730_173320/1_metrics.json ​
    ​
tip​
Replace /root/virt-benchmark-dev/ubuntu24.04/bin/rag/ragbench_out/chatqnafixed_20250730_173320/1_metrics.json with the file containing the actual test data.​
  • Sample output:​
  • ​
    {​
    "chatqna-xeon-backend-server_average_latency_per_request": 13.670678080748985,​
    "tei-embedding-server_average_latency_per_request": 0.029958314499999972,​
    "vllm-service_average_latency_per_request": 13.525004148483276,​
    "tei-reranking-server_average_latency_per_request": 0.10077269599999998,​
    "retriever-redis-server_average_latency_per_request": 0.002257339499919908​
    }​
    ​
Performance data​
This section presents the duration data for Embedding and Rerank operations before and after enabling AMX acceleration, by using an ECS instance of the ecs.g4i.16xlarge type.​
​
Request count​
Embedding duration (ms)​
​
Rerank duration (ms)​
​
​
Not accelerated​
AMX acceleration​
Not accelerated​
AMX acceleration​
1​
314.25​
41.19​
345.42​
106.23​
2​
312.39​
31.87​
335.5​
111.36​
4​
305.6​
32.94​
366.95​
108.77​
8​
377.13​
52.33​
383.89​
159.54​
16​
721.81​
65.13​
586.86​
233.23​
32​
1909.94​
104.76​
882.99​
431.02​
64​
4600.33​
169.6​
915.75​
884.31​
128​
9475.15​
228.16​
912.41​
1913.32​
​
Vector database​
Install an optimized vector database​
tip​
This section provides a Milvus vector database with operator-level acceleration. Database-level acceleration is not currently supported.​
  1. Purchase an ecs.g4i instance. In the example provided in this topic, the following instance configurations are used.​
  • Instance type: ecs.g4i.4xlarge​
  • Image: Ubuntu 24.04 64 bit​
  • Network: an assigned EIP​
  1. Execute the following command to install dependencies.​
  • ​
    apt update​
    apt install docker.io​
    ​
  1. Execute the following command to pull the vector database image optimized for the ecs.g4i instance type.​
  • ​
    docker pull cr-for-diting-nodelete-cn-beijing.cr.volces.com/practice-images/vectordb:amx​
    ​
  1. Execute the following command to start the Docker image.​
  • ​
    docker run -itd --name vectordb --privileged --network host cr-for-diting-nodelete-cn-beijing.cr.volces.com/practice-images/vectordb:amx bash​
    ​
  1. Execute the following commands to enter the container.​
  • ​
    docker exec -it vectordb bash​
    ​
  1. Test operator performance using ann-benchmark.​
  1. Execute the following command to download test resources.​
  • ​
    cd ~/ann-benchmarks/data​
    wget http://ann-benchmarks.com/nytimes-256-angular.hdf5​
    ​
  1. Execute the following command to run the test.​
  • ​
    conda activate hnswlib && cd /root && bash bench-hnswlib.sh​
    conda activate faiss && cd /root && bash bench-faiss.sh​
    ​
Performance data​
This section presents data on the number of query requests a vector database can process per second before and after enabling AMX acceleration, by using an ECS instance of the ecs.g4i.4xlarge type.​
​
Metric​
Not accelerated​
AMX acceleration​
hnswlib​
Build an index using the Hierarchical Navigable Small World (HNSW) algorithm.​
​
​
qps-recall-95​
The number of query requests that can be processed per second at a 95% recall rate.​
12921.64​
18725.88​
qps-recall-99​
The number of query requests that can be processed per second at a 99% recall rate.​
3177.78​
4974.79​
faiss-indexflatip​
Build an index using the Facebook AI Similarity Search (FAISS) algorithm.​
​
​
qps​
The number of query requests that can be processed per second at a 100% recall rate.​
6296.99​
12285.91​
​
Test conclusion​
When you deploy the RAG architecture on General-purpose g4i instances equipped with the 6th-generation Intel® Xeon® Scalable processor (Granite Rapids) and enable the Advanced Matrix Extensions (AMX) instruction set, all core components of the RAG architecture achieve significant performance improvements. In scenarios where cost-effectiveness and abundant instance resources are prioritized, you can use instance types equipped with the 6th-generation Intel® Xeon® Scalable processor (Granite Rapids), such as the General-purpose g4i instances, as an alternative to GPU instances. This way, you can obtain the most cost-effective RAG inference solution.​
Last updated: 2026.06.18 17:48:27