Files
deepset-ai--haystack/docs-website/reference_versioned_docs/version-2.30/integrations-api/searchapi.md
T
wehub-resource-sync c56bef871b
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:22:28 +08:00

3.4 KiB
Raw Blame History

title, id, description, slug
title id description slug
SearchApi integrations-searchapi SearchApi integration for Haystack /integrations-searchapi

haystack_integrations.components.websearch.searchapi.websearch

SearchApiWebSearch

Uses SearchApi to search the web for relevant documents.

Usage example:

from haystack.utils import Secret

from haystack_integrations.components.websearch.searchapi import SearchApiWebSearch

websearch = SearchApiWebSearch(top_k=10, api_key=Secret.from_env_var("SEARCHAPI_API_KEY"))
results = websearch.run(query="Who is the boyfriend of Olivia Wilde?")

assert results["documents"]
assert results["links"]

init

__init__(
    api_key: Secret = Secret.from_env_var("SEARCHAPI_API_KEY"),
    top_k: int | None = 10,
    allowed_domains: list[str] | None = None,
    search_params: dict[str, Any] | None = None,
) -> None

Initialize the SearchApiWebSearch component.

Parameters:

  • api_key (Secret) API key for the SearchApi API
  • top_k (int | None) Number of documents to return.
  • allowed_domains (list[str] | None) List of domains to limit the search to.
  • search_params (dict[str, Any] | None) Additional parameters passed to the SearchApi API. For example, you can set 'num' to 100 to increase the number of search results. See the SearchApi website for more details.

The default search engine is Google, however, users can change it by setting the engine parameter in the search_params.

to_dict

to_dict() -> dict[str, Any]

Serializes the component to a dictionary.

Returns:

  • dict[str, Any] Dictionary with serialized data.

from_dict

from_dict(data: dict[str, Any]) -> SearchApiWebSearch

Deserializes the component from a dictionary.

Parameters:

  • data (dict[str, Any]) The dictionary to deserialize from.

Returns:

  • SearchApiWebSearch The deserialized component.

run

run(query: str) -> dict[str, list[Document] | list[str]]

Uses SearchApi to search the web.

Parameters:

  • query (str) Search query.

Returns:

  • dict[str, list[Document] | list[str]] A dictionary with the following keys:
  • "documents": List of documents returned by the search engine.
  • "links": List of links returned by the search engine.

Raises:

  • TimeoutError If the request to the SearchApi API times out.
  • SearchApiError If an error occurs while querying the SearchApi API.

run_async

run_async(query: str) -> dict[str, list[Document] | list[str]]

Asynchronously uses SearchApi to search the web.

This is the asynchronous version of the run method with the same parameters and return values.

Parameters:

  • query (str) Search query.

Returns:

  • dict[str, list[Document] | list[str]] A dictionary with the following keys:
  • "documents": List of documents returned by the search engine.
  • "links": List of links returned by the search engine.

Raises:

  • TimeoutError If the request to the SearchApi API times out.
  • SearchApiError If an error occurs while querying the SearchApi API.