spectrawl icon indicating copy to clipboard operation
spectrawl copied to clipboard

feat: add Exa AI-powered search tool

Open tgonzalezc5 opened this issue 7 months ago • 0 comments

Summary

Adds Exa as an additional search provider in the cascade, alongside the existing nine engines. Exa is an AI-native search engine that returns clean, agent-ready results with built-in content retrieval (highlights, text, summaries), neural search, and rich filtering (category, domains, dates, user location).

  • New src/search/engines/exa.js following the same https-based pattern as tavily.js, brave.js, and serper.js
  • Registered under the exa key in the ENGINES cascade registry
  • Reads EXA_API_KEY from env (or config.exa.apiKey)
  • Defaults to type: 'auto' with contents: { highlights: true, text: { maxCharacters: 1000 } } so results land in the same snippet-sized shape the cascade already expects — configurable per-call
  • Forwards category, includeDomains / excludeDomains, startPublishedDate / endPublishedDate, startCrawlDate / endCrawlDate, and userLocation
  • Snippet extraction cascades through highlights → summary → text so any combination of contents options produces a usable result
  • TypeScript typings added for config.search.exa
  • README updated: engines table row and env var reference

Usage

const { Spectrawl } = require('spectrawl')

const web = new Spectrawl({
  search: {
    cascade: ['gemini-grounded', 'exa', 'tavily'],
    exa: { type: 'neural', category: 'research paper' }
  }
})

const result = await web.deepSearch('transformer architectures for long context')
console.log(result.sources)

Set EXA_API_KEY in your environment (1,000 free searches/month, get a key at https://dashboard.exa.ai).

Files changed

  • src/search/engines/exa.js — new engine
  • src/search/index.js — register exa in the cascade
  • index.d.ts — add exa config typings
  • README.md — engines table + env var
  • test/exa.test.js — 10 unit tests covering the engine end-to-end

Test plan

  • [x] Added unit tests for exaSearch covering:
    • Missing EXA_API_KEY → throws
    • API response → cascade result shape mapping
    • x-api-key and x-exa-integration headers on the outgoing request
    • Default request body (type: 'auto', numResults: 10, contents shape)
    • Filter forwarding: type, maxResults, category, includeDomains, excludeDomains, startPublishedDate, endPublishedDate, userLocation
    • contents: false disables the contents object
    • Custom contents object overrides the default
    • Snippet fallback: highlights → summary → text → empty string
    • Non-results payload → descriptive error
    • Registry integration via new SearchEngine({ cascade: ['exa'] })
  • [x] node --test test/exa.test.js — 10 / 10 pass
  • [x] node --test test/exa.test.js test/search.test.js test/config.test.js — 18 / 18 pass (no regressions in existing search tests)
  • [ ] Live end-to-end run against api.exa.ai (requires an EXA_API_KEY; not run in this environment)

tgonzalezc5 avatar Apr 21 '26 12:04 tgonzalezc5