Skip to main content

Tavily Search API

Tavily's Search API is a search engine built specifically for AI agents (LLMs), delivering real-time, accurate, and factual results at speed.

Usage

npm install @langchain/community

You will need to populate a TAVILY_API_KEY environment variable with your Tavily API key or pass it into the constructor as apiKey.

For a full list of allowed arguments, see the official documentation. You can also pass any param to the SDK via a kwargs object.

import { TavilySearchAPIRetriever } from "@langchain/community/retrievers/tavily_search_api";

const retriever = new TavilySearchAPIRetriever({
k: 3,
});

const retrievedDocs = await retriever.invoke(
"What did the speaker say about Justice Breyer in the 2022 State of the Union?"
);
console.log({ retrievedDocs });

/*
{
retrievedDocs: [
Document {
pageContent: `Shy Justice Br eyer. During his remarks, the president paid tribute to retiring Supreme Court Justice Stephen Breyer. "Tonight, I'd like to honor someone who dedicated his life to...`,
metadata: [Object]
},
Document {
pageContent: 'Fact Check. Ukraine. 56 Posts. Sort by. 10:16 p.m. ET, March 1, 2022. Biden recognized outgoing Supreme Court Justice Breyer during his speech. President Biden recognized outgoing...',
metadata: [Object]
},
Document {
pageContent: `In his State of the Union address on March 1, Biden thanked Breyer for his service. "I'd like to honor someone who has dedicated his life to serve this country: Justice Breyer — an Army...`,
metadata: [Object]
}
]
}
*/

API Reference:


Was this page helpful?


You can leave detailed feedback on GitHub.