Skip to main content
Perplexity Search is a web search API that returns ranked, source-attributed results designed for use by LLMs and agents. It powers the answer engine at perplexity.ai and is exposed through the dedicated Search API endpoint. 本页介绍如何使用 the Perplexity Search API as a LangChain 工具。

设置

安装

Install the LangChain Perplexity integration package:

凭证

You’ll need a Perplexity API key to use this integration. Create one in the Perplexity API key dashboard.
The integration also accepts PERPLEXITY_API_KEY if you prefer that name.

Using PerplexitySearchResults tool

PerplexitySearchResults is a tool that can be used with LangChain agents to perform Perplexity searches. Calling it returns a JSON array of search results, each containing a title, url, snippet, date, and last_updated field.

Advanced features for PerplexitySearchResults

The tool accepts the following constructor and call-time arguments:
  • max_results — number of results to return.
  • 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. 参见 domain filter docs.
  • search_recency_filter — one of "day", "week", "month", "year". 参见 date and time filter docs.
  • search_after_date / search_before_date — date strings in MM/DD/YYYY format.

Use within an Agent

We can use the PerplexitySearchResults 工具与 a LangGraph agent. This gives the agent the ability to dynamically search the web for grounded, source-attributed information. First, set up the 语言模型. 你需要 provide your OpenAI API key:

API 参考

详细文档 of the Perplexity Search API and all of its options, see the Search API reference and the Perplexity API documentation.