Tavily Search - Use Cases & API

Tavily Search is a specialized search engine focuses on providing real-time, accurate, and unbiased information, enabling AI applications to retrieve and process data efficiently

Tavily Search API is a specialized search engine designed for Large Language Models (LLMs) and AI agents. It focuses on providing real-time, accurate, and unbiased information, enabling AI applications to retrieve and process data efficiently. Unlike general-purpose search engines, Tavily is built with AI developers in mind, simplifying the integration of dynamic web information into AI-driven solutions.

Key advantages of using Tavily Search API:

  • Purpose-built for AI: Designed specifically for AI agents and LLMs, ensuring ideal results for AI workflows like Retrieval Augmented Generation (RAG).
  • Customizable: Offers control over search depth and domain management.
  • Real-time: Retrieves reliable, up-to-date information.
  • Easy Integration: Simple API setup with support for Python libraries and partnerships with LangChain and LlamaIndex.
  • Scalable: Built to scale for both startups and enterprise customers.
  • Accuracy: Employs advanced algorithms and NLP techniques to gather information from trusted, authoritative sources.

Features and Functionalities

Tavily Search API offers a range of features and functionalities tailored for AI applications:

  • Real-time Web Access: Provides fast and reliable access to real-time information with high rate limits.
  • Accurate Results: Delivers precise and relevant content snippets optimized for AI processing.
  • Customizable Search Depth: Users can control the depth of the search to balance speed and comprehensiveness. Options include "basic" for faster results and "advanced" for more comprehensive searches.
  • Domain Management: Allows users to include or exclude specific domains in their searches, enhancing the relevance and precision of results.
  • Data Enrichment: Ideal for filling in missing data points in datasets by leveraging advanced search algorithms and real-time data retrieval.
  • Image Search: Supports image searches using the include_images parameter.
  • Answer Generation: Can generate answers to questions based on search results, providing both basic and advanced answer options.
  • Raw Content Retrieval: Option to include the cleaned and parsed HTML content of search results.

Quick Start Guide

Here is a quick start guide to using the Tavily Search API in Python:

Step 1: Set up your development environment

  • Python Installation: Ensure you have Python 3.8 or higher installed.

Install Tavily Python client:Bash

pip install tavily-python

Virtual Environment: Create a virtual environment to manage dependencies:Bash

python -m venv langchain_tavily
source langchain_tavily/bin/activate  # On macOS/Linux
langchain_tavily\\Scripts\\activate # On Windows

Step 2: Obtain and configure your API Key

  • Sign up: Create an account at the Tavily website.
  • Retrieve API Key: Obtain your API key from your account dashboard.1

Set API Key as environment variable:Python

import os
os.environ["TAVILY_API_KEY"] = "YOUR_API_KEY_HERE" # Replace with your actual API key

Step 3: Perform a basic search query

Python

    from tavily import TavilyClient
    import os

    api_key = os.getenv("TAVILY_API_KEY")
    tavily_client = TavilyClient(api_key=api_key)

    query = "Who is Leo Messi?"
    response = tavily_client.search(query)

    for result in response['results']:
        print(result['title'])
        print(result['content'])

Step 4: Explore advanced search options

Python

    response_with_images = tavily_client.search(query="Who is Leo Messi?", include_images=True)
    for image in response_with_images['images']:
        print(image)

API Parameters

The Tavily Search API offers several parameters to customize search queries:

Search Parameters:

  • query (required): The search query string.
  • search_depth: Depth of search ("basic" or "advanced"). Default is "basic".
  • topic: Category of search ("general" or "news"). Default is "general".
  • days: Number of days back to include in "news" searches. Default is 3 days.
  • time_range: Time range to filter results ("day", "week", "month", "year", or "d", "w", "m", "y").
  • max_results: Maximum number of results to return (0-20). Default is 5.
  • include_images: Boolean to include image URLs in the response. Default is False.
  • include_image_descriptions: Boolean to include image descriptions (requires include_images=True). Default is False.
  • include_answer: Boolean or string ("basic" or "advanced") to include an AI-generated answer. Default is False.
  • include_raw_content: Boolean to include parsed HTML content. Default is False.
  • include_domains: List of domains to include in search results.
  • exclude_domains: List of domains to exclude from search results.

Extraction Parameters:

  • urls (required): URL or list of URLs to extract content from (max 20 URLs in a list).
  • include_images: Boolean to include image URLs extracted from webpages. Default is False.
  • extract_depth: Depth of extraction ("basic" or "advanced"). Default is "basic".