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

# Perplexity 集成

> 使用 LangChain Python 与 Perplexity 集成。

> [Perplexity](https://www.perplexity.ai/pro) 是最强大的互联网搜索方式，提供无限 Pro 搜索、升级的 AI 模型、无限文件上传、图像生成和 API 额度。
>
> 你可以查看[可用模型列表](https://docs.perplexity.ai/docs/model-cards)。

## 安装与设置

安装 Perplexity x LangChain 集成包：

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-perplexity
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-perplexity
  ```
</CodeGroup>

从 [Perplexity API 密钥仪表板](https://www.perplexity.ai/account/api/keys) 获取你的 API 密钥，并将其设置为 `PPLX_API_KEY`（或 `PERPLEXITY_API_KEY`）环境变量。更多详情请参阅 [Perplexity 入门指南](https://docs.perplexity.ai/docs/getting-started)。

## 聊天模型

查看各种 [Perplexity 使用示例](/oss/python/integrations/chat/perplexity)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_perplexity import ChatPerplexity
```

## 检索器

你可以使用 [`PerplexitySearchRetriever`](/oss/python/integrations/retrievers/perplexity_search) 从 [Perplexity Search API](https://docs.perplexity.ai/docs/search/quickstart) 获取网页搜索结果，并将其作为标准检索管道中的 [`Document`](https://reference.langchain.com/python/langchain-core/documents/base/Document) 对象。

查看[使用示例](/oss/python/integrations/retrievers/perplexity_search)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_perplexity import PerplexitySearchRetriever
```

## 工具

你可以将 Perplexity 用作代理工具，让代理能够访问 Perplexity Search API。

查看[使用示例](/oss/python/integrations/tools/perplexity_search)。

### PerplexitySearchResults

一个查询 Perplexity Search API 并返回 JSON 结果数组（标题、URL、摘要、日期、最后更新时间）的工具。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_perplexity import PerplexitySearchResults
```

## 嵌入模型

你可以使用 [`PerplexityEmbeddings`](/oss/python/integrations/embeddings/perplexity) 通过 [Perplexity Embeddings API](https://docs.perplexity.ai/api-reference/embeddings-post) 生成嵌入向量。

查看[使用示例](/oss/python/integrations/embeddings/perplexity)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_perplexity import PerplexityEmbeddings
```

## 组件参考

| 类                           | 抽象   | 导入路径                                                         | 描述                                            |
| --------------------------- | ---- | ------------------------------------------------------------ | --------------------------------------------- |
| `ChatPerplexity`            | 聊天模型 | `from langchain_perplexity import ChatPerplexity`            | 封装 Perplexity API 用于基于事实的聊天补全的聊天模型。           |
| `PerplexitySearchRetriever` | 检索器  | `from langchain_perplexity import PerplexitySearchRetriever` | 从 Perplexity Search API 返回 `Document` 对象的检索器。 |
| `PerplexitySearchResults`   | 工具   | `from langchain_perplexity import PerplexitySearchResults`   | 将 Perplexity Search API 结果作为 JSON 数组返回给代理的工具。 |
| `PerplexityEmbeddings`      | 嵌入   | `from langchain_perplexity import PerplexityEmbeddings`      | 封装 Perplexity Embeddings API 的嵌入模型。           |

***

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

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