exa-ruby

Ruby client for the Exa.ai API. Search and analyze web content using neural search, question answering, code discovery, and research automation.

Installation

Add to your Gemfile:

ruby gem 'exa-ai'

Then run:

bash bundle install

Or install directly:

bash gem install exa-ai

Configuration

Get your API key from dashboard.exa.ai.

Environment Variable (recommended)

bash export EXA_API_KEY="your-api-key-here"

Ruby Code

```ruby require ‘exa-ai’

Exa.configure do |config| config.api_key = “your-api-key-here” end

Or pass directly to client

client = Exa::Client.new(api_key: “your-api-key-here”) ```

CLI Flag

bash exa-ai search "query" --api-key YOUR_API_KEY

Quick Start

Ruby API

```ruby require ‘exa-ai’

Exa.configure do |config| config.api_key = ENV[‘EXA_API_KEY’] end

client = Exa::Client.new

Search the web

results = client.search(“Ruby programming language”) results.results.each { |item| puts “#item[‘title’]: #item[‘url’]” }

Find similar content

similar = client.find_similar(“https://arxiv.org/abs/2307.06435”) similar.results.each { |item| puts item[‘url’] }

Get an answer to a question

answer = client.answer(“What is machine learning?”) puts answer.answer

Find code examples

code = client.context(“React hooks”) puts code.response

Get page contents

contents = client.get_contents([“https://ruby-lang.org”]) puts contents.results.first[“text”] ```

Command Line

```bash # Core Search Commands exa-ai search “Ruby programming language” exa-ai find-similar “https://arxiv.org/abs/2307.06435” exa-ai answer “What is machine learning?” exa-ai context “React hooks” –tokens-num 5000 exa-ai get-contents “https://ruby-lang.org”

Research Commands

exa-ai research-start –instructions “What species of ant are similar to honeypot ants?” exa-ai research-get RESEARCH_ID exa-ai research-list

Webset Management

exa-ai webset-create –search ‘companies”,”count”:1’ exa-ai webset-list –limit 5 exa-ai webset-get WEBSET_ID exa-ai webset-update WEBSET_ID –metadata ‘“updated”:”true”,”version”:”2”’ exa-ai webset-delete WEBSET_ID –force exa-ai webset-cancel WEBSET_ID

Webset Searches

exa-ai webset-search-create WEBSET_ID –query “Ford Mustang” –entity custom –entity-description “vintage cars” exa-ai webset-search-create WEBSET_ID –query “tech CEOs” –entity person –count 20 exa-ai webset-search-create WEBSET_ID –query “Y Combinator startups” –entity company exa-ai webset-search-get WEBSET_ID SEARCH_ID exa-ai webset-search-cancel WEBSET_ID SEARCH_ID

Webset Items

exa-ai webset-item-list WEBSET_ID exa-ai webset-item-get WEBSET_ID ITEM_ID exa-ai webset-item-delete WEBSET_ID ITEM_ID –force

Enrichments

exa-ai enrichment-create WEBSET_ID –description “Find company email” –format text exa-ai enrichment-create WEBSET_ID –description “Company size category” –format options –options ‘[(1-10)”,(11-50)”,(51+)”]’ exa-ai enrichment-list WEBSET_ID exa-ai enrichment-get WEBSET_ID ENRICHMENT_ID exa-ai enrichment-update WEBSET_ID ENRICHMENT_ID –description “Updated description” exa-ai enrichment-delete WEBSET_ID ENRICHMENT_ID –force exa-ai enrichment-cancel WEBSET_ID ENRICHMENT_ID

Webset Imports

exa-ai webset-import-create companies.csv –count 100 –title “My Companies” –format csv –entity-type company exa-ai webset-import-create data.csv –count 50 –title “Tech Startups” –format csv –entity-type company –csv-identifier 0 exa-ai webset-import-create import.csv –count 100 –title “Import” –format csv –entity-type company –metadata ‘“source”:”crm”’ –quiet exa-ai webset-import-list exa-ai webset-import-get IMPORT_ID exa-ai webset-import-update IMPORT_ID –title “Updated Title” exa-ai webset-import-delete IMPORT_ID ```

Features

The gem provides complete access to Exa’s API endpoints:

  • Search — Neural and keyword search across billions of web pages
  • Find Similar — Discover content similar to a given URL
  • Answer — Generate comprehensive answers with source citations
  • Context — Find relevant code and documentation snippets
  • Get Contents — Extract full text content from web pages

Research

  • Research Tasks — Start and manage long-running research tasks with AI
  • Task Management — Get status updates and list all research tasks

Websets

  • Webset Management — Create, update, delete, and list datasets of web pages
  • Webset Searches — Run searches within websets and manage search tasks
  • Webset Items — List, retrieve, and manage individual items in websets
  • Enrichments — Create and manage AI-powered data enrichment tasks on websets
  • Imports — Upload CSV files to import external data into websets

Error Handling

```ruby require ‘exa-ai’

client = Exa::Client.new(api_key: “your-key”)

begin results = client.search(“test”) rescue Exa::Unauthorized => e puts “Invalid API key: #ee.message” rescue Exa::TooManyRequests => e puts “Rate limited, please retry” rescue Exa::ServerError => e puts “Server error: #ee.message” end ```

Documentation

Development

See CONTRIBUTING.md for: - Running tests - Development setup - Code conventions - Building and releasing

Support

  • Documentation: https://docs.exa.ai
  • Dashboard: https://dashboard.exa.ai
  • Status: https://status.exa.ai

License

MIT License - See LICENSE file for details


Built with Exa.ai — The search and discovery API