Class Introduction
Function
Uses Transformers to start a model locally and provides the text-to-vector sparse embedding function. Weights of models in the BertModel class supported by Transformers are required. The class inherits the langchain_core.embeddings.Embeddings API. Currently, only the BAAI/bge-m3 model is supported.
If the configured model weight is not in the safetensors format, convert the model weight to the safetensors format before using it. This prevents security problems caused by insecure model weight formats such as CKPT and BIN.
Prototype
from mx_rag.embedding.local import SparseEmbedding SparseEmbedding(model_path, dev_id, use_fp16)
Parameters
Example
from paddle.base import libpaddle
from mx_rag.embedding.local import SparseEmbedding
# Same as embed = SparseEmbedding("/path/to/model", 1).
embed = SparseEmbedding.create(model_path="/path/to/model", dev_id=1)
print(embed.embed_documents(['abc', 'bcd']))
print(embed.embed_query('abc'))
Parent topic: SparseEmbedding