Class Introduction
Function
Connects to the TEI service and calculates relevance scores for documents. It inherits the abstract class Reranker.
Prototype
from mx_rag.reranker.service import TEIReranker TEIReranker(url, k, client_param)
Parameters
Parameter |
Data Type |
Required/Optional |
Description |
|---|---|---|---|
url |
String |
Required |
TEI re-ranking service address. The string contains [1, 128] characters. The /rerank and /v1/rerank APIs are supported. NOTE:
Currently, the re-ranking service created based on the TEI framework does not support the HTTPS protocol. For security purposes, you can set up an Nginx service to ensure that the service and re-ranking service remain within the same trusted network. When the client accesses the Nginx in HTTPS mode, the Nginx forwards a request to the re-ranking service. |
k |
Integer |
Optional |
The most relevant k results after re-ranking. The value range is [1, 10000]. The default value is 1. |
client_param |
ClientParam |
Optional |
HTTPS client configuration parameter. The default value is ClientParam(). For details, see ClientParam. |
Return Value
TEIReranker object.
Example
from paddle.base import libpaddle
from mx_rag.reranker.service import TEIReranker
from mx_rag.utils import ClientParam
# Same as LocalReranker(url="https://ip:port/rerank", client_param=ClientParam(xxx)).
rerank = TEIReranker.create(url="https://ip:port/rerank",
client_param=ClientParam(ca_file="/path/to/ca.crt"))
docs = ['I am Xiao Hong','I am Xiao Ming']
scores = rerank.rerank ('Hello', docs)
res = rerank.rerank_top_k(docs, scores)
print(res)