forked from opea-project/GenAIComps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_retrievers_qdrant.sh
More file actions
80 lines (64 loc) · 2.2 KB
/
Copy pathtest_retrievers_qdrant.sh
File metadata and controls
80 lines (64 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
set -x
IMAGE_REPO=${IMAGE_REPO:-"opea"}
export REGISTRY=${IMAGE_REPO}
export TAG="comps"
echo "REGISTRY=IMAGE_REPO=${IMAGE_REPO}"
echo "TAG=${TAG}"
WORKPATH=$(dirname "$PWD")
LOG_PATH="$WORKPATH/tests"
export host_ip=$(hostname -I | awk '{print $1}')
service_name="retriever-qdrant"
function build_docker_images() {
cd $WORKPATH
docker build --no-cache -t ${REGISTRY:-opea}/retriever:${TAG:-latest} --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/src/Dockerfile .
if [ $? -ne 0 ]; then
echo "opea/retriever built fail"
exit 1
else
echo "opea/retriever built successful"
fi
}
function start_service() {
export QDRANT_PORT=11622
export RETRIEVER_PORT=11623
export QDRANT_HOST=${host_ip}
export INDEX_NAME="rag-qdrant"
export LOGFLAG=True
cd $WORKPATH/comps/retrievers/deployment/docker_compose
docker compose -f compose.yaml up ${service_name} -d > ${LOG_PATH}/start_services_with_compose.log
sleep 3m
}
function validate_microservice() {
export PATH="${HOME}/miniforge3/bin:$PATH"
source activate
test_embedding=$(python -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)")
result=$(http_proxy='' curl http://${host_ip}:$RETRIEVER_PORT/v1/retrieval \
-X POST \
-d "{\"text\":\"test\",\"embedding\":${test_embedding}}" \
-H 'Content-Type: application/json')
if [[ $result == *"retrieved_docs"* ]]; then
echo "Result correct."
else
echo "Result wrong. Received was $result"
docker logs ${service_name} >> ${LOG_PATH}/retriever.log
exit 1
fi
}
function stop_docker() {
cd $WORKPATH/comps/retrievers/deployment/docker_compose
docker compose -f compose.yaml down ${service_name} --remove-orphans
cid=$(docker ps -aq --filter "name=qdrant-vector-db")
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
}
function main() {
stop_docker
build_docker_images
start_service
validate_microservice
stop_docker
echo y | docker system prune
}
main