跳到主要内容

InstructorEmbeddingFunction

InstructorEmbeddingFunction 是 pymilvus 中的一个类,它使用 Instructor 嵌入模型将文本编码为嵌入,以支持在 Milvus 中进行嵌入检索。

python
pymilvus.model.dense.InstructorEmbeddingFunction

构造函数​

为常见用例构造一个 MistralAIEmbeddingFunction。

python
InstructorEmbeddingFunction(
model_name: str = "hkunlp/instructor-xl",
batch_size: int = 32,
query_instruction: str = "Represent the question for retrieval:",
doc_instruction: str = "Represent the document for retrieval:",
device: str = "cpu",
normalize_embeddings: bool = True,
**kwargs
)

参数:

  • model_name (string)

    用于编码的 Mistral AI 嵌入模型名称。该值默认为 hkunlp/instructor-xl。更多信息,请参见 模型列表。

  • batch_size (int)

    计算时使用的批大小。它决定了每个批次中一起处理的句子数量。

  • query_instruction (string)

    特定于任务的指令,用于指导模型如何为查询或问题生成嵌入。

  • doc_instruction (string)

    特定于任务的指令,用于指导模型为文档生成嵌入。

  • device (string)

    指定计算时使用的 torch.device。如果未指定,函数将使用默认设备。

  • normalize_embeddings (bool)

    如果设置为 True,返回的向量长度将为 1,这表示它们已被归一化。在这种情况下,相似性搜索将使用更快的点积(util.dot_score),而不是余弦相似度。

  • kwargs

    允许将额外的关键字参数传递给模型初始化。更多信息,请参见 instructor-embedding。

示例​

python
from pymilvus.model.dense import InstructorEmbeddingFunction

ef = InstructorEmbeddingFunction(
model_name="hkunlp/instructor-xl", # Defaults to `hkunlp/instructor-xl`
query_instruction="Represent the question for retrieval:",
doc_instruction="Represent the document for retrieval:"
)
最低 SDK 版本v2.4.x