Skip to content

Commit d47e327

Browse files
authored
Add Perplexity integration entry (#478)
* Add Perplexity integration entry * docs(perplexity): align with latest perplexity-haystack integration - Remove all references to Sonar models. The integration uses the Agent API (OpenAI-compatible Responses) and Search API exclusively. - Update PerplexityChatGenerator default to openai/gpt-5.4 (was sonar-pro). - Surface the actual list of supported Agent API models (openai/gpt-5.5, openai/gpt-5.4, openai/gpt-4o, anthropic/claude-sonnet-4-6, xai/grok-4-1, google/gemini-3-flash-preview). - Mention default + alternative embedding models (pplx-embed-v1-0.6b, pplx-embed-v1-4b). - Add a PerplexityDocumentEmbedder example. - Section title 'Chat Completions (Agent API)' to make the API surface explicit.
1 parent 51fa1ae commit d47e327

2 files changed

Lines changed: 126 additions & 0 deletions

File tree

integrations/perplexity.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
layout: integration
3+
name: Perplexity
4+
description: Use the Perplexity Agent API, Embeddings API, and grounded Search API in Haystack pipelines.
5+
authors:
6+
- name: deepset
7+
socials:
8+
github: deepset-ai
9+
twitter: deepset_ai
10+
linkedin: https://www.linkedin.com/company/deepset-ai/
11+
pypi: https://pypi.org/project/perplexity-haystack
12+
repo: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/perplexity
13+
type: Model Provider
14+
report_issue: https://github.com/deepset-ai/haystack-core-integrations/issues
15+
logo: /logos/perplexity.png
16+
version: Haystack 2.0
17+
toc: true
18+
---
19+
20+
### **Table of Contents**
21+
- [Overview](#overview)
22+
- [Installation](#installation)
23+
- [Usage](#usage)
24+
- [License](#license)
25+
26+
## Overview
27+
28+
The `perplexity-haystack` package lets you use Perplexity's Agent API, Embeddings API, and grounded Search API in Haystack pipelines through four components:
29+
30+
- `PerplexityChatGenerator` — chat completions through the Perplexity Agent API (OpenAI-compatible Responses API). Defaults to `openai/gpt-5.4`; other supported models include `openai/gpt-5.5`, `openai/gpt-4o`, `anthropic/claude-sonnet-4-6`, `xai/grok-4-1`, and `google/gemini-3-flash-preview`.
31+
- `PerplexityTextEmbedder` and `PerplexityDocumentEmbedder` — embeddings through the Perplexity Embeddings API. Defaults to `pplx-embed-v1-0.6b`; `pplx-embed-v1-4b` is also available.
32+
- `PerplexityWebSearch` — grounded web search results through the Perplexity Search API.
33+
34+
For more information about the Perplexity API, see [the Perplexity docs](https://docs.perplexity.ai).
35+
36+
In order to follow along with this guide, you'll need a Perplexity API key. Add it as an environment variable, `PERPLEXITY_API_KEY`.
37+
38+
## Installation
39+
40+
```bash
41+
pip install perplexity-haystack
42+
```
43+
44+
## Usage
45+
46+
You can use the Perplexity components as standalone components or in Haystack pipelines.
47+
48+
### Use Perplexity Chat Completions (Agent API)
49+
50+
`PerplexityChatGenerator` is powered by the Perplexity Agent API and defaults to `openai/gpt-5.4`.
51+
52+
```python
53+
import os
54+
55+
from haystack.dataclasses import ChatMessage
56+
from haystack_integrations.components.generators.perplexity import PerplexityChatGenerator
57+
58+
os.environ["PERPLEXITY_API_KEY"] = "YOUR_PERPLEXITY_API_KEY"
59+
60+
client = PerplexityChatGenerator()
61+
response = client.run(
62+
messages=[ChatMessage.from_user("What are Agentic Pipelines? Be brief.")]
63+
)
64+
65+
print(response["replies"])
66+
```
67+
68+
You can pick any of the supported Agent API models via the `model` parameter, for example:
69+
70+
```python
71+
client = PerplexityChatGenerator(model="anthropic/claude-sonnet-4-6")
72+
```
73+
74+
### Use Perplexity Embeddings
75+
76+
```python
77+
import os
78+
79+
from haystack_integrations.components.embedders.perplexity import PerplexityTextEmbedder
80+
81+
os.environ["PERPLEXITY_API_KEY"] = "YOUR_PERPLEXITY_API_KEY"
82+
83+
embedder = PerplexityTextEmbedder()
84+
response = embedder.run(text="What is Haystack by deepset?")
85+
86+
print(response["embedding"])
87+
```
88+
89+
For embedding a list of documents, use `PerplexityDocumentEmbedder`:
90+
91+
```python
92+
from haystack import Document
93+
from haystack_integrations.components.embedders.perplexity import PerplexityDocumentEmbedder
94+
95+
docs = [Document(content="What is Haystack by deepset?")]
96+
result = PerplexityDocumentEmbedder().run(documents=docs)
97+
98+
print(result["documents"][0].embedding)
99+
```
100+
101+
### Use Perplexity Web Search (Search API)
102+
103+
```python
104+
import os
105+
106+
from haystack.utils import Secret
107+
from haystack_integrations.components.websearch.perplexity import PerplexityWebSearch
108+
109+
os.environ["PERPLEXITY_API_KEY"] = "YOUR_PERPLEXITY_API_KEY"
110+
111+
websearch = PerplexityWebSearch(
112+
api_key=Secret.from_env_var("PERPLEXITY_API_KEY"),
113+
top_k=5,
114+
)
115+
result = websearch.run(query="What is Haystack by deepset?")
116+
117+
documents = result["documents"]
118+
links = result["links"]
119+
120+
print(documents)
121+
print(links)
122+
```
123+
124+
### License
125+
126+
`perplexity-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.

logos/perplexity.png

8.7 KB
Loading

0 commit comments

Comments
 (0)