Skip to content

Commit a719b61

Browse files
hteeyeohpre-commit-ci[bot]chensuyue
authored
[rerank]: Refine documentation for rerank comps (opea-project#758)
* [rerank]: Refine documentation for rerank comps Restructure and refine README documentation for rerank components. Signed-off-by: Yeoh, Hoong Tee <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * rerank-doc: Break up README lines for viewing experience Signed-off-by: Yeoh, Hoong Tee <[email protected]> --------- Signed-off-by: Yeoh, Hoong Tee <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: chen, suyue <[email protected]>
1 parent 0f1c323 commit a719b61

File tree

6 files changed

+180
-75
lines changed

6 files changed

+180
-75
lines changed

comps/reranks/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Reranking Microservice
2+
3+
The Reranking Microservice, fueled by reranking models, stands as a straightforward yet immensely potent tool for semantic search.
4+
When provided with a query and a collection of documents, reranking swiftly indexes the documents based on their semantic relevance to the query,
5+
arranging them from most to least pertinent. This microservice significantly enhances overall accuracy. In a text retrieval system,
6+
either a dense embedding model or a sparse lexical search index is often employed to retrieve relevant text documents based on the input.
7+
However, a reranking model can further refine this process by rearranging potential candidates into a final, optimized order.
8+
9+
![Flow Chart](./assets/img/reranking_flow.png)
10+
11+
---
12+
13+
## 🛠️ Features
14+
15+
- **rerank on retrieved documents**: Perform reranking on the given documents using reranking models together with query.
16+
17+
---
18+
19+
## ⚙️ Implementation
20+
21+
### Utilizing Reranking with fastRAG
22+
23+
For additional information, please refer to this [README](./fastrag/README.md)
24+
25+
### Utilizing Reranking with Mosec
26+
27+
For additional information, please refer to this [README](./mosec/langchain/README.md)
28+
29+
### Utilizing Reranking with TEI
30+
31+
For additional information, please refer to this [README](./tei/README.md)
32+
33+
### Utilizing Reranking with VideoQnA
34+
35+
For additional information, please refer to this [README](./videoqna/README.md)
106 KB
Loading

comps/reranks/fastrag/README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# Reranking Microservice
1+
# Reranking Microservice with fastRAG
22

3-
The Reranking Microservice, fueled by reranking models, stands as a straightforward yet immensely potent tool for semantic search. When provided with a query and a collection of documents, reranking swiftly indexes the documents based on their semantic relevance to the query, arranging them from most to least pertinent. This microservice significantly enhances overall accuracy. In a text retrieval system, either a dense embedding model or a sparse lexical search index is often employed to retrieve relevant text documents based on the input. However, a reranking model can further refine this process by rearranging potential candidates into a final, optimized order.
3+
`fastRAG` is a research framework for efficient and optimized retrieval augmented generative pipelines, incorporating state-of-the-art LLMs and Information Retrieval.
4+
5+
Please refer to [Official fastRAG repo](https://github.com/IntelLabs/fastRAG/tree/main)
6+
for more information.
7+
8+
This README provides set-up instructions and comprehensive details regarding the reranking microservice via fastRAG.
9+
10+
---
411

512
## 🚀1. Start Microservice with Python (Option 1)
613

@@ -28,6 +35,8 @@ export EMBED_MODEL="Intel/bge-small-en-v1.5-rag-int8-static"
2835
python local_reranking.py
2936
```
3037

38+
---
39+
3140
## 🚀2. Start Microservice with Docker (Option 2)
3241

3342
### 2.1 Setup Environment Variables
@@ -49,21 +58,25 @@ docker build -t opea/reranking-fastrag:latest --build-arg https_proxy=$https_pro
4958
docker run -d --name="reranking-fastrag-server" -p 8000:8000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e EMBED_MODEL=$EMBED_MODEL opea/reranking-fastrag:latest
5059
```
5160

52-
## 🚀3. Consume Reranking Service
61+
---
5362

54-
### 3.1 Check Service Status
63+
## ✅ 3. Invoke Reranking Microservice
5564

56-
```bash
57-
curl http://localhost:8000/v1/health_check \
58-
-X GET \
59-
-H 'Content-Type: application/json'
60-
```
65+
The Reranking microservice exposes following API endpoints:
6166

62-
### 3.2 Consume Reranking Service
67+
- Check Service Status
6368

64-
```bash
65-
curl http://localhost:8000/v1/reranking \
66-
-X POST \
67-
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
68-
-H 'Content-Type: application/json'
69-
```
69+
```bash
70+
curl http://localhost:8000/v1/health_check \
71+
-X GET \
72+
-H 'Content-Type: application/json'
73+
```
74+
75+
- Execute reranking process by providing query and documents
76+
77+
```bash
78+
curl http://localhost:8000/v1/reranking \
79+
-X POST \
80+
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
81+
-H 'Content-Type: application/json'
82+
```
Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,65 @@
1-
# build reranking Mosec endpoint docker image
1+
# Reranking Microservice with Mosec
22

3-
```
4-
docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t opea/reranking-langchain-mosec-endpoint:latest -f comps/reranks/mosec/langchain/dependency/Dockerfile .
5-
```
3+
`Mosec` is a high-performance and flexible model serving framework for building ML model-enabled backend and microservices.
64

7-
## build reranking microservice docker image
5+
Please refer to [Official mosec repo](https://github.com/mosecorg/mosec)
6+
for more information.
87

9-
```
10-
docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t opea/reranking-langchain-mosec:latest -f comps/reranks/mosec/langchain/Dockerfile .
11-
```
8+
This README provides set-up instructions and comprehensive details regarding the reranking microservice via mosec.
129

13-
## launch Mosec endpoint docker container
10+
---
1411

15-
```
16-
docker run -d --name="reranking-langchain-mosec-endpoint" -p 6001:8000 opea/reranking-langchain-mosec-endpoint:latest
17-
```
12+
## Build Reranking Mosec Image
1813

19-
## launch embedding microservice docker container
14+
- Build reranking mosec endpoint docker image.
2015

21-
```
22-
export MOSEC_RERANKING_ENDPOINT=http://127.0.0.1:6001
23-
docker run -d --name="reranking-langchain-mosec-server" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p 6000:8000 --ipc=host -e MOSEC_RERANKING_ENDPOINT=$MOSEC_RERANKING_ENDPOINT opea/reranking-langchain-mosec:latest
24-
```
16+
```
17+
docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t opea/reranking-langchain-mosec-endpoint:latest -f comps/reranks/mosec/langchain/dependency/Dockerfile .
18+
```
2519

26-
## run client test
20+
---
2721

28-
```
29-
curl http://localhost:6000/v1/reranking \
30-
-X POST \
31-
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
32-
-H 'Content-Type: application/json'
33-
```
22+
## Build Reranking Microservice Image
23+
24+
- Build reranking microservice docker image.
25+
26+
```
27+
docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t opea/reranking-langchain-mosec:latest -f comps/reranks/mosec/langchain/Dockerfile .
28+
```
29+
30+
---
31+
32+
## Launch Mosec Endpoint Image Container
33+
34+
- Start the mosec endpoint image docker container.
35+
36+
```
37+
docker run -d --name="reranking-langchain-mosec-endpoint" -p 6001:8000 opea/reranking-langchain-mosec-endpoint:latest
38+
```
39+
40+
---
41+
42+
## Launch Embedding Microservice Image Container
43+
44+
- Start the embedding microservice image docker container.
45+
46+
```
47+
export MOSEC_RERANKING_ENDPOINT=http://127.0.0.1:6001
48+
49+
docker run -d --name="reranking-langchain-mosec-server" -e http_proxy=$http_proxy -e https_proxy=$https_proxy -p 6000:8000 --ipc=host -e MOSEC_RERANKING_ENDPOINT=$MOSEC_RERANKING_ENDPOINT opea/reranking-langchain-mosec:latest
50+
```
51+
52+
---
53+
54+
## ✅ Invoke Reranking Microservice
55+
56+
The Reranking microservice exposes following API endpoints:
57+
58+
- Execute reranking process by providing query and documents
59+
60+
```
61+
curl http://localhost:6000/v1/reranking \
62+
-X POST \
63+
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
64+
-H 'Content-Type: application/json'
65+
```

comps/reranks/tei/README.md

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# Reranking Microservice
1+
# Reranking Microservice via TEI
22

3-
The Reranking Microservice, fueled by reranking models, stands as a straightforward yet immensely potent tool for semantic search. When provided with a query and a collection of documents, reranking swiftly indexes the documents based on their semantic relevance to the query, arranging them from most to least pertinent. This microservice significantly enhances overall accuracy. In a text retrieval system, either a dense embedding model or a sparse lexical search index is often employed to retrieve relevant text documents based on the input. However, a reranking model can further refine this process by rearranging potential candidates into a final, optimized order.
3+
`Text Embeddings Inference (TEI)` is a comprehensive toolkit designed for efficient deployment and serving of open source text embeddings models.
4+
It enable us to host our own reranker endpoint seamlessly.
5+
6+
This README provides set-up instructions and comprehensive details regarding the reranking microservice via TEI.
7+
8+
---
49

510
## 🚀1. Start Microservice with Python (Option 1)
611

@@ -17,7 +22,8 @@ pip install -r requirements.txt
1722
```bash
1823
export HF_TOKEN=${your_hf_api_token}
1924
export RERANK_MODEL_ID="BAAI/bge-reranker-base"
20-
volume=$PWD/data
25+
export volume=$PWD/data
26+
2127
docker run -d -p 6060:80 -v $volume:/data -e http_proxy=$http_proxy -e https_proxy=$https_proxy --pull always ghcr.io/huggingface/text-embeddings-inference:cpu-1.5 --model-id $RERANK_MODEL_ID --hf-api-token $HF_TOKEN
2228
```
2329

@@ -34,9 +40,12 @@ curl 127.0.0.1:6060/rerank \
3440

3541
```bash
3642
export TEI_RERANKING_ENDPOINT="http://${your_ip}:6060"
43+
3744
python reranking_tei_xeon.py
3845
```
3946

47+
---
48+
4049
## 🚀2. Start Microservice with Docker (Option 2)
4150

4251
If you start an Reranking microservice with docker, the `docker_compose_reranking.yaml` file will automatically start a TEI service with docker.
@@ -74,30 +83,34 @@ docker run -d --name="reranking-tei-server" -p 8000:8000 --ipc=host -e http_prox
7483
docker compose -f docker_compose_reranking.yaml up -d
7584
```
7685

77-
## 🚀3. Consume Reranking Service
86+
---
7887

79-
### 3.1 Check Service Status
88+
## ✅3. Invoke Reranking Microservice
8089

81-
```bash
82-
curl http://localhost:8000/v1/health_check \
83-
-X GET \
84-
-H 'Content-Type: application/json'
85-
```
90+
The Reranking microservice exposes following API endpoints:
8691

87-
### 3.2 Consume Reranking Service
92+
- Check Service Status
8893

89-
```bash
90-
curl http://localhost:8000/v1/reranking \
91-
-X POST \
92-
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
93-
-H 'Content-Type: application/json'
94-
```
94+
```bash
95+
curl http://localhost:8000/v1/health_check \
96+
-X GET \
97+
-H 'Content-Type: application/json'
98+
```
9599

96-
You can add the parameter `top_n` to specify the return number of the reranker model, default value is 1.
100+
- Execute reranking process by providing query and documents
97101

98-
```bash
99-
curl http://localhost:8000/v1/reranking \
100-
-X POST \
101-
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}], "top_n":2}' \
102-
-H 'Content-Type: application/json'
103-
```
102+
```bash
103+
curl http://localhost:8000/v1/reranking \
104+
-X POST \
105+
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
106+
-H 'Content-Type: application/json'
107+
```
108+
109+
- You can add the parameter `top_n` to specify the return number of the reranker model, default value is 1.
110+
111+
```bash
112+
curl http://localhost:8000/v1/reranking \
113+
-X POST \
114+
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}], "top_n":2}' \
115+
-H 'Content-Type: application/json'
116+
```

comps/reranks/videoqna/README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
# Rerank Microservice
1+
# Rerank Microservice with VideoQnA
22

3-
This is a Docker-based microservice that do result rerank for VideoQnA use case. Local rerank is used rather than rerank model.
3+
This README provides set-up instructions and comprehensive details regarding the reranking microservice with VideoQnA.
4+
This microservice is designed that do result rerank for VideoQnA use case. Local rerank is used rather than rerank model.
45

5-
For the `VideoQnA` usecase, during the data preparation phase, frames are extracted from videos and stored in a vector database. To identify the most relevant video, we count the occurrences of each video source among the retrieved data with rerank function `get_top_doc`. This sorts the video as a descending list of names, ranked by their degree of match with the query. Then we could send the `top_n` videos to the downstream LVM.
6+
For the `VideoQnA` usecase, during the data preparation phase, frames are extracted from videos and stored in a vector database.
7+
To identify the most relevant video, we count the occurrences of each video source among the retrieved data with rerank function `get_top_doc`.
8+
This sorts the video as a descending list of names, ranked by their degree of match with the query.
9+
Then we could send the `top_n` videos to the downstream LVM.
10+
11+
---
612

713
## 🚀1. Start Microservice with Docker
814

@@ -23,14 +29,21 @@ until docker logs reranking-videoqna-server 2>&1 | grep -q "Uvicorn running on";
2329
done
2430
```
2531

