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

# Hugging Face 集成中的 Instructor embeddings

> 集成 Hugging Face 上的 Instructor-style 嵌入模型，使用 LangChain Python。

> The `hkunlp/instructor-*` 家族引入了指令调优的句子嵌入。它们已被现代指令感知模型广泛取代，但原始模型仍在Hugging Face上提供，可通过 `HuggingFaceInstructEmbeddings` 类别使用。

对于新项目，建议使用 `HuggingFaceEmbeddings`（参考[`langchain-huggingface`](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/embeddings/sentence_transformers)）配合当前指令感知模型 `intfloat/e5-large-v2`、`Qwen/Qwen3-Embedding-0.6B` 或 `BAAI/bge-m3`。通过 `encode_kwargs` 和 `query_encode_kwargs` 传递查询和文档提示：

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

embeddings = HuggingFaceEmbeddings(
    model_name="intfloat/e5-large-v2",
    encode_kwargs={"prompt": "passage: "},
    query_encode_kwargs={"prompt": "query: "},
)
```

## 遗留指令师用法

```shell theme={null}
pip install -qU langchain-community InstructorEmbedding sentence-transformers
```

> [!WARNING]
>
> `langchain-community`包已不再维护。从`langchain_community`导入的示例可能过时或无法使用。请谨慎使用。

```python theme={null}
from langchain_community.embeddings import HuggingFaceInstructEmbeddings

embeddings = HuggingFaceInstructEmbeddings(
    query_instruction="Represent the query for retrieval: "
)

query_result = embeddings.embed_query("This is a test document.")
```

***

> 官方原文：[src/oss/python/integrations/embeddings/instruct\_embeddings.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/embeddings/instruct_embeddings.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.