SearchApiWebSearch
Search the web for relevant documents using SearchApi. Use this component in pipelines that need to retrieve information from the web.
Key Features
- Searches the web using the SearchApi service.
- Configurable number of results with
top_k. - Supports filtering results by allowed domains.
- Supports passing additional parameters to the SearchApi API, including the ability to change the search engine.
- Returns both documents and links from the search results.
Configuration
- Drag the
SearchApiWebSearchcomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set the
SEARCHAPI_API_KEYsecret in your workspace. For instructions, see Add Secrets. - Set
top_kto control the number of results to return.
- Set the
- Go to the Advanced tab to configure
allowed_domainsandsearch_params.
Connections
SearchApiWebSearch receives a search query string as input. It outputs a list of documents and a list of links. Connect it to components that process or present web search results.
Source Code
To check this component's source code, open searchapi.py in the Haystack repository.
Usage Examples
Basic Configuration
SearchApiWebSearch:
type: components.websearch.searchapi.SearchApiWebSearch
init_parameters: {}
Connect the pipeline's query input to its query input. Connect its documents output to a PromptBuilder or other components that process retrieved content.
components:
SearchApiWebSearch:
type: components.websearch.searchapi.SearchApiWebSearch
init_parameters:
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
query | str | Search query. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | List of documents returned by the search engine. |
links | List[str] | List of links returned by the search engine. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| api_key | Secret | Secret.from_env_var('SEARCHAPI_API_KEY') | API key for the SearchApi API |
| top_k | Optional[int] | 10 | Number of documents to return. |
| allowed_domains | Optional[List[str]] | None | List of domains to limit the search to. |
| search_params | Optional[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. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
| query | str | Search query. |
Related Information
Was this page helpful?