From f1734f96691b3a8f6992897979a6c91618fa926e Mon Sep 17 00:00:00 2001 From: Ritik Raj Date: Wed, 22 Apr 2026 23:04:59 +0530 Subject: [PATCH 1/6] Add Search API integration page Closes #447 --- integrations/searchapi.md | 130 ++++++++++++++++++++++++++++++++++++++ logos/searchapi.png | Bin 0 -> 2083 bytes 2 files changed, 130 insertions(+) create mode 100644 integrations/searchapi.md create mode 100644 logos/searchapi.png diff --git a/integrations/searchapi.md b/integrations/searchapi.md new file mode 100644 index 0000000..82beff1 --- /dev/null +++ b/integrations/searchapi.md @@ -0,0 +1,130 @@ +--- +layout: integration +name: SearchApi +description: Uses SearchApi.io API for web searches +authors: + - name: deepset + socials: + github: deepset-ai + twitter: deepset_ai + linkedin: https://www.linkedin.com/company/deepset-ai/ +pypi: https://pypi.org/project/haystack-ai/ +repo: https://github.com/deepset-ai/haystack +type: Data Ingestion +report_issue: https://github.com/deepset-ai/haystack/issues +logo: /logos/searchapi.png +version: Haystack 2.0 +toc: true +--- + +### **Table of Contents** +- [Overview](#overview) +- [Installation](#installation) +- [Usage](#usage) +- [License](#license) + +## Overview + +The `SearchApiWebSearch` component allows you to perform web searches using the [SearchApi.io](https://www.searchapi.io/) service. It retrieves relevant snippets and URLs that can be used directly in your Haystack applications, such as Retrieval-Augmented Generation (RAG) pipelines or with Haystack Agents. + +This component is part of the core `haystack-ai` package, meaning you do not need to install an external integration package to use it. + +When you pass a query to `SearchApiWebSearch`, it returns a list of URLs and text snippets that are most relevant to your search. + +## Installation + +Since the SearchApi web search component is built into the core Haystack framework, you just need to install `haystack-ai`: + +```bash +pip install haystack-ai +``` + +You will also need to get an API key from [SearchApi.io](https://www.searchapi.io/) and set it as an environment variable: + +```bash +export SEARCHAPI_API_KEY="your-api-key" +``` + +## Usage + +### Components + +This integration provides the following component: + +- `SearchApiWebSearch`: A component that queries the SearchApi service to find web pages relevant to a given query. + +### Standalone Usage + +Here is how you can use `SearchApiWebSearch` directly: + +```python +from haystack.components.websearch import SearchApiWebSearch +from haystack.utils import Secret +import os + +# Ensure the environment variable is set +os.environ["SEARCHAPI_API_KEY"] = "your-api-key" + +# Initialize the component (it automatically uses the SEARCHAPI_API_KEY environment variable) +web_search = SearchApiWebSearch(api_key=Secret.from_env_var("SEARCHAPI_API_KEY")) + +# Run a search query +results = web_search.run(query="What is Haystack AI?") + +# Access the search results +documents = results["documents"] +links = results["links"] + +for doc in documents: + print(f"Title: {doc.meta.get('title')}") + print(f"Snippet: {doc.content}") + print(f"URL: {doc.meta.get('link')}") + print("-" * 50) +``` + +### Usage within a Pipeline + +You can integrate `SearchApiWebSearch` directly into a Generative QA pipeline to answer questions using the live web context: + +```python +import os +from haystack import Pipeline +from haystack.components.websearch import SearchApiWebSearch +from haystack.components.builders.prompt_builder import PromptBuilder +from haystack.components.generators import OpenAIGenerator + +os.environ["SEARCHAPI_API_KEY"] = "your-searchapi-api-key" +os.environ["OPENAI_API_KEY"] = "your-openai-api-key" + +template = """ +Given the following web search results, answer the user's question. + +Search Results: +{% for document in documents %} + {{ document.content }} +{% endfor %} + +Question: {{ query }} +Answer: +""" + +pipe = Pipeline() +pipe.add_component("websearch", SearchApiWebSearch()) +pipe.add_component("prompt_builder", PromptBuilder(template=template)) +pipe.add_component("llm", OpenAIGenerator()) + +pipe.connect("websearch.documents", "prompt_builder.documents") +pipe.connect("prompt_builder", "llm") + +query = "What are the latest features in Haystack 2.0?" +response = pipe.run({ + "websearch": {"query": query}, + "prompt_builder": {"query": query} +}) + +print(response["llm"]["replies"][0]) +``` + +## License + +`haystack-ai` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license. diff --git a/logos/searchapi.png b/logos/searchapi.png new file mode 100644 index 0000000000000000000000000000000000000000..29f3fb03e1ce021cee234d67bb27106cab6cf148 GIT binary patch literal 2083 zcmYk7c|4SfAIEK*R4cI!K2uZ)Z-%v{$yP;GML9XSt!AdMo9o&B&nf)8 zZpEG4b#IVZn3KpaV^ANhF|D=mp?bA!NU zN!;v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q5b$@)ptY$H18<8{%VH4jN%l`Yn%XwWu(U(Tj>B(14}9*w0@9UW6#AYOy(e zbV{M<__DxYp5&F?ycterik;@QQ!$i*{L|4(3j*S%QSj;?Z3T{vaEz6PzRFm}pe4W4 z7~T&1KT$88b-!nR#zk%Mu)l70pf5Hpy8`*rT)W{|9vgo^@@?umzm!P!%P3lhc-6Pq zEUlixUu|yAyi#yX*gq{O3u}PE&!84-<;C&lMwKQ%9g;2n+n!i0W1dtUo>QMi?`0Wm zHa?-bN4*Bo_q&Ruf46$0QROWm*LI)cXPR+G(`tqCNtN+o|5-G^5WA^Vi>4C`W+D&p zjz37=yq(dS(Lt0NSW!2~Z)dh{YoL45aFHqf&S{~Gu?`QjD+ki-+)n!VE5~PnI7_wZ z_G9j`vs(JU&7zqbTlL<_1R4QNI_aqT!T8swBA$78V=r>Bs_Ltnvn#I&D7VChi_bC-P$4L6&8XI32?05-08W+oX;C1TUmOMS)?o$|Q3gp+*kXJI- zlb(wRwT|gMS5;SQR20K;9`aR=6R987ZIV-NyR}`f=8parAp^S1CTi`cCSToZs8?gF zs9~D;HaEHPQBo4{^ObX_bELWUU-qlSbM)lRTrcm-D^r#gjw$Bg42=Xl|5JF zO|ocLFCYw+790>9RWEq#Gqs#;3y_s2*PEA#j@z@-nYmMKraF>}e|Mi`bmREZ%%Omr z_g&9`BXXdcAUVe3pWN0x0?KShyIx*<~i81UlnZrEPnm%%b6Kj!kVvnB>xQ%SijK# literal 0 HcmV?d00001 From ae794d802c4f1a1293e35fedef4304511aa70c3b Mon Sep 17 00:00:00 2001 From: Ritik Raj <149488602+ritikraj2425@users.noreply.github.com> Date: Fri, 24 Apr 2026 11:39:05 +0530 Subject: [PATCH 2/6] Update integrations/searchapi.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bilge Yücel --- integrations/searchapi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/searchapi.md b/integrations/searchapi.md index 82beff1..fa72f4b 100644 --- a/integrations/searchapi.md +++ b/integrations/searchapi.md @@ -51,7 +51,7 @@ export SEARCHAPI_API_KEY="your-api-key" This integration provides the following component: -- `SearchApiWebSearch`: A component that queries the SearchApi service to find web pages relevant to a given query. +- [`SearchApiWebSearch`](https://docs.haystack.deepset.ai/docs/searchapiwebsearch): A component that queries the SearchApi service to find web pages relevant to a given query. ### Standalone Usage From a45b4a7b4d584752595031d45836ebd2c2b2f578 Mon Sep 17 00:00:00 2001 From: Ritik Raj <149488602+ritikraj2425@users.noreply.github.com> Date: Fri, 24 Apr 2026 11:39:19 +0530 Subject: [PATCH 3/6] Update integrations/searchapi.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bilge Yücel --- integrations/searchapi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/searchapi.md b/integrations/searchapi.md index fa72f4b..7a31515 100644 --- a/integrations/searchapi.md +++ b/integrations/searchapi.md @@ -39,7 +39,7 @@ Since the SearchApi web search component is built into the core Haystack framewo pip install haystack-ai ``` -You will also need to get an API key from [SearchApi.io](https://www.searchapi.io/) and set it as an environment variable: +You will also need to get an API key from [SearchApi](https://www.searchapi.io/) and set it as an environment variable: ```bash export SEARCHAPI_API_KEY="your-api-key" From f12a2aaec9cf6c17be0eeba7ae1d1697e743cb6c Mon Sep 17 00:00:00 2001 From: Ritik Raj <149488602+ritikraj2425@users.noreply.github.com> Date: Fri, 24 Apr 2026 11:39:30 +0530 Subject: [PATCH 4/6] Update integrations/searchapi.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bilge Yücel --- integrations/searchapi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/searchapi.md b/integrations/searchapi.md index 7a31515..3bf744a 100644 --- a/integrations/searchapi.md +++ b/integrations/searchapi.md @@ -25,7 +25,7 @@ toc: true ## Overview -The `SearchApiWebSearch` component allows you to perform web searches using the [SearchApi.io](https://www.searchapi.io/) service. It retrieves relevant snippets and URLs that can be used directly in your Haystack applications, such as Retrieval-Augmented Generation (RAG) pipelines or with Haystack Agents. +The `SearchApiWebSearch` component allows you to perform web searches using the [SearchApi](https://www.searchapi.io/) service. It retrieves relevant snippets and URLs that can be used directly in your Haystack applications, such as Retrieval-Augmented Generation (RAG) pipelines or with Haystack Agents. This component is part of the core `haystack-ai` package, meaning you do not need to install an external integration package to use it. From a6b34c76364695210fc631617d8fb2e35386a741 Mon Sep 17 00:00:00 2001 From: Ritik Raj <149488602+ritikraj2425@users.noreply.github.com> Date: Fri, 24 Apr 2026 11:39:49 +0530 Subject: [PATCH 5/6] Update integrations/searchapi.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bilge Yücel --- integrations/searchapi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/searchapi.md b/integrations/searchapi.md index 3bf744a..ce08fea 100644 --- a/integrations/searchapi.md +++ b/integrations/searchapi.md @@ -1,7 +1,7 @@ --- layout: integration name: SearchApi -description: Uses SearchApi.io API for web searches +description: Uses SearchApi for web searches authors: - name: deepset socials: From a473e4dfc0818d4dfe031c7f6adb3faf51cfd310 Mon Sep 17 00:00:00 2001 From: Ritik Raj Date: Fri, 24 Apr 2026 11:43:07 +0530 Subject: [PATCH 6/6] removed usage in pipeline section --- integrations/searchapi.md | 42 --------------------------------------- 1 file changed, 42 deletions(-) diff --git a/integrations/searchapi.md b/integrations/searchapi.md index ce08fea..2371fb2 100644 --- a/integrations/searchapi.md +++ b/integrations/searchapi.md @@ -82,48 +82,6 @@ for doc in documents: print("-" * 50) ``` -### Usage within a Pipeline - -You can integrate `SearchApiWebSearch` directly into a Generative QA pipeline to answer questions using the live web context: - -```python -import os -from haystack import Pipeline -from haystack.components.websearch import SearchApiWebSearch -from haystack.components.builders.prompt_builder import PromptBuilder -from haystack.components.generators import OpenAIGenerator - -os.environ["SEARCHAPI_API_KEY"] = "your-searchapi-api-key" -os.environ["OPENAI_API_KEY"] = "your-openai-api-key" - -template = """ -Given the following web search results, answer the user's question. - -Search Results: -{% for document in documents %} - {{ document.content }} -{% endfor %} - -Question: {{ query }} -Answer: -""" - -pipe = Pipeline() -pipe.add_component("websearch", SearchApiWebSearch()) -pipe.add_component("prompt_builder", PromptBuilder(template=template)) -pipe.add_component("llm", OpenAIGenerator()) - -pipe.connect("websearch.documents", "prompt_builder.documents") -pipe.connect("prompt_builder", "llm") - -query = "What are the latest features in Haystack 2.0?" -response = pipe.run({ - "websearch": {"query": query}, - "prompt_builder": {"query": query} -}) - -print(response["llm"]["replies"][0]) -``` ## License