Introduction
Haystack is an open-source framework for building production-ready LLM applications and RAG pipelines in Python. Tavily integrates with Haystack through thetavily-haystack package maintained by deepset. It exposes a TavilyWebSearch component that queries Tavily Search and returns Haystack Document objects alongside the source URLs.
You can also review the upstream integration page in the Haystack integrations directory.
Installation
Install the integration package:Credentials
Set your Tavily API key as an environment variable:TavilyWebSearch reads from TAVILY_API_KEY, but you can also pass the key explicitly with Secret.from_token(...).
Basic Usage
UseTavilyWebSearch to fetch web results as Haystack Document objects:
search_params:
Using Tavily in a Haystack Pipeline
Here is a simple RAG-style pipeline that searches the web with Tavily, builds a prompt from the returned documents, and sends the prompt to a chat model:Note: This example usesOpenAIChatGenerator, so you will also need to setOPENAI_API_KEY.
Async Usage
TavilyWebSearch also supports asynchronous execution with run_async:
Key Parameters
api_key: Tavily API key. Defaults to theTAVILY_API_KEYenvironment variable.top_k: Maximum number of search results to return. Defaults to10.search_params: Additional parameters forwarded to Tavily Search, includingsearch_depth,include_answer,include_raw_content,include_domains, andexclude_domains.