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

# Perplexity 集成

> 使用 LangChain Python 与 Perplexity 集成。

> [Perplexity](https://www.perplexity.ai/pro) is the most powerful way to search
> the internet with unlimited Pro Search, upgraded AI models, unlimited file upload,
> image generation, and API credits.
>
> 您可以查看 a [list of available models](https://docs.perplexity.ai/docs/model-cards).

## 安装和设置

Install the Perplexity x LangChain integration package:

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

获取您的 API 密钥 from the [Perplexity API key dashboard](https://www.perplexity.ai/account/api/keys) and set it as the `PERPLEXITY_API_KEY` (or `PPLX_API_KEY`) environment variable. See the [Perplexity getting started guide](https://docs.perplexity.ai/docs/getting-started) for more details.

## 聊天模型

See a variety of [Perplexity usage examples](/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) to fetch web search results from the [Perplexity Search API](https://docs.perplexity.ai/docs/search/quickstart) as [`Document`](https://reference.langchain.com/python/langchain-core/documents/base/Document) objects in a standard retrieval pipeline.

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

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

## 工具

You can use Perplexity as an agent tool to give your agent access to the Perplexity Search API.

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

### PerplexitySearchResults

A tool that queries the Perplexity Search API and returns a JSON array of results (title, URL, snippet, date, last updated).

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

## 向量嵌入模型

You can use [`PerplexityEmbeddings`](/oss/python/integrations/embeddings/perplexity) to generate embeddings via the [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
```

## Deep Agents CLI

Use Perplexity as a first-class provider in the [Deep Agents CLI](/oss/python/deepagents/cli/providers).

Install the CLI with the Perplexity extra:

<CodeGroup>
  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv tool install 'deepagents-cli[perplexity]'
  ```
</CodeGroup>

Then set `PERPLEXITY_API_KEY` and reference Perplexity models with the `perplexity:` prefix (e.g. `perplexity:sonar-pro`) in the interactive `/model` switcher or your config.

## Components reference

| Class                       | Abstraction | Import path                                                  | Description                                                                 |
| --------------------------- | ----------- | ------------------------------------------------------------ | --------------------------------------------------------------------------- |
| `ChatPerplexity`            | Chat model  | `from langchain_perplexity import ChatPerplexity`            | Chat model wrapping the Perplexity API for grounded chat completions.       |
| `PerplexitySearchRetriever` | Retriever   | `from langchain_perplexity import PerplexitySearchRetriever` | Retriever that returns `Document` objects from the Perplexity Search API.   |
| `PerplexitySearchResults`   | Tool        | `from langchain_perplexity import PerplexitySearchResults`   | Tool that returns Perplexity Search API results as a JSON array for agents. |
| `PerplexityEmbeddings`      | Embeddings  | `from langchain_perplexity import PerplexityEmbeddings`      | Embedding model wrapping the Perplexity Embeddings API.                     |

***

<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/providers/perplexity.mdx)或[提交 issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
