Skip to main content
Open In ColabOpen on GitHub

Hugging Face 上的指令嵌入

Hugging Face sentence-transformers 是一个用于最先进句子、文本和图像嵌入的 Python 框架。 HuggingFaceInstructEmbeddings 类中使用了指令嵌入模型之一。

from langchain_community.embeddings import HuggingFaceInstructEmbeddings
embeddings = HuggingFaceInstructEmbeddings(
query_instruction="Represent the query for retrieval: "
)
load INSTRUCTOR_Transformer
max_seq_length 512
text = "This is a test document."
query_result = embeddings.embed_query(text)