|
| 1 | +# `@langchain/tavily` |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/@langchain/tavily) |
| 4 | + |
| 5 | +This package provides integrations for the [Tavily](https://tavily.com/) 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. |
| 6 | + |
| 7 | +This package exposes two tools: |
| 8 | +- `TavilySearch`: Performs a search optimized for LLMs and RAG. |
| 9 | +- `TavilyExtract`: Extracts raw content from a list of URLs. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +```bash |
| 14 | +npm install @langchain/tavily |
| 15 | +``` |
| 16 | + |
| 17 | +## Setup |
| 18 | + |
| 19 | +You need a Tavily API key to use these tools. You can get one [here](https://app.tavily.com). Set it as an environment variable: |
| 20 | + |
| 21 | +```typescript |
| 22 | +process.env.TAVILY_API_KEY = "YOUR_API_KEY"; |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +### TavilySearch |
| 28 | + |
| 29 | +```typescript |
| 30 | +import { TavilySearch } from "@langchain/tavily"; |
| 31 | + |
| 32 | +const tool = new TavilySearch({ |
| 33 | + maxResults: 5, |
| 34 | + // You can set other constructor parameters here, e.g.: |
| 35 | + // topic: "general", |
| 36 | + // includeAnswer: false, |
| 37 | + // includeRawContent: false, |
| 38 | + // includeImages: false, |
| 39 | + // searchDepth: "basic", |
| 40 | +}); |
| 41 | + |
| 42 | +// Invoke with a query |
| 43 | +const results = await tool.invoke({ |
| 44 | + query: "what is the current weather in SF?" |
| 45 | +}); |
| 46 | + |
| 47 | +console.log(results); |
| 48 | +``` |
| 49 | + |
| 50 | +### TavilyExtract |
| 51 | + |
| 52 | +```typescript |
| 53 | +import { TavilyExtract } from "@langchain/tavily"; |
| 54 | + |
| 55 | +const tool = new TavilyExtract({ |
| 56 | + // Constructor parameters: |
| 57 | + // extractDepth: "basic", |
| 58 | + // includeImages: false, |
| 59 | +}); |
| 60 | + |
| 61 | +// Invoke with a list of URLs |
| 62 | +const results = await tool.invoke({ |
| 63 | + urls: ["https://en.wikipedia.org/wiki/Lionel_Messi"] |
| 64 | +}); |
| 65 | + |
| 66 | +console.log(results); |
| 67 | +``` |
| 68 | + |
| 69 | +## Documentation |
| 70 | + |
| 71 | +For more detailed information, check out the documentation pages: |
| 72 | + |
| 73 | +- **TavilySearch**: [http://js.langchain.com/docs/integrations/tools/tavily_search/](http://js.langchain.com/docs/integrations/tools/tavily_search/) |
| 74 | +- **TavilyExtract**: [http://js.langchain.com/docs/integrations/tools/tavily_extract/](http://js.langchain.com/docs/integrations/tools/tavily_extract/) |
| 75 | + |
| 76 | +## License |
| 77 | + |
| 78 | +This package is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
0 commit comments