DocumentationAPI ReferenceπŸ““ TutorialsπŸ§‘β€πŸ³ Cookbook🀝 IntegrationsπŸ’œ Discord

Web search engine for Haystack.

Module serper_dev

SerperDevWebSearch

Uses Serper to search the web for relevant documents.

See the Serper Dev website for more details.

Usage example:

from haystack.components.websearch import SerperDevWebSearch
from haystack.utils import Secret

websearch = SerperDevWebSearch(top_k=10, api_key=Secret.from_token("test-api-key"))
results = websearch.run(query="Who is the boyfriend of Olivia Wilde?")

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

SerperDevWebSearch.__init__

def __init__(api_key: Secret = Secret.from_env_var("SERPERDEV_API_KEY"),
             top_k: Optional[int] = 10,
             allowed_domains: Optional[List[str]] = None,
             search_params: Optional[Dict[str, Any]] = None)

Initialize the SerperDevWebSearch component.

Arguments:

  • api_key: API key for the Serper API.
  • top_k: Number of documents to return.
  • allowed_domains: List of domains to limit the search to.
  • search_params: Additional parameters passed to the Serper API. For example, you can set 'num' to 20 to increase the number of search results. See the Serper website for more details.

SerperDevWebSearch.to_dict

def to_dict() -> Dict[str, Any]

Serializes the component to a dictionary.

Returns:

Dictionary with serialized data.

SerperDevWebSearch.from_dict

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "SerperDevWebSearch"

Serializes the component to a dictionary.

Returns:

Dictionary with serialized data.

SerperDevWebSearch.run

@component.output_types(documents=List[Document], links=List[str])
def run(query: str) -> Dict[str, Union[List[Document], List[str]]]

Use Serper to search the web.

Arguments:

  • query: Search query.

Raises:

  • SerperDevError: If an error occurs while querying the SerperDev API.
  • TimeoutError: If the request to the SerperDev API times out.

Returns:

A dictionary with the following keys:

  • "documents": List of documents returned by the search engine.
  • "links": List of links returned by the search engine.

Module searchapi

SearchApiWebSearch

Uses SearchApi to search the web for relevant documents.

Usage example:

from haystack.components.websearch import SearchApiWebSearch
from haystack.utils import Secret

websearch = SearchApiWebSearch(top_k=10, api_key=Secret.from_token("test-api-key"))
results = websearch.run(query="Who is the boyfriend of Olivia Wilde?")

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

SearchApiWebSearch.__init__

def __init__(api_key: Secret = Secret.from_env_var("SEARCHAPI_API_KEY"),
             top_k: Optional[int] = 10,
             allowed_domains: Optional[List[str]] = None,
             search_params: Optional[Dict[str, Any]] = None)

Initialize the SearchApiWebSearch component.

Arguments:

  • api_key: API key for the SearchApi API
  • top_k: Number of documents to return.
  • allowed_domains: List of domains to limit the search to.
  • search_params: 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.

SearchApiWebSearch.to_dict

def to_dict() -> Dict[str, Any]

Serializes the component to a dictionary.

Returns:

Dictionary with serialized data.

SearchApiWebSearch.from_dict

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "SearchApiWebSearch"

Deserializes the component from a dictionary.

Arguments:

  • data: The dictionary to deserialize from.

Returns:

The deserialized component.

SearchApiWebSearch.run

@component.output_types(documents=List[Document], links=List[str])
def run(query: str) -> Dict[str, Union[List[Document], List[str]]]

Uses SearchApi to search the web.

Arguments:

  • query: Search query.

Raises:

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

Returns:

A dictionary with the following keys:

  • "documents": List of documents returned by the search engine.
  • "links": List of links returned by the search engine.