> ## 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.

# UpstageEmbeddings 集成

> 使用 LangChain 集成 UpstageEmbeddings 嵌入模型。

从 '/snippets/oss/langchain-community-unmaintained.mdx' 导入 LangchainCommunityUnmaintained;

这个笔记本介绍了如何使用 Upstage 嵌入模型入门。

## 安装

安装 `langchain-upstage` 包。

```bash theme={null}
pip install -U langchain-upstage
```

## 环境配置

请确保设置以下环境变量：

* `UPSTAGE_API_KEY`: 您的 Upstage API 键，从 [Upstage 控制台](https://console.upstage.ai/) 获取。

```python theme={null}
import os

os.environ["UPSTAGE_API_KEY"] = "YOUR_API_KEY"
```

## 使用方法

初始化 `UpstageEmbeddings` 类。

```python theme={null}
from langchain_upstage import UpstageEmbeddings

embeddings = UpstageEmbeddings(model="solar-embedding-1-large")
```

使用 `embed_documents` 对文本列表或文档进行嵌入。

```python theme={null}
doc_result = embeddings.embed_documents(
    ["Sung is a professor.", "This is another document"]
)
print(doc_result)
```

使用 `embed_query` 对查询字符串进行嵌入。

```python theme={null}
query_result = embeddings.embed_query("What does Sung do?")
print(query_result)
```

使用 `aembed_documents` 和 `aembed_query` 进行异步操作。

```python theme={null}
# async embed query
await embeddings.aembed_query("My query to look up")
```

```python theme={null}
# async embed documents
await embeddings.aembed_documents(
    ["This is a content of the document", "This is another document"]
)
```

## 与向量存储结合使用

您可以使用 `UpstageEmbeddings` 与向量存储组件结合。以下是一个简单示例。

```python theme={null}
from langchain_community.vectorstores import DocArrayInMemorySearch

vectorstore = DocArrayInMemorySearch.from_texts(
    ["harrison worked at kensho", "bears like to eat honey"],
    embedding=UpstageEmbeddings(model="solar-embedding-1-large"),
)
retriever = vectorstore.as_retriever()
docs = retriever.invoke("Where did Harrison work?")
print(docs)
```

***

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


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