Email Search

mails-agent provides three search modes that let your agent find emails by exact keywords, semantic meaning, or a combination of both. All search is scoped to the authenticated mailbox.

Search Modes

Keyword search (FTS5)

Full-text search powered by SQLite FTS5 in Cloudflare D1. Fast, exact matching on subject and body text. Best for finding emails containing specific terms, addresses, or identifiers.

Semantic search (Workers AI + Vectorize)

Embeds the query using Cloudflare Workers AI and searches against pre-computed email embeddings stored in Vectorize. Finds conceptually related emails even when exact keywords differ. For example, searching "payment confirmation" can match an email titled "Your order receipt".

Hybrid search (RRF fusion)

Combines keyword and semantic results using Reciprocal Rank Fusion (RRF). This mode runs both searches in parallel, merges the ranked result lists, and returns a unified ranking. This is the default mode for /v1/search and the recommended mode for most use cases. The /v1/inbox endpoint defaults to keyword mode.

ModeBest forSpeed
keywordExact terms, email addresses, order IDsFastest (~10ms)
semanticConceptual search, natural language queriesFast (~50ms)
hybridGeneral purpose (default)Fast (~60ms)

API Endpoints

GET/v1/inbox?query=xxx&mode=hybrid — Search via inbox endpoint

Add a query parameter to the inbox endpoint to search. The mode parameter selects the search strategy.

Query parameters

ParameterTypeDefaultDescription
querystring-Search query (required for search)
modestringkeywordSearch mode: keyword, semantic, or hybrid. Note: /v1/search defaults to hybrid.
labelstring-Filter by auto-label (see below)
limitnumber20Max results (max 100)
offsetnumber0Pagination offset

Example: Hybrid search

curl -s -H "Authorization: Bearer $API_KEY" \
  "https://mails-worker.genedai.workers.dev/v1/inbox?query=payment%20confirmation&mode=hybrid"
{
  "emails": [
    {
      "id": "msg_xyz789",
      "mailbox": "[email protected]",
      "from_address": "[email protected]",
      "from_name": "Stripe Billing",
      "subject": "Your payment receipt for March",
      "code": null,
      "direction": "inbound",
      "status": "received",
      "received_at": "2026-03-30T08:00:00Z",
      "has_attachments": false,
      "attachment_count": 0
    }
  ],
  "search_mode": "hybrid"
}
GET/v1/search?q=xxx — Dedicated search endpoint

An alias for search that defaults to hybrid mode. The q parameter is equivalent to query.

Example: Keyword-only search

curl -s -H "Authorization: Bearer $API_KEY" \
  "https://mails-worker.genedai.workers.dev/v1/search?q=invoice+INV-2026-001&mode=keyword"

Example: Semantic search

curl -s -H "Authorization: Bearer $API_KEY" \
  "https://mails-worker.genedai.workers.dev/v1/search?q=emails+about+project+deadlines&mode=semantic"

Auto-Labels

Every incoming email is automatically classified into one of four labels using a lightweight rules engine:

LabelDescriptionExamples
newsletterBulk marketing, digests, subscriptionsWeekly digest, product updates, blog roundups
notificationAutomated transactional notificationsOrder confirmations, shipping updates, billing receipts
codeEmails containing verification codes2FA codes, signup verification, password resets
personalHuman-written messagesDirect correspondence, replies, introductions

Filter by label

# Get only verification code emails
curl -s -H "Authorization: Bearer $API_KEY" \
  "https://mails-worker.genedai.workers.dev/v1/inbox?label=code"

# Get only personal emails
curl -s -H "Authorization: Bearer $API_KEY" \
  "https://mails-worker.genedai.workers.dev/v1/inbox?label=personal"

# Combine label filter with search
curl -s -H "Authorization: Bearer $API_KEY" \
  "https://mails-worker.genedai.workers.dev/v1/inbox?query=github&label=notification"

Search Tips