Skip to content

Commit 1d58f1e

Browse files
julian-rischclaude
andauthored
chore: deprecate SerperDevWebSearch + update docs (#11577)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 19f3985 commit 1d58f1e

5 files changed

Lines changed: 52 additions & 14 deletions

File tree

docs-website/docs/pipeline-components/websearch/serperdevwebsearch.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Search engine using SerperDev API.
1717
| **Mandatory init variables** | `api_key`: The SearchAPI API key. Can be set with `SERPERDEV_API_KEY` env var. |
1818
| **Mandatory run variables** | `query`: A string with your query |
1919
| **Output variables** | `documents`: A list of documents <br /> <br />`links`: A list of strings of resulting links |
20-
| **API reference** | [Websearch](/reference/websearch-api) |
21-
| **GitHub link** | https://github.com/deepset-ai/haystack/blob/main/haystack/components/websearch/serper_dev.py |
22-
| **Package name** | `haystack-ai` |
20+
| **API reference** | [SerperDev](/reference/integrations-serperdev) |
21+
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/serperdev |
22+
| **Package name** | `serperdev-haystack` |
2323

2424
</div>
2525

@@ -38,12 +38,18 @@ To use [Search API](https://www.searchapi.io/) as an alternative, see its respec
3838

3939
## Usage
4040

41+
Install the `serperdev-haystack` package to use the `SerperDevWebSearch` component:
42+
43+
```shell
44+
pip install serperdev-haystack
45+
```
46+
4147
### On its own
4248

4349
This is an example of how `SerperDevWebSearch` looks up answers to our query on the web and converts the results into a list of documents with content snippets of the results, as well as URLs as strings.
4450

4551
```python
46-
from haystack.components.websearch import SerperDevWebSearch
52+
from haystack_integrations.components.websearch.serperdev import SerperDevWebSearch
4753
from haystack.utils import Secret
4854

4955
web_search = SerperDevWebSearch(api_key=Secret.from_token("<your-api-key>"))
@@ -63,7 +69,7 @@ from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
6369
from haystack.components.fetchers import LinkContentFetcher
6470
from haystack.components.converters import HTMLToDocument
6571
from haystack.components.generators.chat import OpenAIChatGenerator
66-
from haystack.components.websearch import SerperDevWebSearch
72+
from haystack_integrations.components.websearch.serperdev import SerperDevWebSearch
6773
from haystack.dataclasses import ChatMessage
6874
from haystack.utils import Secret
6975

@@ -181,7 +187,7 @@ components:
181187
exclude_subdomains: false
182188
search_params: {}
183189
top_k: 2
184-
type: haystack.components.websearch.serper_dev.SerperDevWebSearch
190+
type: haystack_integrations.components.websearch.serperdev.websearch.SerperDevWebSearch
185191
connection_type_validation: true
186192
connections:
187193
- receiver: fetcher.urls

docs-website/versioned_docs/version-2.30/pipeline-components/websearch/serperdevwebsearch.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Search engine using SerperDev API.
1717
| **Mandatory init variables** | `api_key`: The SearchAPI API key. Can be set with `SERPERDEV_API_KEY` env var. |
1818
| **Mandatory run variables** | `query`: A string with your query |
1919
| **Output variables** | `documents`: A list of documents <br /> <br />`links`: A list of strings of resulting links |
20-
| **API reference** | [Websearch](/reference/websearch-api) |
21-
| **GitHub link** | https://github.com/deepset-ai/haystack/blob/main/haystack/components/websearch/serper_dev.py |
22-
| **Package name** | `haystack-ai` |
20+
| **API reference** | [SerperDev](/reference/integrations-serperdev) |
21+
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/serperdev |
22+
| **Package name** | `serperdev-haystack` |
2323

2424
</div>
2525

@@ -38,12 +38,18 @@ To use [Search API](https://www.searchapi.io/) as an alternative, see its respec
3838

3939
## Usage
4040

41+
Install the `serperdev-haystack` package to use the `SerperDevWebSearch` component:
42+
43+
```shell
44+
pip install serperdev-haystack
45+
```
46+
4147
### On its own
4248

4349
This is an example of how `SerperDevWebSearch` looks up answers to our query on the web and converts the results into a list of documents with content snippets of the results, as well as URLs as strings.
4450

4551
```python
46-
from haystack.components.websearch import SerperDevWebSearch
52+
from haystack_integrations.components.websearch.serperdev import SerperDevWebSearch
4753
from haystack.utils import Secret
4854

4955
web_search = SerperDevWebSearch(api_key=Secret.from_token("<your-api-key>"))
@@ -63,7 +69,7 @@ from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
6369
from haystack.components.fetchers import LinkContentFetcher
6470
from haystack.components.converters import HTMLToDocument
6571
from haystack.components.generators.chat import OpenAIChatGenerator
66-
from haystack.components.websearch import SerperDevWebSearch
72+
from haystack_integrations.components.websearch.serperdev import SerperDevWebSearch
6773
from haystack.dataclasses import ChatMessage
6874
from haystack.utils import Secret
6975

@@ -181,7 +187,7 @@ components:
181187
exclude_subdomains: false
182188
search_params: {}
183189
top_k: 2
184-
type: haystack.components.websearch.serper_dev.SerperDevWebSearch
190+
type: haystack_integrations.components.websearch.serperdev.websearch.SerperDevWebSearch
185191
connection_type_validation: true
186192
connections:
187193
- receiver: fetcher.urls

haystack/components/websearch/serper_dev.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import warnings
56
from typing import Any
67
from urllib.parse import urlparse
78

@@ -73,6 +74,15 @@ def __init__(
7374
For example, you can set 'num' to 20 to increase the number of search results.
7475
See the [Serper website](https://serper.dev/) for more details.
7576
"""
77+
warnings.warn(
78+
"`SerperDevWebSearch` will be removed from Haystack in version 3.0, as it is moving to "
79+
"the `serperdev-haystack` package. To continue using it, install that package with "
80+
"`pip install serperdev-haystack` and update your import to "
81+
"`from haystack_integrations.components.websearch.serperdev import SerperDevWebSearch`.",
82+
FutureWarning,
83+
stacklevel=2,
84+
)
85+
7686
self.api_key = api_key
7787
self.top_k = top_k
7888
self.allowed_domains = allowed_domains
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
deprecations:
3+
- |
4+
``SerperDevWebSearch`` is deprecated and will be removed from Haystack in version 3.0. It is moving to
5+
the ``serperdev-haystack`` package. To continue using it, install the package with
6+
``pip install serperdev-haystack`` and update your import as follows:
7+
8+
.. code-block:: python
9+
10+
from haystack_integrations.components.websearch.serperdev import SerperDevWebSearch

test/components/websearch/test_serperdev.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ def test_web_search(self) -> None:
282282
results = ws.run(query="Who is the boyfriend of Olivia Wilde?")
283283
documents = results["documents"]
284284
links = results["links"]
285-
assert len(documents) == len(links) == 10
285+
# documents can also include answer box and "people also ask" results, so only links
286+
# (which come from organic results) are guaranteed to be at most top_k
287+
assert 0 < len(documents) <= 10
288+
assert 0 < len(links) <= 10
286289
assert all(isinstance(doc, Document) for doc in documents)
287290
assert all(isinstance(link, str) for link in links)
288291
assert all(link.startswith("http") for link in links)
@@ -298,7 +301,10 @@ async def test_web_search_async(self) -> None:
298301
results = await ws.run_async(query="Who is the boyfriend of Olivia Wilde?")
299302
documents = results["documents"]
300303
links = results["links"]
301-
assert len(documents) == len(links) == 10
304+
# documents can also include answer box and "people also ask" results, so only links
305+
# (which come from organic results) are guaranteed to be at most top_k
306+
assert 0 < len(documents) <= 10
307+
assert 0 < len(links) <= 10
302308
assert all(isinstance(doc, Document) for doc in documents)
303309
assert all(isinstance(link, str) for link in links)
304310
assert all(link.startswith("http") for link in links)

0 commit comments

Comments
 (0)