Exa Web Search
Semantic web search with Exa AI for intelligent information retrieval
Exa Web Search Tool
Exa is a powerful semantic web search API that provides intelligent search capabilities for AI agents. It supports neural search, content filtering, and real-time web crawling.
Installation
npm install @exalabs/ai-sdkEnvironment Variables
EXA_API_KEY=your-exa-api-keyGet your API key from the Exa Dashboard.
Quick Start
- Simple Usage
typescript import { Agent } from 'praisonai'; import { exaSearch } from 'praisonai/tools'; const agent = new Agent({ name: 'WebResearcher', instructions: 'You are a research assistant that searches the web for information.', tools: [exaSearch()], }); const result = await agent.run('Find the latest AI developments in Europe'); console.log(result.text); - With Configuration
Adjust agent instructions, tool options, and provider settings for production — see the Configuration section below.
Configuration Options
import { exaSearch } from 'praisonai/tools';
const searchTool = exaSearch({
// Search type: auto, neural, fast, deep
type: 'auto',
// Number of results (default: 10)
numResults: 10,
// Category filter
category: 'news', // company, research paper, news, pdf, github, etc.
// Domain filters
includeDomains: ['github.com', 'arxiv.org'],
excludeDomains: ['wikipedia.org'],
// Date filters (ISO 8601)
startPublishedDate: '2024-01-01T00:00:00.000Z',
endPublishedDate: '2024-12-31T23:59:59.999Z',
// Text filters
includeText: ['AI', 'machine learning'],
excludeText: ['spam'],
// Content options
contents: {
text: { maxCharacters: 1000 },
summary: true,
livecrawl: 'fallback', // never, fallback, always, preferred
},
});Search Types
| Type | Description |
|---|---|
auto | Intelligent hybrid search (recommended) |
neural | Semantic/meaning-based search |
fast | Quick keyword-based search |
deep | Comprehensive deep search |
Category Filters
company– Company websitesresearch paper– Academic papersnews– News articlespdf– PDF documentsgithub– GitHub repositoriespersonal site– Personal websiteslinkedin profile– LinkedIn profilesfinancial report– Financial documents
Advanced Example
import { Agent } from 'praisonai';
import { exaSearch } from 'praisonai/tools';
const agent = new Agent({
name: 'CompanyResearcher',
instructions: 'Research companies and provide detailed analysis.',
tools: [
exaSearch({
type: 'auto',
numResults: 6,
category: 'company',
contents: {
text: { maxCharacters: 2000 },
livecrawl: 'preferred',
summary: true,
},
}),
],
});
const result = await agent.run(
'Find AI startups in Europe founded after 2020 with recent funding'
);
console.log(result.text);Using with AI SDK Directly
import { generateText, stepCountIs } from 'ai';
import { webSearch } from '@exalabs/ai-sdk';
import { openai } from '@ai-sdk/openai';
const { text } = await generateText({
model: openai('gpt-4o'),
prompt: 'What are the latest developments in quantum computing?',
tools: {
webSearch: webSearch({
numResults: 5,
type: 'auto',
}),
},
stopWhen: stepCountIs(3),
});
console.log(text);Response Format
interface ExaSearchResult {
results: Array<{
title: string;
url: string;
content: string;
score?: number;
publishedDate?: string;
author?: string;
}>;
autopromptString?: string;
}Best Practices
Guidelines
- Use appropriate search type –
autoworks well for most cases - Filter by category – Narrow results for specific content types
- Set date ranges – Get recent or historical content as needed
- Use livecrawl – Get fresh content when needed
- Limit results – Start with fewer results and increase if needed
Error Handling
import { exaSearch } from 'praisonai/tools';
const tool = exaSearch();
try {
const result = await tool.execute({ query: 'AI news' });
console.log(result);
} catch (error) {
if (error.message.includes('EXA_API_KEY')) {
console.error('Missing API key. Set EXA_API_KEY environment variable.');
} else {
console.error('Search failed:', error.message);
}
}Related Tools
- Tavily Search – Alternative web search
- Perplexity Search – Real-time search with filtering
- Firecrawl – Web scraping and crawling