跳到主要内容
HuggingFace 上的 BGE 模型最好的开源嵌入模型之一。BGE 模型由北京智源人工智能研究院 (BAAI) 创建。BAAI 是一家从事人工智能研发的私人非营利组织。
本笔记展示了如何通过 Hugging Face 使用 BGE 嵌入
pip install -qU  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

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.