Class Introduction
Function
Connects to the TEI service and provides the text-to-vector embedding function. The class inherits the langchain_core.embeddings.Embeddings API.
Prototype
from mx_rag.embedding.service import TEIEmbedding TEIEmbedding(url, client_param, embed_mode)
Parameters
Parameter |
Data Type |
Required/Optional |
Description |
|---|---|---|---|
url |
String |
Required |
TEI embedding service address. The string contains [1, 128] characters. The /v1/embed, /v1/embeddings, and /embed_sparse APIs are supported. NOTE:
Currently, the embedding 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 embedding service remain within the same trusted network. When the client accesses the Nginx in HTTPS mode, the Nginx forwards a request to the embedding service. |
client_param |
ClientParam |
Optional |
HTTPS client configuration parameter. The default value is ClientParam(). For details, see ClientParam. |
embed_mode |
String |
Optional |
(Deprecated) Corresponds to the vectorization type provided by the TEI service. The value can only be sparse or dense (default). sparse indicates sparse vectorization, and dense indicates dense vectorization. |
Return Value
TEIEmbedding object.
Example
from paddle.base import libpaddle
from mx_rag.embedding.service import TEIEmbedding
from mx_rag.utils import ClientParam
# Same as tei_embed = TEIEmbedding("https://ip:port/embed", client_param = ClientParam(xxx)).
tei_embed = TEIEmbedding.create(url="https://ip:port/embed",
client_param=ClientParam(ca_file="/path/to/ca.crt"))
print(tei_embed.embed_documents(['abc', 'bcd']))
print(tei_embed.embed_query('abc'))