You.com Search
haystack_integrations.components.websearch.youcom.youcom_websearch
YouComError
Bases: ComponentError
An error occurred while querying the You.com Search API.
YouComWebSearch
A component that uses the You.com Search API to search the web and return results as Haystack Documents.
Works with zero configuration: when no API key is available, searches use You.com's
keyless free tier (rate limited
per IP), so getting-started pipelines run without any setup. Set the YOUDOTCOM_API_KEY
environment variable (or pass api_key) to use the keyed
You.com Search API with higher limits.
Pass keyless_fallback=False to require a key and fail fast instead of degrading to the
keyless tier — useful in production pipelines where a missing key should surface as an error.
Usage example
from haystack_integrations.components.websearch.youcom import YouComWebSearch
websearch = YouComWebSearch(top_k=5) # no API key needed to get started
result = websearch.run(query="What is Haystack by deepset?")
documents = result["documents"]
links = result["links"]
init
__init__(
api_key: Secret = Secret.from_env_var(API_KEY_ENV_VAR, strict=False),
keyless_fallback: bool = True,
top_k: int | None = 10,
freshness: str | None = None,
country: str | None = None,
search_lang: str | None = None,
safesearch: str | None = None,
extra_params: dict[str, Any] | None = None,
timeout: int = 10,
max_retries: int = 3,
) -> None
Initialize the YouComWebSearch component.
Parameters:
- api_key (
Secret) – You.com API key. Defaults to theYOUDOTCOM_API_KEYenvironment variable. Resolved leniently, so an unset key is not an error — seekeyless_fallbackfor what happens then. - keyless_fallback (
bool) – What to do when no API key resolves. WhenTrue(the default), search the keyless free tier, which needs no credentials but is rate limited per IP; the component logs which endpoint it selected. WhenFalse, raiseYouComErrorinstead, so a missing key fails fast rather than silently degrading. - top_k (
int | None) – Maximum number of results to return per section (web, news). Maps to thecountparameter in the You.com API (1-100). - freshness (
str | None) – Only return results from within the given window:"day","week","month","year", or a date range in the format"YYYY-MM-DDtoYYYY-MM-DD". - country (
str | None) – 2-letter country code determining the geographical focus of web results (e.g."US","DE"). - search_lang (
str | None) – Language of the returned web results in BCP 47 format (e.g."EN","PT-BR"). Maps to thelanguageparameter in the You.com API. - safesearch (
str | None) – Content moderation level:"off","moderate", or"strict". - extra_params (
dict[str, Any] | None) – Additional query parameters passed directly to the You.com Search API (e.g.{"include_domains": "nytimes.com,bbc.com"}). - timeout (
int) – Timeout in seconds for the HTTP request. Defaults to 10. - max_retries (
int) – Maximum number of retry attempts on transient failures. Defaults to 3.
run
Search the web using the You.com Search API and return results as Documents.
Parameters:
- query (
str) – Search query string. - top_k (
int | None) – Optional per-run override of the maximum number of results. If not provided, the init-timetop_kis used.
Returns:
dict[str, Any]– A dictionary with:documents: List of Documents containing search result content.links: List of URLs from the search results.
Raises:
YouComError– If the You.com Search API request fails.
run_async
Asynchronously search the web using the You.com Search API and return results as Documents.
Parameters:
- query (
str) – Search query string. - top_k (
int | None) – Optional per-run override of the maximum number of results. If not provided, the init-timetop_kis used.
Returns:
dict[str, Any]– A dictionary with:documents: List of Documents containing search result content.links: List of URLs from the search results.
Raises:
YouComError– If the You.com Search API request fails.