> ## 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 on Hugging Face integration

> Integrate with BGE embedding models on Hugging Face using LangChain Python.

> [BGE models on Hugging Face](https://huggingface.co/BAAI) are a family of open-source embedding and reranking models published by the [Beijing Academy of Artificial Intelligence (BAAI)](https://en.wikipedia.org/wiki/Beijing_Academy_of_Artificial_Intelligence). BGE was one of the leading open-source embedding families in 2023 and 2024, and while newer models on the [MTEB leaderboard](https://huggingface.co/spaces/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.

## `BAAI/bge-m3` and newer

```shell theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langchain-huggingface
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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)

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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

| Model                    | Size | Notes                                                      |
| ------------------------ | ---- | ---------------------------------------------------------- |
| `BAAI/bge-small-en-v1.5` | 33M  | Smallest English model, CPU-friendly                       |
| `BAAI/bge-large-en-v1.5` | 335M | Stronger English, widely used baseline                     |
| `BAAI/bge-m3`            | 570M | Multilingual; dense, sparse, and multi-vector in one model |

For reranking (not embedding), see [`BAAI/bge-reranker-v2-m3`](https://huggingface.co/BAAI/bge-reranker-v2-m3) via the [Cross Encoder Reranker guide](/oss/python/integrations/document_transformers/cross_encoder_reranker).

## More

See the [Sentence Transformers integration page](/oss/python/integrations/embeddings/sentence_transformers) for GPU configuration, batch sizes, query/document prompts, and deployment options.

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/embeddings/bge_huggingface.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
