From 0775900eb434c48b0ff5b1dff75454a1d89e7bbf Mon Sep 17 00:00:00 2001 From: Ritik Raj Date: Wed, 22 Apr 2026 22:56:38 +0530 Subject: [PATCH 1/3] made few adjustments --- integrations/serperdev.md | 130 ++++++++++++++++++++++++++++++++++++++ logos/serperdev.png | Bin 0 -> 4132 bytes 2 files changed, 130 insertions(+) create mode 100644 integrations/serperdev.md create mode 100644 logos/serperdev.png diff --git a/integrations/serperdev.md b/integrations/serperdev.md new file mode 100644 index 0000000..b801e81 --- /dev/null +++ b/integrations/serperdev.md @@ -0,0 +1,130 @@ +--- +layout: integration +name: SerperDev +description: Uses Serper.dev 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/serperdev.png +version: Haystack 2.0 +toc: true +--- + +### **Table of Contents** +- [Overview](#overview) +- [Installation](#installation) +- [Usage](#usage) +- [License](#license) + +## Overview + +The `SerperDevWebSearch` component allows you to perform web searches using the [Serper.dev](https://serper.dev/) API. 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 `SerperDevWebSearch`, it returns a list of URLs and text snippets that are most relevant to your search. + +## Installation + +Since the Serper.dev 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 [Serper.dev](https://serper.dev/) and set it as an environment variable: + +```bash +export SERPERDEV_API_KEY="your-api-key" +``` + +## Usage + +### Components + +This integration provides the following component: + +- `SerperDevWebSearch`: A component that queries the Serper.dev API to find web pages relevant to a given query. + +### Standalone Usage + +Here is how you can use `SerperDevWebSearch` directly: + +```python +from haystack.components.websearch import SerperDevWebSearch +from haystack.utils import Secret +import os + +# Ensure the environment variable is set +os.environ["SERPERDEV_API_KEY"] = "your-api-key" + +# Initialize the component (it automatically uses the SERPERDEV_API_KEY environment variable) +web_search = SerperDevWebSearch(api_key=Secret.from_env_var("SERPERDEV_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 `SerperDevWebSearch` 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 SerperDevWebSearch +from haystack.components.builders.prompt_builder import PromptBuilder +from haystack.components.generators import OpenAIGenerator + +os.environ["SERPERDEV_API_KEY"] = "your-serperdev-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", SerperDevWebSearch()) +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/serperdev.png b/logos/serperdev.png new file mode 100644 index 0000000000000000000000000000000000000000..b96d932d92bb366fa55d37fb456a3d44f58ecfdd GIT binary patch literal 4132 zcmZ{nSv=Ga_s74Il%=whLQ$w_>`O5bA=yg!k#%g7CHwj-Lb9fioygK8vb6}&lr4;H ztTXm~n;5fxXY=>`@1Be2;=DiSoY(7f&ds?w$(H6uyj*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204b08 Mon Sep 17 00:00:00 2001 From: Ritik Raj <149488602+ritikraj2425@users.noreply.github.com> Date: Fri, 24 Apr 2026 11:28:07 +0530 Subject: [PATCH 2/3] Apply suggestion from @bilgeyucel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bilge Yücel --- integrations/serperdev.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/serperdev.md b/integrations/serperdev.md index b801e81..0d1fdbc 100644 --- a/integrations/serperdev.md +++ b/integrations/serperdev.md @@ -51,7 +51,7 @@ export SERPERDEV_API_KEY="your-api-key" This integration provides the following component: -- `SerperDevWebSearch`: A component that queries the Serper.dev API to find web pages relevant to a given query. +- [`SerperDevWebSearch`](https://docs.haystack.deepset.ai/docs/serperdevwebsearch): A component that queries the Serper.dev API to find web pages relevant to a given query. ### Standalone Usage From a42e2b0014f415978f07e80da8e95c4f37b183f3 Mon Sep 17 00:00:00 2001 From: Ritik Raj Date: Fri, 24 Apr 2026 11:36:11 +0530 Subject: [PATCH 3/3] Update SerperDev pipeline example to use ChatPromptBuilder and OpenAIChatGenerator --- integrations/serperdev.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/integrations/serperdev.md b/integrations/serperdev.md index 0d1fdbc..9c10f82 100644 --- a/integrations/serperdev.md +++ b/integrations/serperdev.md @@ -90,13 +90,15 @@ You can integrate `SerperDevWebSearch` directly into a Generative QA pipeline to import os from haystack import Pipeline from haystack.components.websearch import SerperDevWebSearch -from haystack.components.builders.prompt_builder import PromptBuilder -from haystack.components.generators import OpenAIGenerator +from haystack.components.builders import ChatPromptBuilder +from haystack.components.generators.chat import OpenAIChatGenerator +from haystack.dataclasses import ChatMessage os.environ["SERPERDEV_API_KEY"] = "your-serperdev-api-key" os.environ["OPENAI_API_KEY"] = "your-openai-api-key" -template = """ +template = [ + ChatMessage.from_user(""" Given the following web search results, answer the user's question. Search Results: @@ -106,23 +108,24 @@ Search Results: Question: {{ query }} Answer: -""" +""") +] pipe = Pipeline() pipe.add_component("websearch", SerperDevWebSearch()) -pipe.add_component("prompt_builder", PromptBuilder(template=template)) -pipe.add_component("llm", OpenAIGenerator()) +pipe.add_component("prompt_builder", ChatPromptBuilder(template=template)) +pipe.add_component("llm", OpenAIChatGenerator()) pipe.connect("websearch.documents", "prompt_builder.documents") -pipe.connect("prompt_builder", "llm") +pipe.connect("prompt_builder.prompt", "llm.messages") query = "What are the latest features in Haystack 2.0?" response = pipe.run({ "websearch": {"query": query}, - "prompt_builder": {"query": query} + "prompt_builder": {"template_variables": {"query": query}} }) -print(response["llm"]["replies"][0]) +print(response["llm"]["replies"][0].content) ``` ## License