Skip to Content

Semantic (meaning-based) search of a mailbox.

Finds the messages whose MEANING is closest to the query, ranked by similarity — 'the invoice from the Berlin supplier' finds it whether or not those words appear. Hybrid by default: the lexical BM25 ranking is fused in by reciprocal rank, which is what makes exact identifiers (invoice numbers, names) findable too. Requires the mailbox to have semantic search enabled (PATCH /identities/:id { semantic: true }). Bounded at the 100 most relevant candidates before filtering: this is 'the most relevant', never 'every match ranked' — deep paging is /search's job. Results are the same MessageMeta rows /search returns.

openemail.search.semantic(
  mailboxId: string,
  options: SearchSemanticOptions,
): PagePromise<SemanticSearchResult, MessageMeta>

It calls GET /mailboxes/{mailboxId}/search/semantic: Semantic (meaning-based) search of a mailbox in the API reference.

Example

for await (const messageMeta of openemail.search.semantic(mailboxId, { q: '…' })) {
  // every item of every page (await the call instead for one page)
}

Arguments

ArgumentTypeDescription
mailboxIdstringMailbox ULID identifier. The path's {mailboxId}.

Options

The last argument, options, takes:

OptionTypeSent asDescription
qstringquery qRequired. The query, in natural language
limitnumberquery limitMaximum messages to return (default 25, max 100)
cursorstringquery cursorPagination cursor for the next page — an offset into the re-issued query's list
sincenumberquery sinceOnly mail received at or after this epoch second (an ANN pre-filter, cheap)
beforenumberquery beforeOnly mail received before this epoch second
labelstringquery labelRestrict to one label or folder. A POST-filter over a candidate list bounded at 100, so it forces hybrid fusion and the answer carries scoped: candidate-bounded
fuse('lexical' | 'none')query fuselexical (default) fuses the BM25 ranking in — hybrid; none answers the semantic ranking alone (ignored when label is given)
snippetbooleanquery snippetWhether to include highlighted excerpts

Every call also takes signal, timeout, retry and headers, which say how that one call is sent (call options).

Answer

It is a listing, a PagePromise. Awaited, it is one page as the API answers it, SemanticSearchResult. Iterated with for await, it is every MessageMeta of every page, each page fetched as the loop reaches it.

Errors

StatusWhat it means
400validation_failed, empty_query, or invalid_cursor
401unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a WWW-Authenticate: Bearer challenge
404Mailbox not found, not accessible to this principal, or the caller is a folder-scoped viewer
409semantic_not_enabled — the mailbox has not opted in, or its account lacks the plan gate
429rate_limited — the credential's semantic-search budget; Retry-After carries the wait
503semantic_unavailable — a transient model or index fault; Retry-After carries the wait. Or semantic_misconfigured — a permanent refusal or an unconfigured shard, with NO Retry-After: retrying never resolves it, an operator does. Or temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description)

A failed call rejects with a RequestError: its status, and its code, the API's error. Decide on the code: one status covers several.

Types

It names these types of the API, each on a page of its own: MessageMeta, SemanticSearchResult.