Skip to main content
Version: 3.5

WebRouterWebSearch

Most common position in a pipelineBefore a prompt builder, or before WebRouterFetcher to retrieve page content
Mandatory init variablesNone
Mandatory run variablesquery: The search query
Output variablesdocuments: Search results as Haystack Documents. links: Result URLs.
API referenceWebRouter
GitHub linkhttps://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/webrouter
Package namewebrouter-haystack

Overview​

WebRouterWebSearch uses WebRouter to search through several providers using one interface. With the default configuration, it uses providers that need no API key and falls back when a provider fails.

Each result becomes a Haystack Document. Its content contains the fullest text returned by the provider; some providers return only a snippet. Document metadata includes title, url and provider, plus published_date when available. The Document's score holds the provider's score when available. links contains the result URLs.

Configuration​

  • top_k limits the number of results (default: 10).
  • provider selects a specific backend; omit it to use automatic routing.
  • search_params forwards options such as include_domains and timeout to WebRouter. A max_results entry overrides top_k. A dictionary passed to run() replaces the initialization dictionary for that call.

See the component API reference for supported providers and parameters, and the WebRouter documentation for backend behavior.

Credentials​

The component uses API keys explicitly supplied through provider_keys. For example, to use Tavily, set TAVILY_API_KEY and reference it with a Haystack Secret:

python
from haystack.utils import Secret
from haystack_integrations.components.websearch.webrouter import WebRouterWebSearch

search = WebRouterWebSearch(
provider="tavily",
provider_keys={"tavily": Secret.from_env_var("TAVILY_API_KEY")},
)

Secrets are resolved during warm-up. provider_keys supports providers that can be configured with an API key alone. See the API reference for supported providers.

Usage​

Install the integration:

shell
pip install webrouter-haystack

On its own​

This example needs no API key:

python
from haystack_integrations.components.websearch.webrouter import WebRouterWebSearch

search = WebRouterWebSearch(top_k=3)
result = search.run(query="What is Haystack by deepset?")
for document in result["documents"]:
print(document.meta["url"])
print(document.content)

Use await search.run_async(query=...) to search from async code.

In a pipeline​

Connect links to WebRouterFetcher.urls to fetch page content rather than use search snippets:

python
from haystack import Pipeline
from haystack_integrations.components.fetchers.webrouter import WebRouterFetcher
from haystack_integrations.components.websearch.webrouter import WebRouterWebSearch

search = WebRouterWebSearch(top_k=1)
fetcher = WebRouterFetcher()
pipeline = Pipeline()
pipeline.add_component("search", search)
pipeline.add_component("fetcher", fetcher)
pipeline.connect("search.links", "fetcher.urls")

result = pipeline.run(data={"search": {"query": "What is Haystack by deepset?"}})
for document in result["fetcher"]["documents"]:
print(document.content)
print(result["fetcher"]["meta"]["failures"])