> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Hugging Face 上的指令嵌入集成

> 使用 LangChain Python 集成 Hugging Face 上的指令嵌入模型。

> [Hugging Face sentence-transformers](https://huggingface.co/sentence-transformers) 是一个用于最先进句子、文本和图像嵌入的 Python 框架。
> `HuggingFaceInstructEmbeddings` 类中使用了其中一种指令嵌入模型。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.embeddings import HuggingFaceInstructEmbeddings
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
embeddings = HuggingFaceInstructEmbeddings(
    query_instruction="Represent the query for retrieval: "
)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
load INSTRUCTOR_Transformer
max_seq_length  512
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
text = "This is a test document."
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
query_result = embeddings.embed_query(text)
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
```

***

<div className="source-links">
  <Callout icon="terminal-2">
    [连接这些文档](/use-these-docs) 到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/embeddings/instruct_embeddings.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
