|
| 1 | +# Build Mega Service of ChatQnA on Xeon |
| 2 | + |
| 3 | +This document outlines the deployment process for a ChatQnA application utilizing the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline on Intel Xeon server. The steps include Docker image creation, container deployment via Docker Compose, and service execution to integrate microservices such as `embedding`, `retriever`, `rerank`, and `llm`. We will publish the Docker images to Docker Hub soon, it will simplify the deployment process for this service. |
| 4 | + |
| 5 | +## 🚀 Apply Xeon Server on AWS |
| 6 | + |
| 7 | +To apply a Xeon server on AWS, start by creating an AWS account if you don't have one already. Then, head to the [EC2 Console](https://console.aws.amazon.com/ec2/v2/home) to begin the process. Within the EC2 service, select the Amazon EC2 M7i or M7i-flex instance type to leverage the power of 4th Generation Intel Xeon Scalable processors. These instances are optimized for high-performance computing and demanding workloads. |
| 8 | + |
| 9 | +For detailed information about these instance types, you can refer to this [link](https://aws.amazon.com/ec2/instance-types/m7i/). Once you've chosen the appropriate instance type, proceed with configuring your instance settings, including network configurations, security groups, and storage options. |
| 10 | + |
| 11 | +After launching your instance, you can connect to it using SSH (for Linux instances) or Remote Desktop Protocol (RDP) (for Windows instances). From there, you'll have full access to your Xeon server, allowing you to install, configure, and manage your applications as needed. |
| 12 | + |
| 13 | +## 🚀 Build Docker Images |
| 14 | + |
| 15 | +First of all, you need to build Docker Images locally and install the python package of it. |
| 16 | + |
| 17 | +```bash |
| 18 | +git clone https://github.com/opea-project/GenAIComps.git |
| 19 | +cd GenAIComps |
| 20 | +pip install -r requirements.txt |
| 21 | +pip install . |
| 22 | +``` |
| 23 | + |
| 24 | +### 1. Build Embedding Image |
| 25 | + |
| 26 | +```bash |
| 27 | +docker build -t opea/gen-ai-comps:embedding-tei-server --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/docker/Dockerfile . |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Build Retriever Image |
| 31 | + |
| 32 | +```bash |
| 33 | +docker build -t opea/gen-ai-comps:retriever-redis-server --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/docker/Dockerfile . |
| 34 | +``` |
| 35 | + |
| 36 | +### 3. Build Rerank Image |
| 37 | + |
| 38 | +```bash |
| 39 | +docker build -t opea/gen-ai-comps:reranking-tei-xeon-server --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/docker/Dockerfile . |
| 40 | +``` |
| 41 | + |
| 42 | +### 4. Build LLM Image |
| 43 | + |
| 44 | +```bash |
| 45 | +docker build -t opea/gen-ai-comps:llm-tgi-server --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/llm/langchain/docker/Dockerfile . |
| 46 | +``` |
| 47 | + |
| 48 | +### 5. Pull qna-rag-redis-server Image |
| 49 | + |
| 50 | +```bash |
| 51 | +docker pull intel/gen-ai-examples:qna-rag-redis-server |
| 52 | +``` |
| 53 | + |
| 54 | +Then run the command `docker images`, you will have the following four Docker Images: |
| 55 | + |
| 56 | +1. `opea/gen-ai-comps:embedding-tei-server` |
| 57 | +2. `opea/gen-ai-comps:retriever-redis-server` |
| 58 | +3. `opea/gen-ai-comps:reranking-tei-xeon-server` |
| 59 | +4. `opea/gen-ai-comps:llm-tgi-server` |
| 60 | +5. `intel/gen-ai-examples:qna-rag-redis-server` |
| 61 | + |
| 62 | +## 🚀 Start Microservices |
| 63 | + |
| 64 | +### Setup Environment Variables |
| 65 | + |
| 66 | +Since the `docker_compose_xeon.yaml` will consume some environment variables, you need to setup them in advance as below. |
| 67 | + |
| 68 | +```bash |
| 69 | +export http_proxy=${your_http_proxy} |
| 70 | +export https_proxy=${your_http_proxy} |
| 71 | +export EMBEDDING_MODEL_ID="BAAI/bge-large-en-v1.5" |
| 72 | +export RERANK_MODEL_ID="BAAI/bge-reranker-large" |
| 73 | +export LLM_MODEL_ID="m-a-p/OpenCodeInterpreter-DS-6.7B" |
| 74 | +export TEI_EMBEDDING_ENDPOINT="http://${your_ip}:8090" |
| 75 | +export TEI_RERANKING_ENDPOINT="http://${your_ip}:6060" |
| 76 | +export TGI_LLM_ENDPOINT="http://${your_ip}:8008" |
| 77 | +export REDIS_URL="redis://${your_ip}:6379" |
| 78 | +export INDEX_NAME=${your_index_name} |
| 79 | +export HUGGINGFACEHUB_API_TOKEN=${your_hf_api_token} |
| 80 | +``` |
| 81 | + |
| 82 | +### Start Microservice Docker Containers |
| 83 | + |
| 84 | +```bash |
| 85 | +docker compose -f docker_compose_xeon.yaml up -d |
| 86 | +``` |
| 87 | + |
| 88 | +### Validate Microservices |
| 89 | + |
| 90 | +1. TEI Embedding Service |
| 91 | + |
| 92 | +```bash |
| 93 | +curl ${your_ip}:8090/embed \ |
| 94 | + -X POST \ |
| 95 | + -d '{"inputs":"What is Deep Learning?"}' \ |
| 96 | + -H 'Content-Type: application/json' |
| 97 | +``` |
| 98 | + |
| 99 | +2. Embedding Microservice |
| 100 | + |
| 101 | +```bash |
| 102 | +curl http://${your_ip}:6000/v1/embeddings\ |
| 103 | + -X POST \ |
| 104 | + -d '{"text":"hello"}' \ |
| 105 | + -H 'Content-Type: application/json' |
| 106 | +``` |
| 107 | + |
| 108 | +3. Retriever Microservice |
| 109 | + |
| 110 | +```bash |
| 111 | +curl http://${your_ip}:7000/v1/retrieval\ |
| 112 | + -X POST \ |
| 113 | + -d '{"text":"test","embedding":[1,1,...1]}' \ |
| 114 | + -H 'Content-Type: application/json' |
| 115 | +``` |
| 116 | + |
| 117 | +4. TEI Reranking Service |
| 118 | + |
| 119 | +```bash |
| 120 | +curl http://${your_ip}:6060/rerank \ |
| 121 | + -X POST \ |
| 122 | + -d '{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."]}' \ |
| 123 | + -H 'Content-Type: application/json' |
| 124 | +``` |
| 125 | + |
| 126 | +5. Reranking Microservice |
| 127 | + |
| 128 | +```bash |
| 129 | +curl http://${your_ip}:8000/v1/reranking\ |
| 130 | + -X POST \ |
| 131 | + -d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \ |
| 132 | + -H 'Content-Type: application/json' |
| 133 | +``` |
| 134 | + |
| 135 | +6. TGI Service |
| 136 | + |
| 137 | +```bash |
| 138 | +curl http://${your_ip}:8008/generate \ |
| 139 | + -X POST \ |
| 140 | + -d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \ |
| 141 | + -H 'Content-Type: application/json' |
| 142 | +``` |
| 143 | + |
| 144 | +7. LLM Microservice |
| 145 | + |
| 146 | +```bash |
| 147 | +curl http://${your_ip}:9000/v1/chat/completions\ |
| 148 | + -X POST \ |
| 149 | + -d '{"text":"What is Deep Learning?"}' \ |
| 150 | + -H 'Content-Type: application/json' |
| 151 | +``` |
| 152 | + |
| 153 | +Following the validation of all aforementioned microservices, we are now prepared to construct a mega-service. However, before launching the mega-service, it's essential to ingest data into the vector store. |
| 154 | + |
| 155 | +## 🚀 Ingest Data Into Vector Database |
| 156 | + |
| 157 | +```bash |
| 158 | +docker exec -it qna-rag-redis-server bash |
| 159 | +cd /ws |
| 160 | +python ingest.py |
| 161 | +``` |
| 162 | + |
| 163 | +## 🚀 Construct Mega Service |
| 164 | + |
| 165 | +Modify the `initial_inputs` of line 34 in `chatqna.py`, then you will get the ChatQnA result of this mega service. |
| 166 | + |
| 167 | +All of the intermediate results will be printed for each microservices. Users can check the accuracy of the results to make targeted modifications. |
| 168 | + |
| 169 | +```bash |
| 170 | +python chatqna.py |
| 171 | +``` |
0 commit comments