26-
Available configuration by environment variable:
32+
### 1.3 Configuration available by setting environment variable
33+
34+
Configuration that available by setting environment variable:
2735

2836
- CHUNK_DURATION: target chunk duration, should be aligned with VideoQnA dataprep. Default 10s.
2937

30-
## ✅ 2. Test
38+
---
39+
40+
## ✅ 2. Invoke Reranking Microservice
41+
42+
The Reranking microservice exposes following API endpoints:
3143

3244
```bash
3345
export ip_address=$(hostname -I | awk '{print $1}')
46+
3447
curl -X 'POST' \
3548
"http://${ip_address}:8000/v1/reranking" \
3649
-H 'accept: application/json' \
@@ -45,15 +58,14 @@ curl -X 'POST' \
4558
{"other_key": "value", "video":"top_video_name", "timestamp":"20"}
4659
]
4760
}'
48-
```
49-
50-
The result should be:
5161

52-
```bash
53-
{"id":"random number","video_url":"http://0.0.0.0:6005/top_video_name","chunk_start":20.0,"chunk_duration":10.0,"prompt":"this is the query","max_new_tokens":512}
62+
# Expected output result:
63+
# {"id":"random number","video_url":"http://0.0.0.0:6005/top_video_name","chunk_start":20.0,"chunk_duration":10.0,"prompt":"this is the query","max_new_tokens":512}
5464
```
5565

56-
## ♻️ 3. Clean
66+
---
67+
68+
## ♻️ 3. Cleaning the Container
5769

5870
```bash
5971
# remove the container

0 commit comments

Comments
 (0)