Skip to main content
Open In ColabOpen on GitHub

Hugging Face 上的 BGE

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

该笔记本展示了如何使用 BGE EmbeddingsHugging Face

%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="",请参见 常见问题 BGE M3

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