Hugging Face 上的 BGE
BGE models on the HuggingFace are one of the best open-source embedding models. BGE model is created by the Beijing Academy of Artificial Intelligence (BAAI).
BAAIis a private non-profit organization engaged in AI research and development.
本笔记本展示了如何使用 BGE Embeddings 到 Hugging 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
)
API 参考:HuggingFaceBgeEmbeddings
请注意,您需要为 model_name="BAAI/bge-m3" 传递 query_instruction="",详见 FAQ BGE M3。
embedding = hf.embed_query("hi this is harrison")
len(embedding)
384