WebRouterWebSearch
| Most common position in a pipeline | Before a prompt builder, or before WebRouterFetcher to retrieve page content |
| Mandatory init variables | None |
| Mandatory run variables | query: The search query |
| Output variables | documents: Search results as Haystack Documents. links: Result URLs. |
| API reference | WebRouter |
| GitHub link | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/webrouter |
| Package name | webrouter-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_klimits the number of results (default: 10).providerselects a specific backend; omit it to use automatic routing.search_paramsforwards options such asinclude_domainsandtimeoutto WebRouter. Amax_resultsentry overridestop_k. A dictionary passed torun()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:
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:
On its own
This example needs no API key:
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:
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"])