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

# Hugging Face 集成中的 Instruct 嵌入

> 使用 LangChain Python 与 Hugging Face 嵌入模型中的 Instruct 嵌入进行集成。

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

```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="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\python\integrations\embeddings\instruct_embeddings.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

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