> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-cta2-1778260809-ad7a43f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Hugging Face integration

> Integrate with the Hugging Face embedding model using LangChain Python.

## Local Embeddings

You can generate embeddings locally using the `HuggingFaceEmbeddings` class. This utilizes the `sentence_transformers` library to download the model weights and run them directly on your machine.

Let's load the Hugging Face Embedding class.

```python theme={null}
pip install -qU  langchain langchain-huggingface sentence_transformers
```

```python theme={null}
from langchain_huggingface.embeddings import HuggingFaceEmbeddings
```

```python theme={null}
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
```

```python theme={null}
text = "This is a test document."
```

```python theme={null}
query_result = embeddings.embed_query(text)
```

```python theme={null}
query_result[:3]
```

```text theme={null}
[-0.04895168915390968, -0.03986193612217903, -0.021562768146395683]
```

```python theme={null}
doc_result = embeddings.embed_documents([text])
```

## Hugging Face Inference Endpoints (Serverless API)

If you prefer not to download models locally, you can access embedding models via the [Inference Endpoints](https://huggingface.co/docs/inference-endpoints/index), which let us use open-source models on Hugging Face's scalable serverless infrastructure.

Ensure you have huggingface\_hub installed, which is usually included with langchain-huggingface

```python theme={null}
!pip install huggingface_hub
```

First, we need to get a read-only API key from [Hugging Face](https://huggingface.co/settings/tokens).

```python theme={null}
import os
from getpass import getpass

os.environ["HUGGINGFACEHUB_API_TOKEN"] = getpass()
```

Now we can use the `HuggingFaceEndpointEmbeddings` class to run open-source embedding models remotely via the API.

```python theme={null}
from langchain_huggingface.embeddings import HuggingFaceEndpointEmbeddings
```

```python theme={null}
embeddings = HuggingFaceEndpointEmbeddings(
    model="sentence-transformers/all-MiniLM-L6-v2"
)
```

```python theme={null}
text = "This is a test document."
```

```python theme={null}
query_result = embeddings.embed_query(text)
```

```python theme={null}
query_result[:3]
```

***

<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/huggingfacehub.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
