__call__()
SpladeEmbeddingFunction 中的此操作接受一个文本字符串列表,并将其直接编码为向量嵌入。
与 encode_documents() 或 encode_queries() 不同,后两者允许您预先添加 doc_instruction 或 query_instruction,并使用 k_tokens_document 或 k_tokens_query 对结果进行裁剪,而 __call__() 方法会直接返回嵌入,不提供预添加指令或裁剪结果的选项。
请求语法
python
# Instance created
splade_ef = SpladeEmbeddingFunction()
# __call__ method will be called
splade_ef(
texts: List[str]
) -> csr_array
参数:
-
texts (List[str])
字符串值列表,其中每个字符串都表示将传递给嵌入模型进行编码的文本。模型会为列表中的每个字符串生成一个嵌入向量。
返回类型:
csr_array
返回:
表示文档嵌入的压缩稀疏行矩阵。
异常:
-
ImportError
未安装 transformers 库时,将引发此异常。
示例
python
from pymilvus import model
splade_ef = model.sparse.SpladeEmbeddingFunction(
model_name="naver/splade-cocondenser-selfdistil",
device="cpu"
)
docs = [
"Artificial intelligence was founded as an academic discipline in 1956.",
"Alan Turing was the first person to conduct substantial research in AI.",
"Born in Maida Vale, London, Turing was raised in southern England.",
]
splade_ef(docs)
# <3x30522 sparse array of type '<class 'numpy.float32'>'
# with 298 stored elements in Compressed Sparse Row format>