@langchain/tavily
v1.2.0
Published
Tavily integration for LangChain.js
Maintainers
Keywords
Readme
@langchain/tavily
This package provides integrations for the Tavily search engine within LangChain.js. Tavily is a search engine built specifically for AI agents (LLMs), delivering real-time, accurate, and factual results at speed.
This package exposes four tools:
TavilySearch: Performs a search optimized for LLMs and RAG.TavilyExtract: Extracts raw content from a list of URLs.TavilyCrawl: Initiates a structured web crawl starting from a specified base URL.TavilyMap: Generates a site map starting from a specified base URL.TavilyResearch: Creates structured research tasks and optionally streams research output.TavilyGetResearch: Retrieves research results byrequest_idfor previously created research tasks.
Installation
npm install @langchain/tavilySetup
You need a Tavily API key to use these tools. You can get one here. Set it as an environment variable:
process.env.TAVILY_API_KEY = "YOUR_API_KEY";Usage
TavilySearch
import { TavilySearch } from "@langchain/tavily";
const tool = new TavilySearch({
maxResults: 5,
// You can set other constructor parameters here, e.g.:
// topic: "general",
// includeAnswer: false,
// includeRawContent: false,
// includeImages: false,
// searchDepth: "basic",
});
// Invoke with a query
const results = await tool.invoke({
query: "what is the current weather in SF?",
});
console.log(results);TavilyExtract
import { TavilyExtract } from "@langchain/tavily";
const tool = new TavilyExtract({
// Constructor parameters:
// extractDepth: "basic",
// includeImages: false,
});
// Invoke with a list of URLs
const results = await tool.invoke({
urls: ["https://en.wikipedia.org/wiki/Lionel_Messi"],
});
console.log(results);TavilyResearch
import { TavilyResearch } from "@langchain/tavily";
const tool = new TavilyResearch({
// Optional constructor defaults:
// model: "auto",
// stream: false,
// citationFormat: "numbered",
// apiBaseUrl: "https://api.tavily.com",
});
// Invoke with a research task
const result = await tool.invoke({
input: "Research the latest developments in AI",
model: "mini",
citationFormat: "apa",
});
console.log(result);TavilyGetResearch
import { TavilyGetResearch } from "@langchain/tavily";
const tool = new TavilyGetResearch({
// Optional constructor parameters:
// apiBaseUrl: "https://api.tavily.com",
});
// Invoke with a request_id returned from TavilyResearch
const result = await tool.invoke({
requestId: "your-request-id-here",
});
console.log(result);TavilyCrawl
import { TavilyCrawl } from "@langchain/tavily";
const tool = new TavilyCrawl({
// Constructor parameters:
// extractDepth: "basic",
// format: "markdown",
// maxDepth: 3,
// maxBreadth: 50,
// limit: 100,
// includeImages: false,
// allowExternal: false,
});
// Invoke with a URL and optional parameters
const results = await tool.invoke({
url: "https://docs.tavily.com/",
instructions: "Find information about the LangChain integration.",
});
console.log(results);TavilyMap
import { TavilyMap } from "@langchain/tavily";
const tool = new TavilyMap({
// Constructor parameters:
// maxDepth: 3,
// maxBreadth: 50,
// limit: 100,
// allowExternal: false,
});
// Invoke with a URL and optional parameters
const results = await tool.invoke({
url: "https://docs.tavily.com/",
});
console.log(results);Documentation
For more detailed information, check out the documentation pages:
- TavilySearch: http://js.langchain.com/docs/integrations/tools/tavily_search/
- TavilyExtract: http://js.langchain.com/docs/integrations/tools/tavily_extract/
- TavilyCrawl: http://js.langchain.com/docs/integrations/tools/tavily_crawl/
- TavilyMap: http://js.langchain.com/docs/integrations/tools/tavily_map/
License
This package is licensed under the MIT License. See the LICENSE file for details.
