Hugging Face 上的 BGE
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
)
API 參考:HuggingFaceBgeEmbeddings
請注意,對於 model_name="BAAI/bge-m3"
,您需要傳遞 query_instruction=""
,請參閱 FAQ BGE M3。
embedding = hf.embed_query("hi this is harrison")
len(embedding)
384