Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.langchain.com/llms.txt

Use this file to discover all available pages before exploring further.

BGE models on Hugging Face are a family of open-source embedding and reranking models published by the Beijing Academy of Artificial Intelligence (BAAI). BGE was one of the leading open-source embedding families in 2023 and 2024, and while newer models on the MTEB leaderboard have since surpassed them on raw retrieval scores, BGE (and BAAI/bge-m3 in particular) remains a widely used, well-balanced default for multilingual retrieval.
LangChain provides two ways to use BGE models:
  • HuggingFaceEmbeddings from langchain-huggingface: the generic Sentence Transformers class. Covers every BGE variant and is the recommended choice for new projects.
  • HuggingFaceBgeEmbeddings from langchain-community: a BGE-specific wrapper that automatically prepends the query instruction used by the older English v1.5 models. Convenient when you specifically want a v1.5 model and don’t want to manage the prompt yourself.

BAAI/bge-m3 and newer

pip install -qU langchain-huggingface
from langchain_huggingface import HuggingFaceEmbeddings

embeddings = HuggingFaceEmbeddings(
    model_name="BAAI/bge-m3",
    encode_kwargs={"normalize_embeddings": True},
)
BAAI/bge-m3 is trained without a query prompt, so no extra configuration is needed. normalize_embeddings=True is recommended for cosine similarity, per the model authors.

BAAI/bge-*-en-v1.5 (quick path)

The older English v1.5 models expect the query to be prefixed with an instruction. The dedicated HuggingFaceBgeEmbeddings class handles that automatically:
pip install -qU langchain-community sentence-transformers
from langchain_community.embeddings import HuggingFaceBgeEmbeddings

embeddings = HuggingFaceBgeEmbeddings(
    model_name="BAAI/bge-large-en-v1.5",
    encode_kwargs={"normalize_embeddings": True},
)
For parity with the generic class (or to use the model-card-accurate prompt instead of the library default), the same thing via HuggingFaceEmbeddings:
from langchain_huggingface import HuggingFaceEmbeddings

embeddings = HuggingFaceEmbeddings(
    model_name="BAAI/bge-large-en-v1.5",
    encode_kwargs={"normalize_embeddings": True},
    query_encode_kwargs={
        "prompt": "Represent this sentence for searching relevant passages: ",
        "normalize_embeddings": True,
    },
)
Different BGE variants use different prompts; check each model card on Hugging Face for the exact string.

Picking a BGE model

ModelSizeNotes
BAAI/bge-small-en-v1.533MSmallest English model, CPU-friendly
BAAI/bge-large-en-v1.5335MStronger English, widely used baseline
BAAI/bge-m3570MMultilingual; dense, sparse, and multi-vector in one model
For reranking (not embedding), see BAAI/bge-reranker-v2-m3 via the Cross Encoder Reranker guide.

More

See the Sentence Transformers integration page for GPU configuration, batch sizes, query/document prompts, and deployment options.