Skip to main content
Perplexity Search is a web search API that returns ranked, source-attributed results designed for use by LLMs and agents. The Search API endpoint returns the underlying web results that power Perplexity’s answer engine.
我们可以将其用作检索器。 它将展示此集成特有的功能。 After going through, it may be useful to explore relevant use-case pages to learn how to use this retriever as part of a larger chain.

设置

安装

The integration lives in the langchain-perplexity package:

凭证

You’ll need a Perplexity API key to use this integration. Create one in the Perplexity API key dashboard, then set it as the PPLX_API_KEY environment variable (the integration also accepts PERPLEXITY_API_KEY).
如果您希望从单个查询中获得自动追踪功能,还可以通过取消注释以下代码来设置 LangSmith API 密钥:

实例化

PerplexitySearchRetriever accepts the following constructor arguments:
  • k — max number of results (1–20). Defaults to 10.
  • max_tokens — max total tokens across all results.
  • max_tokens_per_page — max tokens returned per result page.
  • country — ISO country code to bias results (e.g. "US").
  • search_domain_filter — list of domains to include or exclude (max 20). Prefix a domain with - to exclude it. See the domain filter docs.
  • search_recency_filter — one of "day", "week", "month", "year". See the date and time filter docs.
  • search_after_date / search_before_date — date strings in MM/DD/YYYY format.

用法

Each returned Document has the result snippet as its page_content, plus title, url, date, and last_updated in metadata.

Filtered usage

You can constrain the search with the same filters supported by the Perplexity Search API:

在链中使用

We can easily combine this retriever into a chain to build a simple RAG pipeline.

API 参考

For detailed documentation of the Perplexity Search API and all of its options, see the Search API reference and the Perplexity API documentation.