TavilySearchAPIWrapper#

class langchain_community.utilities.tavily_search.TavilySearchAPIWrapper[source]#

Bases: BaseModel

Wrapper for Tavily Search API.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param tavily_api_key: SecretStr [Required]#
Constraints:
  • type = string

  • writeOnly = True

  • format = password

clean_results(results: List[Dict]) β†’ List[Dict][source]#

Clean results from Tavily Search API.

Parameters:

results (List[Dict]) –

Return type:

List[Dict]

raw_results(query: str, max_results: int | None = 5, search_depth: str | None = 'advanced', include_domains: List[str] | None = [], exclude_domains: List[str] | None = [], include_answer: bool | None = False, include_raw_content: bool | None = False, include_images: bool | None = False) β†’ Dict[source]#
Parameters:
  • query (str) –

  • max_results (int | None) –

  • search_depth (str | None) –

  • include_domains (List[str] | None) –

  • exclude_domains (List[str] | None) –

  • include_answer (bool | None) –

  • include_raw_content (bool | None) –

  • include_images (bool | None) –

Return type:

Dict

async raw_results_async(query: str, max_results: int | None = 5, search_depth: str | None = 'advanced', include_domains: List[str] | None = [], exclude_domains: List[str] | None = [], include_answer: bool | None = False, include_raw_content: bool | None = False, include_images: bool | None = False) β†’ Dict[source]#

Get results from the Tavily Search API asynchronously.

Parameters:
  • query (str) –

  • max_results (int | None) –

  • search_depth (str | None) –

  • include_domains (List[str] | None) –

  • exclude_domains (List[str] | None) –

  • include_answer (bool | None) –

  • include_raw_content (bool | None) –

  • include_images (bool | None) –

Return type:

Dict

results(query: str, max_results: int | None = 5, search_depth: str | None = 'advanced', include_domains: List[str] | None = [], exclude_domains: List[str] | None = [], include_answer: bool | None = False, include_raw_content: bool | None = False, include_images: bool | None = False) β†’ List[Dict][source]#

Run query through Tavily Search and return metadata.

Parameters:
  • query (str) – The query to search for.

  • max_results (int | None) – The maximum number of results to return.

  • search_depth (str | None) – The depth of the search. Can be β€œbasic” or β€œadvanced”.

  • include_domains (List[str] | None) – A list of domains to include in the search.

  • exclude_domains (List[str] | None) – A list of domains to exclude from the search.

  • include_answer (bool | None) – Whether to include the answer in the results.

  • include_raw_content (bool | None) – Whether to include the raw content in the results.

  • include_images (bool | None) – Whether to include images in the results.

Returns:

The query that was searched for. follow_up_questions: A list of follow up questions. response_time: The response time of the query. answer: The answer to the query. images: A list of images. results: A list of dictionaries containing the results:

title: The title of the result. url: The url of the result. content: The content of the result. score: The score of the result. raw_content: The raw content of the result.

Return type:

query

async results_async(query: str, max_results: int | None = 5, search_depth: str | None = 'advanced', include_domains: List[str] | None = [], exclude_domains: List[str] | None = [], include_answer: bool | None = False, include_raw_content: bool | None = False, include_images: bool | None = False) β†’ List[Dict][source]#
Parameters:
  • query (str) –

  • max_results (int | None) –

  • search_depth (str | None) –

  • include_domains (List[str] | None) –

  • exclude_domains (List[str] | None) –

  • include_answer (bool | None) –

  • include_raw_content (bool | None) –

  • include_images (bool | None) –

Return type:

List[Dict]