Install
Quickstart
new Raily(options)
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | — | The API key for your endpoint. |
endpoint | string | — | Your endpoint URL. |
timeoutMs | number | 60000 | Per-request timeout, in milliseconds. |
search(query, options?)
| Argument | Type | Default | Description |
|---|---|---|---|
query | string | — | What to search for. |
options.limit | number | 3 | Max results (1–10). Fewer may come back. |
options.explain | boolean | false | Resolve to a SearchResult (hits + info) instead of a bare array. |
Promise<SearchHit[]> — or Promise<SearchResult> when explain: true (see
Debugging empty results).
Debugging empty results
A search can legitimately return nothing — and a bare[] doesn’t say why. Pass
{ explain: true } to get the endpoint’s own message plus a hint:
SearchHit
Working with fields
fields is a flat { name: value } map of the display fields configured on your source —
e.g. title, text, author, published_date. Read a value by name:
", ". To see what your source exposes, log
the whole map once:
hit.raw.
Errors
| Error | When | What to do |
|---|---|---|
RailyAuthError | Key missing, invalid, expired, or for a different endpoint. | Check RAILY_API_KEY and that it was issued for this endpoint. |
RailyError | Network, server, or timeout. | Retry with backoff; raise timeoutMs for slow networks. |
RailyAuthError extends RailyError, so check it first.
Concurrency
search returns a promise — fan out with Promise.all:
Recipe: a search route
Troubleshooting
No results came back (empty array)
No results came back (empty array)
An empty array is a valid answer, not an error. The usual causes, in order:
- The query is too generic. Category words like
"articles","news", or"posts"carry no topical signal, so nothing scores above the relevance threshold. Search a specific topic ("battery recycling", not"articles"). - A freshness filter. Queries that imply recency (
"latest","news") apply apublished_datecutoff — on an older corpus that can remove everything. Drop the recency words or widen the range. - The corpus is empty. A brand-new source may have no documents indexed yet. Search a term you know is in the data; if that’s also empty, check ingestion/embedding.
{ explain: true } to see which it is:“API key was rejected for this endpoint” (RailyAuthError)
“API key was rejected for this endpoint” (RailyAuthError)
The key is missing, wrong, expired, or was issued for a different endpoint. A key only
works against the endpoint it was created on. Re-check
RAILY_API_KEY and RAILY_ENDPOINT.Searches are slow or time out
Searches are slow or time out
Raise
timeoutMs and retry. Reuse one client instead of constructing one per request.