Skip to content

Commit 6d14382

Browse files
authored
Merge pull request #285 from Hsy-Intel/main
Fix known issues and refine doc in RAG solution
2 parents c9a26af + 3ba78c0 commit 6d14382

File tree

4 files changed

+77
-12
lines changed

4 files changed

+77
-12
lines changed

cczoo/rag/README.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ The steps to download the required model from the Hugging Face mirror website ar
6161
```shell
6262
cd /home/encrypted_storage
6363
pip install -U huggingface_hub
64-
export HF_ENDPOINT=https://hf-mirror.com
65-
huggingface-cli download --resume-download --local-dir-use-symlinks False meta-llama/Llama-2-7b-chat-hf --local-dir Llama-2-7b-chat-hf
64+
# If your server is in China, you can set this environment variable: export HF_ENDPOINT=https://hf-mirror.com
65+
huggingface-cli download --resume-download --local-dir-use-symlinks False meta-llama/Llama-2-7b-chat-hf --local-dir Llama-2-7b-chat-hf --token <your huggingface token>
6666
huggingface-cli download --resume-download --local-dir-use-symlinks False cross-encoder/ms-marco-MiniLM-L-12-v2 --local-dir ms-marco-MiniLM-L-12-v2
6767
huggingface-cli download --resume-download --local-dir-use-symlinks False facebook/dpr-ctx_encoder-single-nq-base --local-dir dpr-ctx_encoder-single-nq-base
6868
huggingface-cli download --resume-download --local-dir-use-symlinks False facebook/dpr-question_encoder-single-nq-base --local-dir dpr-question_encoder-single-nq-base
6969
```
7070

71-
### 4. Start the RAG service
71+
### 4. Run the RAG service
7272

73-
#### start the database service container
73+
#### run the database service container
7474

7575
If you want to use MySQL as the storage:
7676

@@ -86,7 +86,7 @@ cd <workdir>/confidential-computing-zoo/cczoo/rag
8686
./run.sh es
8787
```
8888

89-
#### start the backend service container
89+
#### run the backend service container
9090

9191
If you use MySQL as the storage:
9292

@@ -119,7 +119,7 @@ python3 generate_db.py
119119

120120
If you use MySQL as the storage, you can edit data in `data/data.txt` directly.
121121

122-
#### Start the frontend service container
122+
#### Run the frontend service container
123123
In another new terminal execute the following command:
124124

125125
```bash
@@ -146,3 +146,52 @@ In your local browser, open the Network URL `http://<host_server>:<host_port>` a
146146

