Skip to content

Commit b7f75b0

Browse files
julian-rischclaude
andauthored
chore: deprecate SearchApiWebSearch + update docs (#11611)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent eeeb88c commit b7f75b0

5 files changed

Lines changed: 50 additions & 13 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Search engine using Search API.
1717
| **Mandatory init variables** | `api_key`: The SearchAPI API key. Can be set with `SEARCHAPI_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/searchapi.py |
22-
| **Package name** | `haystack-ai` |
20+
| **API reference** | [SearchApi](/reference/integrations-searchapi) |
21+
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/searchapi |
22+
| **Package name** | `searchapi-haystack` |
2323

2424
</div>
2525

@@ -38,12 +38,18 @@ To use [Serper Dev](https://serper.dev/?gclid=Cj0KCQiAgqGrBhDtARIsAM5s0_kPElllv3
3838

3939
## Usage
4040

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

4349
This is an example of how `SearchApiWebSearch` 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 SearchApiWebSearch
52+
from haystack_integrations.components.websearch.searchapi import SearchApiWebSearch
4753

4854
web_search = SearchApiWebSearch(api_key=Secret.from_token("<your-api-key>"))
4955
query = "What is the capital of Germany?"
@@ -62,7 +68,7 @@ from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
6268
from haystack.components.fetchers import LinkContentFetcher
6369
from haystack.components.converters import HTMLToDocument
6470
from haystack.components.generators.chat import OpenAIChatGenerator
65-
from haystack.components.websearch import SearchApiWebSearch
71+
from haystack_integrations.components.websearch.searchapi import SearchApiWebSearch
6672
from haystack.dataclasses import ChatMessage
6773

6874
web_search = SearchApiWebSearch(api_key=Secret.from_token("<your-api-key>"), top_k=2)

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Search engine using Search API.
1717
| **Mandatory init variables** | `api_key`: The SearchAPI API key. Can be set with `SEARCHAPI_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/searchapi.py |
22-
| **Package name** | `haystack-ai` |
20+
| **API reference** | [SearchApi](/reference/integrations-searchapi) |
21+
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/searchapi |
22+
| **Package name** | `searchapi-haystack` |
2323

2424
</div>
2525

@@ -38,12 +38,18 @@ To use [Serper Dev](https://serper.dev/?gclid=Cj0KCQiAgqGrBhDtARIsAM5s0_kPElllv3
3838

3939
## Usage
4040

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

4349
This is an example of how `SearchApiWebSearch` 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 SearchApiWebSearch
52+
from haystack_integrations.components.websearch.searchapi import SearchApiWebSearch
4753

4854
web_search = SearchApiWebSearch(api_key=Secret.from_token("<your-api-key>"))
4955
query = "What is the capital of Germany?"
@@ -62,7 +68,7 @@ from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
6268
from haystack.components.fetchers import LinkContentFetcher
6369
from haystack.components.converters import HTMLToDocument
6470
from haystack.components.generators.chat import OpenAIChatGenerator
65-
from haystack.components.websearch import SearchApiWebSearch
71+
from haystack_integrations.components.websearch.searchapi import SearchApiWebSearch
6672
from haystack.dataclasses import ChatMessage
6773

6874
web_search = SearchApiWebSearch(api_key=Secret.from_token("<your-api-key>"), top_k=2)

haystack/components/websearch/searchapi.py

Lines changed: 10 additions & 1 deletion
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

78
import httpx
@@ -29,7 +30,7 @@ class SearchApiWebSearch:
2930
from haystack.components.websearch import SearchApiWebSearch
3031
from haystack.utils import Secret
3132
32-
websearch = SearchApiWebSearch(top_k=10, api_key=Secret.from_env_var("SERPERDEV_API_KEY"))
33+
websearch = SearchApiWebSearch(top_k=10, api_key=Secret.from_env_var("SEARCHAPI_API_KEY"))
3334
results = websearch.run(query="Who is the boyfriend of Olivia Wilde?")
3435
3536
assert results["documents"]
@@ -57,6 +58,14 @@ def __init__(
5758
The default search engine is Google, however, users can change it by setting the `engine`
5859
parameter in the `search_params`.
5960
"""
61+
warnings.warn(
62+
"`SearchApiWebSearch` will be removed from Haystack in version 3.0, as it is moving to "
63+
"the `searchapi-haystack` package. To continue using it, install that package with "
64+
"`pip install searchapi-haystack` and update your import to "
65+
"`from haystack_integrations.components.websearch.searchapi import SearchApiWebSearch`.",
66+
FutureWarning,
67+
stacklevel=2,
68+
)
6069

6170
self.api_key = api_key
6271
self.top_k = top_k
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
deprecations:
3+
- |
4+
``SearchApiWebSearch`` is deprecated and will be removed from Haystack in version 3.0. It is moving to
5+
the ``searchapi-haystack`` package. To continue using it, install the package with
6+
``pip install searchapi-haystack`` and update your import as follows:
7+
8+
.. code-block:: python
9+
10+
from haystack_integrations.components.websearch.searchapi import SearchApiWebSearch

test/components/websearch/test_searchapi.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,10 @@ def test_web_search(self) -> None:
518518
results = ws.run(query="Who is CEO of Microsoft?")
519519
documents = results["documents"]
520520
links = results["links"]
521-
assert len(documents) == len(links) == 10
521+
# documents can also include answer box, knowledge graph, and related questions, so only
522+
# links (which come from organic results) are guaranteed to be at most top_k
523+
assert 0 < len(documents) <= 10
524+
assert 0 < len(links) <= 10
522525
assert all(isinstance(doc, Document) for doc in documents)
523526
assert all(isinstance(link, str) for link in links)
524527
assert all(link.startswith("http") for link in links)
@@ -534,7 +537,10 @@ async def test_web_search_async(self) -> None:
534537
results = await ws.run_async(query="Who is CEO of Microsoft?")
535538
documents = results["documents"]
536539
links = results["links"]
537-
assert len(documents) == len(links) == 10
540+
# documents can also include answer box, knowledge graph, and related questions, so only
541+
# links (which come from organic results) are guaranteed to be at most top_k
542+
assert 0 < len(documents) <= 10
543+
assert 0 < len(links) <= 10
538544
assert all(isinstance(doc, Document) for doc in documents)
539545
assert all(isinstance(link, str) for link in links)
540546
assert all(link.startswith("http") for link in links)

0 commit comments

Comments
 (0)