Skip to main content

BGE 在 Hugging Face 上

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

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

%pip install --upgrade --quiet  sentence_transformers
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

相关


此页面是否有帮助?


您还可以留下详细的反馈 在 GitHub 上