147147
For customized modifications and issues with the RAG framework, please refer to [Haystack](https://github.com/deepset-ai/haystack/tree/main).
148148

149+
#### Run RAG service with RA-TLS
150+
151+
If you want to run the RAG service with remote attestation, you need to modify the following steps:
152+
153+
**Get the verification hash value and configure**
154+
155+
We can get the attestation message by running for both backend and frontend containers:
156+
157+
```shell
158+
docker exec -it tdx_rag_backend bash -c "cd /usr/bin && ./tdx_report_parser"
159+
docker exec -it tdx_rag_frontend bash -c "cd /usr/bin && ./tdx_report_parser"
160+
```
161+
162+
In the `frontend/chatbot-rag/dynamic_config.json` and `backend/pipelines/dynamic_config.json` files:
163+
- Fill in the "ON" or "OFF" to config verification strategy.
164+
- Fill in the hash value obtained through the above command into the `dynamic_config.json` file of the corresponding directory. For example, the hash value obtained from the backend should be filled in the frontend configuration file.
165+
166+
**Add RA configuration when running backend service container**
167+
168+
```shell
169+
./run.sh backend ra <ip addr>
170+
```
171+
The "ra" means "remote attestation" and the subsequent IP address is the attestation server address.
172+
173+
Then, enter the following message:
174+
175+
```shell
176+
Enter database ip addr: <database ip addr>
177+
178+
Enter database username: root
179+
180+
Enter database password: 123456
181+
```
182+
183+
It will finally print the attestation message. It means the backend server runs successfully.
184+
185+
**Add RA configuration when running frontend service container**
186+
187+
```shell
188+
./run.sh frontend ra <ip addr>
189+
```
190+
191+
The "ra" means "remote attestation" and the subsequent IP address is the attestation server address.
192+
193+
**Visit the Web UI and ask questions**
194+
195+
You can click the link generated by the frontend service to access the RAG service.
196+
197+
If everything goes well, you should be able to see the green security connection box at the web page, and the detailed information about remote attestation below.

cczoo/rag/backend/pipelines/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from haystack.nodes.prompt import PromptNode
1111

1212

13-
query_pipeline = Pipeline.load_from_yaml(Path("rag.yaml"))
13+
query_pipeline = Pipeline.load_from_yaml(Path("rag_mysql.yaml"))
1414

1515
def _get_grpc_streaming_iterator(pipeline, request=None):
1616
params = request["params"] or {}
@@ -42,6 +42,9 @@ def Status(self, request, context):
4242
API_PROTOCOL = os.getenv("API_PROTOCOL", "grpc")
4343
print("API_PROTOCOL:", API_PROTOCOL, flush=True)
4444

45+
os.unsetenv("http_proxy")
46+
os.unsetenv("https_proxy")
47+
4548
server = grpc.server(ThreadPoolExecutor(max_workers=8))
4649
query_pb2_grpc.add_QueryServicer_to_server(QueryServicer(), server)
4750

cczoo/rag/frontend/chatbot-rag/build-image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dockerfile=frontend.dockerfile
88

99
DOCKER_BUILDKIT=0 docker build \
1010
-f ${dockerfile} . \
11-
-t intelcczoo/rag-llm:ui \
11+
-t intelcczoo/tdx-rag:frontend \
1212
--network=host \
1313
--build-arg http_proxy=${http_proxy} \
1414
--build-arg https_proxy=${https_proxy} \

cczoo/rag/run.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@
1616

1717
SERVICE_NAME="${1:-}"
1818

19-
[ "$2" == "ra" ] && REMOTE_ATTESTATION="grpc-ratls"
19+
pccs_addr=127.0.0.1
20+
21+
if [ "$2" == "ra" ]; then
22+
REMOTE_ATTESTATION="grpc-ratls"
23+
if [ -z "$3" ]; then
24+
echo "Error: No PCCS address provided."
25+
exit 1
26+
else
27+
pccs_addr="$3"
28+
fi
29+
fi
2030

2131
function show_help {
2232
echo "Usage: ./script.sh SERVICE_NAME [ra]"
2333
echo ""
2434
echo "Arguments:"
2535
echo " SERVICE_NAME : Name of the service (db: Mysql, es: ElasticSearch, backend, backend_es, frontend)"
2636
echo " ra : Enable remote attestation (optional)"
37+
echo " <ip addr> : PCCS service address"
2738
exit 1
2839
}
2940

@@ -64,8 +75,9 @@ elif [ "$SERVICE_NAME" == 'backend' ]; then
6475
docker rm tdx_rag_backend
6576
fi
6677
rm -rf backend/pipelines/faiss-index-so.*
78+
rm -rf /home/encrypted_storage/faiss-index-so.*
6779
echo -e "\nstart backend container..."
68-
mv -n data/data.txt /home/encrypted_storage
80+
cp data/data.txt /home/encrypted_storage
6981
docker run -itd --privileged --network host \
7082
-e http_proxy=${http_proxy} \
7183
-e https_proxy=${https_proxy} \
@@ -81,6 +93,7 @@ elif [ "$SERVICE_NAME" == 'backend' ]; then
8193
-v /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket \
8294
-v /home/encrypted_storage:/home/rag_data/ \
8395
-v $(pwd)/backend/pipelines:/home/user/workspace \
96+
--add-host pccs.service.com:${pccs_addr} \
8497
--shm-size=64gb --name tdx_rag_backend intelcczoo/tdx-rag:backend /bin/bash
8598
sleep 5
8699

@@ -116,6 +129,7 @@ elif [ "$SERVICE_NAME" == 'backend_es' ]; then
116129
-v /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket \
117130
-v /home/encrypted_storage:/home/rag_data/ \
118131
-v $(pwd)/backend/pipelines:/home/user/workspace \
132+
--add-host pccs.service.com:${pccs_addr} \
119133
--shm-size=64gb --name tdx_rag_backend intelcczoo/tdx-rag:backend /bin/bash
120134
sleep 5
121135

@@ -135,8 +149,6 @@ elif [ "$SERVICE_NAME" == 'frontend' ]; then
135149
fi
136150
echo -e "\nstart frontend container..."
137151
docker run -itd --privileged --network host \
138-
-e http_proxy=${http_proxy} \
139-
-e https_proxy=${https_proxy} \
140152
-e no_proxy=${no_proxy} \
141153
-e API_PROTOCOL=${REMOTE_ATTESTATION} \
142154
-e STREAMLIT_SERVER_PORT=8502 \
@@ -145,6 +157,7 @@ elif [ "$SERVICE_NAME" == 'frontend' ]; then
145157
-v /dev:/dev \
146158
-v /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket \
147159
-v $(pwd)/frontend/chatbot-rag:/home/user/workspace \
160+
--add-host pccs.service.com:${pccs_addr} \
148161
--shm-size=64gb --name tdx_rag_frontend intelcczoo/tdx-rag:frontend /bin/bash
149162
sleep 5
150163
docker exec -i tdx_rag_frontend /bin/bash -c "streamlit run app.py"

0 commit comments

Comments
 (0)