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.
We can use this as a retriever. It will show functionality specific to this integration. 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.

Setup

Installation

The integration lives in the langchain-perplexity package:

Credentials

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).
If you want to get automated tracing from individual queries, you can also set your LangSmith API key by uncommenting below:

Instantiation

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.

Usage

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:

Use within a chain

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

API reference

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