Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Running rhypedb

This page covers running and operating a rhypedb-server in practice: configuration, the data directory, authentication, hot reload, compaction, and monitoring.

Upgrading

Opening a database with a release that changes what an analyzer does rebuilds every @fulltext index in the background, into a fresh generation. .matches on a field reports it as still building until its rebuild finishes (GET /status shows the progress); everything else, including writes, is unaffected, and nothing is lost. The 0.1 release that added the per-value word cap (simple/2, english/3) is such a change, so plan for search on a large corpus to be briefly unavailable after that upgrade.

The release that shortened full-text index keys (GH #98) rebuilds every @fulltext index once in the same way, on its first open of a database whose indexes an earlier release built. The new keys take roughly 25 bytes less per indexed word of each document, so the index takes about a third less space. Opening that database with an earlier release afterwards, even before the rebuild has finished, rebuilds the indexes again in the earlier form, and the newer release rebuilds them back on its next open, removing the rows the earlier release left. Results are the same throughout. One case leaves rows behind: if you remove a field's @fulltext directive while running the earlier release, that field's newer-form rows stay on disk (unused) until the directive is added back.

A schema that uses @indexed(cover: false) can't be opened by a release older than that parameter: its schema parser rejects it. Remove the parameter, and open the database once with the newer release, before you downgrade.

Starting the server

rhypedb-server --schema schema.rhype --data-dir /var/lib/rhypedb

Command-line flags

FlagDefaultMeaning
-s, --schema <path>(required, except with --restore-from)Path to the SDL schema file. Optional when restoring (the snapshot carries its own authoritative schema).
-d, --data-dir <path>./rhypedb-dataStorage directory (created if absent).
--restore-from <dir>offRestore a physical backup snapshot into --data-dir before serving (see Restore on boot). Idempotent.
--restore-forceoffAllow --restore-from to overwrite an existing, different database in --data-dir.
--listen <addr>127.0.0.1:4200HTTP listen address.
--tcp-listen <addr>127.0.0.1:4201Binary TCP listen address.
--no-syncoffSkip the WAL fsync at commit. Faster, but a power loss can drop the last few writes. Equivalent to Postgres fsync=off. Don't use in production.

Environment variables

VariableMeaning
RHYPEDB_ADMIN_TOKENBearer token that gates all /admin/* endpoints. If unset, admin routes return 403.
RHYPEDB_EFDefault HNSW search width (ef) for .similar queries that omit ef: (must be ≥ 1; overridable per query). An invalid value is ignored with a warning.
RHYPEDB_RERANKDefault rerank pool size for .similar queries that omit rerank: (0 = off; overridable per query). An invalid value is ignored with a warning.
RHYPEDB_RESTORE_FROMSnapshot directory to restore on boot (same as --restore-from; the flag wins if both are set).
RHYPEDB_RESTORE_FROM_FORCE1/true/yes/on ⇒ same as --restore-force.
RHYPEDB_CONFIGPath to a TOML config file (same as --config; the flag wins if both are set).
RHYPEDB_BLOCK_COMPRESSIONnone (default) or lz4 — per-block SST compression for new files (same as --block-compression).

Configuration file

Instead of (or alongside) flags and env vars, point the server at a TOML config file with --config <path> or RHYPEDB_CONFIG. There is no auto-discovery — the file is loaded only from the explicit path.

Precedence (most-specific wins):

CLI flag  >  env var  >  config file  >  built-in default

So a config file is a fallback layer: anything you also pass as a flag or env var overrides it, and with no --config the server behaves exactly as before.

The keys map one-to-one to the flags/env vars (flat, snake_case):

KeyTypeDefaultEquivalent flag / env
schemapath(required unless restore_from)--schema
data_dirpath./rhypedb-data--data-dir
listenstring127.0.0.1:4200--listen
tcp_listenstring127.0.0.1:4201--tcp-listen
no_syncboolfalse--no-sync
admin_tokenstring(unset → admin off)RHYPEDB_ADMIN_TOKEN
efint ≥ 1(heuristic)RHYPEDB_EF
rerankint (0 = off)offRHYPEDB_RERANK
restore_frompath(off)--restore-from
restore_from_forceboolfalse--restore-force
cache_max_entriesint ≥ 1256(file only)
graceful_drain_secsint ≥ 120(file only)
worker_quiesce_budget_secsint ≥ 110(file only)
block_compression"none" | "lz4""none"--block-compression / RHYPEDB_BLOCK_COMPRESSION

Background embedding pipeline. A [vectorizer] TABLE (not a flat key) tunes the embed worker used by @vectorize fields: batch_size, max_length, intra_threads, quantized, cpu_arena, cache_dir, plus cross_encoder ("off", the default, or a reranker model name) to turn on cross-encoder reranking of .similar text search and its knobs rerank_candidates, reranker_dir, reranker_fp32 — all optional, config-file only, no flag/env in this version. See Embedding pipeline settings for defaults and what each knob costs.

SST block compression. block_compression controls how newly written SST files (memtable flushes and compactions) store their data region. "none" (the default) keeps the uncompressed layout, whose reads are zero-copy views into the memory-mapped file. "lz4" compresses each ~16-entry block with LZ4 — roughly 3.8× smaller files, so more of the working set fits in the OS page cache — but it is opt-in because a benchmark showed it costs ~3.7× on a 1M-row multi-hop graph traversal: each scattered cover-blob read decompresses a whole block to pull a single entry, which doesn't amortize the way a sequential scan does. Turn "lz4" on where disk size / cold-cache density matters and reads are scan-heavy or rare (range/filter scans amortize the block decompress well); keep "none" for point-lookup- and traversal-heavy workloads. Both formats are always readable regardless of this setting — it only affects new writes — so a data directory can hold a mix, and changing the value lets natural compaction migrate files to the new format over time (no offline rewrite needed). An unrecognized value is warned about and ignored (falls back to the lower layer / the default).

Validation. A typo'd or unknown key, invalid TOML, a wrong-typed value (e.g. ef = "x"), or an unreadable --config path is a fatal startup error (exit 1) that names the file. Out-of-range tuning values (ef/rerank/cache/drain below their minimum) are warned about and ignored — they fall back to the lower layer or the default, so a fat-fingered tuning hint never bricks an unattended start. The boolean flags (--no-sync, --restore-force) can only force a value on; to keep one off, leave it unset everywhere.

Relative paths (schema, data_dir, restore_from) resolve against the server's current working directory, not the config file's location — prefer absolute paths in a config file. The effective resolved config is logged at startup (the admin_token is never printed — only whether admin is enabled). Keep any config file containing admin_token out of version control. A commented example with every key and its default ships at docs/examples/rhypedb.toml.

Restore on boot

For a managed deployment (where the platform controls the instance lifecycle and fetches backups from object storage), the server can restore a physical backup snapshot into its --data-dir at startup, before it opens the database or binds a listener, then serve normally:

rhypedb-server --restore-from /restore/snapshot --data-dir /var/lib/rhypedb

The typical scale-to-zero wake flow is: the platform stops the instance (a clean SIGTERM flushes the memtable and saves the HNSW snapshots), fetches a backup from object storage to a local path, and starts the server pointed at it.

What it does, in order: validate the snapshot's MANIFEST.json (a typo'd or incomplete source is refused before anything is cleared) → take the single-writer data-dir lock → clear stale LSM data → copy the SSTs, WAL, schema.rhype, and the hnsw_*.bin index snapshots → open and serve.

Key points:

  • The snapshot's schema wins. A restored data dir carries its own schema.rhype, which is authoritative (the SSTs were written for it). --schema is therefore optional under --restore-from; if you pass it, it must match the snapshot's schema exactly or startup fails.
  • The HNSW snapshots travel with the backup. Restoring the hnsw_*.bin files lets a vector index wake in ~hundreds of ms instead of rebuilding from the LSM (which is multi-second per 100k vectors — see the cold-start benchmark). A missing index snapshot is a warning, not an error (it rebuilds on open).
  • Idempotent. --restore-from records the snapshot identity, so a restart with the same snapshot already in place is a no-op — you can leave RHYPEDB_RESTORE_FROM set across restarts without re-clobbering live data.
  • Overwrite protection. Restoring over an existing, different database requires --restore-force (or RHYPEDB_RESTORE_FROM_FORCE=1). A stale LOCK file from a crashed instance does not count as existing data.
  • Same host only. Like all of rhypedb, the single-writer lock is same-host; the managed platform must guarantee the previous instance is stopped first.

This is the in-server counterpart to the offline rhypedb-cli restore, which remains available for manual use.

The data directory

A data directory is self-contained. After running, /var/lib/rhypedb contains:

EntryWhat it is
sst/LSM-tree sorted-string-table files (the bulk of the data), and MANIFEST, which records the live ones and the ones a compaction superseded (see SST manifest).
wal.logWrite-ahead log for durability between flushes.
wal.log.tmpPresent only briefly: the empty WAL a flush writes before renaming it over wal.log. One left by a failed flush or a crash is removed at the next open; older releases ignore it.
schema.rhypeThe schema (written here by restore/import; the server otherwise reads --schema).
hnsw_<field>.binPersisted HNSW vector index, one per indexed Vector field. Rebuilt from the raw vectors if missing or stale.
LOCKThe single-writer advisory lock (see below). It also carries the token that tells the SST manifest whether anything else has opened the directory since it was written.

One writer per data directory

A data directory must be opened by one process at a time. Two writers on one directory would corrupt the LSM, so on open the server takes an advisory lock (flock) on the LOCK file, held for the lifetime of the process and released automatically when it exits.

If you try to start a second server — or run an offline tool like rhypedb-import or restore — against a directory that's already in use, it fails fast:

data directory is locked: /var/lib/rhypedb/LOCK is locked (held by pid 1234 on host db-1). Stop the server or other tool using this data directory before opening it.

This is a same-host guard. It does not make it safe to point two machines at the same shared/network-mounted directory — never do that. (On a network filesystem the lock may not engage at all; in that case rhypedb still detects a second opener at the next write and halts loudly rather than corrupting data, but the supported model is one host, one local data directory.)

SST manifest

sst/MANIFEST lists the live SSTs in read order and, as obsolete, every SST a flush or compaction superseded whose delete has not been seen to succeed (a compaction's inputs can outlive it on disk: a platform may refuse to delete a file a reader still has mapped, or the process may stop between the swap and the deletes). An obsolete SST is never loaded again: after a compaction that dropped a delete marker, loading it would bring the deleted rows back. It is deleted at the next opportunity, and at the next open.

On open, rhypedb compares the token the manifest was written under with the one LOCK carries. Every open by a release with the manifest carries that token forward. An opener that does not (an older release, or a copy of the directory made without LOCK) breaks it, and the next open treats the manifest as possibly stale. A restore made with this release's rhypedb restore is safe: it removes sst/MANIFEST and carries the token forward, so nothing is left to mismatch.

  • No manifest (a directory from a release before it): every *.sst is live, as before, and a manifest is written. Existing data opens unchanged.
  • Tokens match (only this release has opened the directory since): exactly the listed SSTs are loaded. An unlisted *.sst is this release's own unfinished output (its rows are still in the WAL, or in the SSTs it was merging) and is deleted. A listed SST that is missing was lost outside rhypedb, and open fails rather than drop its rows (see below).
  • Tokens differ (something else may have changed the directory): every SST the manifest does not list as obsolete is kept and loaded, including ones it has never heard of, and a listed SST that is gone is assumed to have been compacted away. An obsolete SST is still deleted, provided it is still the very file that was listed (same length, modification time and CRC of its last 4 KiB): an older release may have reused its name for new data. See the limits below.

Each decision other than a routine delete is logged to stderr, with lines starting rhypedb: the SST manifest in ….

Rolling back and forward. You can roll back to a release from before the manifest and forward again, any number of times, without manual steps. The older release ignores MANIFEST and loads every *.sst; it never deletes the manifest. On the next open by a newer release the tokens differ, so everything the older release wrote is kept, everything it compacted away is accepted as gone, and SSTs the newer release had superseded are still deleted. One caveat belongs to the older release itself: an obsolete SST that was still on disk when you rolled back is live to it, exactly as after the same interruption of its own compaction. Obsolete SSTs are deleted as soon as possible, so one is left only when a delete was refused or the process stopped right after a compaction; the open-time log and sst/MANIFEST (obsolete lines) show any that remain.

Copying a data directory. Copy it whole, with LOCK, preserving modification times (cp -a, rsync -a), or use backups.

Limits of the fingerprint. It relies on a file's length, modification time and tail CRC; it is not a content hash. Two consequences, both outside the supported paths:

  • A copy that drops LOCK and does not preserve modification times can make a superseded file look different from the one listed, so it would be kept and loaded again. That is an unsupported way to copy a data directory.
  • On a filesystem with coarse timestamps (1 to 2 seconds), a file that reuses a superseded file's name with the same length and tail bytes, within one timestamp tick of it, could in theory be mistaken for the superseded file and deleted. This is unlikely: an older release reuses a name only after the directory has been emptied of higher numbers, which takes a restart.

Restoring with an older rhypedb. A v0.2.x restore ignores errors when it clears sst/ and does not touch LOCK. After restoring with an old binary or CLI, before starting the new binary make sure sst/ holds only the restored files and no sst/MANIFEST remains (or, with the server stopped, delete LOCK). Otherwise a leftover MANIFEST whose token still matches LOCK would make the new binary treat the restored SSTs as unlisted and delete them.

Recovery. Open fails, with a message naming the files, in two cases:

  • The manifest is damaged (its checksum or format is wrong). Restore from a backup. Or, with the server stopped, move sst/MANIFEST aside: the next open takes every *.sst as live, as releases before the manifest did. Any SST the damaged manifest listed as obsolete would then be live again and could bring deleted rows back, so prefer a backup if a compaction ran shortly before.
  • A listed live SST is missing while only this release has opened the directory. Its rows are gone from this directory. Restore from a backup. Or, to accept the loss, delete LOCK with the server stopped: the next open treats the manifest as possibly stale, opens with the SSTs that are there (still deleting the obsolete ones), and logs the missing file.

When a flush fails

Every few MB of writes, the memtable (the newest writes, held in memory and in wal.log) is written to a new SST: a flush. If a flush fails, most often because the disk is full, no acknowledged write is lost or hidden:

  • The write whose commit set off the flush was already in wal.log and visible before the flush began, so it succeeds. The failure is logged to stderr, on a line starting rhypedb: a memtable flush in … failed.
  • Until a flush succeeds again, each write first retries it. If the retry fails too, the write fails with that error and changes nothing. Reads keep working and see every acknowledged write.
  • wal.log is not replaced until every row it holds is in an SST, so a restart or crash while the disk is full recovers every acknowledged write from it.
  • Once there is space again (or the I/O fault is fixed), the next write's retry succeeds and writes carry on. No restart is needed.

Authentication

The data-plane endpoints (POST /query, GET /status, GET /health, GET /schema) are open — put them behind your own network boundary or proxy as needed.

The administrative endpoints (/admin/* — migrations, backup, export, compaction, reload) are gated by RHYPEDB_ADMIN_TOKEN:

  • Token unset → admin routes return 403 Forbidden.
  • Token set, request missing/mismatched Authorization: Bearer <token> → 401 Unauthorized.
  • Token set and matched → request proceeds.
curl -s -X POST http://127.0.0.1:4200/admin/compact \
  -H "Authorization: Bearer $RHYPEDB_ADMIN_TOKEN"

The CLI reads the token from --admin-token or the RHYPEDB_ADMIN_TOKEN environment variable.

Hot schema reload

After you change the schema file, you can apply it without restarting the process:

curl -s -X POST http://127.0.0.1:4200/admin/reload \
  -H "Authorization: Bearer $RHYPEDB_ADMIN_TOKEN" \
  --data-binary @schema.rhype

The server rebuilds its in-memory handle on the same underlying storage and swaps it in atomically — in-flight queries are not interrupted. Reload is refused while an online field-type migration is armed (the migration owns the schema until it finishes). After a change_field_type migration cuts over, the server reloads automatically. See Schema Migrations.

Compaction

rhypedb compacts its LSM automatically in the background. To force a flush + full compaction on demand (an expensive, mutating operation — hence admin-gated):

curl -s -X POST http://127.0.0.1:4200/admin/compact \
  -H "Authorization: Bearer $RHYPEDB_ADMIN_TOKEN"
{ "flush_ok": true, "flush_ms": 50, "compact_ok": true, "compact_ms": 200 }

Opening a large database. Each data file records which object ids it holds, so startup rebuilds its set of live objects from those small records without reading object data. Files written by versions before 2026-11 lack the record. For those files, startup walks their object keys instead, which pages in roughly half of their object bytes on every open. A compaction rewrites them in the current format, after which opens stay fast; one POST /admin/compact (or compact() when embedding) converts an older data directory in one go.

Upgrading relation copies

Reverse relation entries store their linking object's other to-one target ids (see Storage cost of indexes and relations). Versions before 2026-11 could let those ids drift from the links. A database that such a version wrote with links in it opens with "cover_peers_sound": false in GET /status. Queries stay correct, but hops through a to-one relation read the links themselves instead of the stored ids, so they run slower. One rewrite pass repairs the ids and shrinks oversized copies; compact afterwards to reclaim the freed space:

curl -s -X POST http://127.0.0.1:4200/admin/rewrite-covers \
  -H "Authorization: Bearer $RHYPEDB_ADMIN_TOKEN"
curl -s -X POST http://127.0.0.1:4200/admin/compact \
  -H "Authorization: Bearer $RHYPEDB_ADMIN_TOKEN"
{ "ok": true, "ms": 5400, "objects": 120000, "rev_edges_rewritten": 3100, "index_entries_rewritten": 0, "cover_peers_sound": true }

The pass runs in small batches alongside normal traffic and is safe to interrupt and rerun. Once it completes, the database stays marked sound across restarts. Embedded users call Database::rewrite_covers() instead.

Monitoring

  • GET /health — liveness. Returns 200 OK with a short status string.
  • GET /status — operational snapshot: active subscriptions, pending embeddings, per-index vector counts, the embedding model's load state (model_loaded, model_error) and the cross-encoder's own load state (reranker_loaded, reranker_error — always present; both stay false/null while the cross-encoder is off) — see Embedding pipeline settings — and — when the schema has @fulltext fields — a fulltext block: building (fields whose index is still being backfilled), failed (background index tasks that hit an error — the next restart retries them), and per-field indexes entries with state (building / built, or dropping for a field whose directive was removed and whose rows are still being swept), generation, documents (indexed documents), and backfill progress indexed / total.
  • GET /schema — live schema introspection (JSON + canonical SDL) for tooling and typed-client codegen. See the API reference.
curl -s http://127.0.0.1:4200/status
{
  "subscriptions": 2,
  "vectorizer": {
    "pending": 0,
    "indexes": [ { "name": "Post.embedding", "vectors": 12000 } ],
    "model_loaded": true,
    "model_error": null,
    "reranker_loaded": false,
    "reranker_error": null
  }
}

Neither requires authentication, and /status exposes only operational metrics (no data), so it is safe to scrape.

Backups

See Backup & Recovery for taking consistent online backups (physical snapshots and portable logical exports) and restoring them.