Install
raily:
Quickstart
Raily(...)
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | — | The API key for your endpoint. |
endpoint | str | — | Your endpoint URL. |
timeout | float | 60.0 | Per-request timeout, in seconds. |
search(query, limit=3)
| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | — | What to search for. |
limit | int | 3 | Max results to return (1–10). Fewer may come back. |
explain | bool | False | Return a SearchResult (hits + info) instead of a bare list. |
list[SearchHit] — or a 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
| Field | Type | Description |
|---|---|---|
score | float | None | Relevance score (higher is better). |
fields | dict[str, str] | Your source’s display fields as a flat {name: value} map (see below). |
text | str | None | A rendered text summary, when available. |
image_url | str | None | The result’s image, for image sources (otherwise None). |
is_relevant | bool | None | False for an exploratory hit shown below the relevance threshold. |
source_collection | str | None | The source the result came from. |
id | str | None | Result id, when the source provides one. |
raw | dict | The full original result, for anything not surfaced above. |
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, print
the whole map once:
hit.raw.
Errors
| Exception | 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 timeout for slow networks. |
RailyAuthError is a subclass of RailyError, so catch it first.
Async
AsyncRaily has the same surface with await:
Recipe: a search endpoint with FastAPI
Troubleshooting
No results came back (empty list)
No results came back (empty list)
An empty list 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 the
timeout (seconds) and retry. Reuse one client rather than constructing one
per request.