Skip to main content

BGE 在 Hugging Face 上

HuggingFace 上的 BGE 模型最佳开源嵌入模型之一。 BGE 模型由 北京人工智能研究院 (BAAI) 创建。BAAI 是一个从事人工智能研究和开发的私营非营利组织。

本笔记本展示了如何通过 Hugging Face 使用 BGE 嵌入

%pip install --upgrade --quiet  sentence_transformers
<!--IMPORTS:[{"imported": "HuggingFaceBgeEmbeddings", "source": "langchain_community.embeddings", "docs": "https://python.langchain.com/api_reference/community/embeddings/langchain_community.embeddings.huggingface.HuggingFaceBgeEmbeddings.html", "title": "BGE on Hugging Face"}]-->
from langchain_community.embeddings import HuggingFaceBgeEmbeddings

model_name = "BAAI/bge-small-en"
model_kwargs = {"device": "cpu"}
encode_kwargs = {"normalize_embeddings": True}
hf = HuggingFaceBgeEmbeddings(
model_name=model_name, model_kwargs=model_kwargs, encode_kwargs=encode_kwargs
)

请注意,对于 model_name="BAAI/bge-m3" 需要传递 query_instruction="",请参见 FAQ BGE M3

embedding = hf.embed_query("hi this is harrison")
len(embedding)
384

相关


Was this page helpful?


You can also leave detailed feedback on GitHub.

扫我,入群扫我,找书