Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

37.8 KB
Raw Blame
# xerj Default Configuration
# ============================================================
# This file sets 59 of XERJ's 137 user-facing settings to their
# production-ready defaults, and describes the rest in comments.
# Every value here IS the default, so copying this file changes
# nothing until you edit it (a test enforces that). The complete
# set — every one of them optional — is documented in
# crates/xerj-common/src/config.rs.
#
# To use: copy this file to xerj.toml and start the server:
#   xerj --config /path/to/xerj.toml
#
# Doing that gives you an AUTHENTICATED server: [auth] enabled = true
# below is the default. The admin key is auto-generated on first start,
# printed in a banner, and written to <data_dir>/admin.key — and every
# client has to send it, `xerj autoindex` included:
#   export XERJ_API_KEY="$(cat <data_dir>/admin.key)"
#   xerj autoindex <folder>
# For a local dev node with no key at all, skip the config file and run
# `xerj --insecure --data-dir ./data` (that disables TLS *and* auth).
#
# All settings are optional — an empty file is valid and uses
# every default below.
# ============================================================

# ── Network & Data Directory (7 settings) ─────────────────────────────────────

[server]

# Port for the native xerj REST API.
# The native API exposes all engine features including schema evolution,
# vector search, and log ingestion.
rest_port = 8080

# Port for the gRPC API (reserved; protocol not yet finalized).
grpc_port = 8081

# Port for the Elasticsearch-compatible REST API (ES 8.x wire format).
# Point existing ES clients, Kibana, or Logstash here.
es_compat_port = 9200

# Multi-instance opt-in. When true, a taken port makes this node bind the next
# free one (the banner prints the ports actually bound), and a data_dir held by
# another live xerj process makes it use "<data_dir>-2", "-3", ... instead.
# Off by default everywhere: a taken port is a fatal startup error so a client
# pointed at the configured port can never silently reach another instance.
# Also: --auto-port / --no-auto-port, or env XERJ_AUTO_PORT=true|false.
auto_port = false

# Directory where all index data, WAL files, and segments are stored.
# Ensure this path has sufficient disk space and fast I/O.
data_dir = "./data"

# IP address to bind all listeners to. An IPv4 or IPv6 literal — "127.0.0.1",
# "0.0.0.0", "::1". Host names are NOT resolved; a name is refused at startup
# before anything is created, rather than resolving to a different interface on
# every host.
#
# Defaults to loopback: a fresh node is reachable from the machine it runs on
# and nowhere else. TLS is off by default, so a node that bound every interface
# out of the box would put its admin API key and every document body on the
# network in cleartext, and a working curl would give no hint of it.
#
# Set "0.0.0.0" (every interface) or a specific private address to expose the
# node. With tls.enabled = false that also requires
# allow_insecure_network_bind = true below — xerj refuses to start otherwise.
# Overridable without this file: --bind 0.0.0.0 or XERJ_BIND_ADDRESS=0.0.0.0.
bind_address = "127.0.0.1"

# Allow a network-reachable bind_address while TLS is off. Default false,
# which REFUSES TO START in that combination: every listener would serve plain
# HTTP, so the Authorization: ApiKey header of every request crosses the
# network in the clear.
#
# Set true only when something in front of this node terminates TLS — reverse
# proxy, sidecar, service mesh, ingress controller — or when the link itself
# is trusted. Container images set it because the container's own network
# namespace is the boundary; the published port is where you add TLS.
#
# Binding loopback needs no opt-out, and this is ignored when tls.enabled =
# true (there the residual gRPC exposure is allow_insecure_grpc_h2c's job).
# Env: XERJ_ALLOW_INSECURE_NETWORK_BIND=true
allow_insecure_network_bind = false

# Reverse proxies whose X-Forwarded-For / X-Real-IP headers may be believed.
#
# Client identity — the per-IP auth rate-limit bucket and the audit-log source
# address — is taken from the TCP peer, which a caller cannot forge.
# X-Forwarded-For is attacker-controlled and is IGNORED unless the socket peer
# matches an entry here. Default is empty: believe nobody.
#
# If you terminate TLS or load-balance in front of xerj, list that proxy here
# or every user behind it shares one rate-limit bucket. List ONLY proxies you
# operate: anything named here can claim to be any client.
#
# Entries are addresses or CIDR blocks; a bad entry fails startup.
#   trusted_proxies = ["10.0.0.7", "10.1.0.0/16", "::1"]
trusted_proxies = []

# ── Authentication (3 settings) ───────────────────────────────────────────────

[auth]

# Enable API-key authentication on all endpoints.
# When true, every request must carry:
#   Authorization: ApiKey <key>
# On first startup, the admin key is written to <data_dir>/admin.key.
# This is the DEFAULT, so copying this file as-is enables auth. That
# includes the CLI clients: `xerj autoindex` never takes the key from
# this file, so pass `--api-key <key>` or set
# XERJ_API_KEY=$(cat <data_dir>/admin.key), or it fails with 401.
# One exception: against a loopback --url, `xerj autoindex` falls back to
# reading <data_dir>/admin.key itself and prints which file it used. That
# path is relative to the working directory, so a run started from anywhere
# else still needs the key passed explicitly.
# Set to false only in trusted private networks or development environments.
enabled = true

# Static admin API key (leave empty to auto-generate on first run).
# If set, this key is used directly — no file is written.
# WARNING: if you store this in a config file, protect the file with
# filesystem permissions (chmod 600).
admin_api_key = ""

# Optional read-only metrics scrape token (leave empty to disable).
# When set AND auth is enabled, a caller presenting this exact token
# (Authorization: Bearer <token>) may scrape GET /v1/metrics — and ONLY that
# endpoint — without the admin key. Hand this to Prometheus so the scraper has
# a low-privilege credential that can read metrics but not index data.
metrics_token = ""

# ── TLS (4 settings) ──────────────────────────────────────────────────────────

[tls]

# Enable in-process TLS termination on the REST and ES-compat listeners.
# Requires cert_path and key_path to be set when true.
# In production, always enable TLS. In Docker, you may terminate TLS at the
# load balancer or proxy instead.
#
# This does NOT cover the gRPC listener (server.grpc_port): tonic is built
# without its TLS feature, so :8081 speaks cleartext h2c whatever this says.
# See allow_insecure_grpc_h2c below.
enabled = false

# Path to the PEM-encoded X.509 certificate file.
# Use a certificate signed by a trusted CA in production.
cert_path = ""

# Path to the PEM-encoded private key file.
# Permissions should be 600 (owner-readable only).
key_path = ""

# Allow the cleartext h2c gRPC listener on a non-loopback bind_address while
# TLS is enabled. Default false, which REFUSES TO START in that combination:
# enabling TLS reads as "every listener is encrypted", gRPC clients keep
# working either way, so the mismatch would otherwise never surface.
#
# Set true only when something in front of server.grpc_port terminates TLS for
# it — a sidecar, service mesh or reverse proxy — or when the port is on a
# network you trust. Binding loopback (bind_address = "127.0.0.1") needs no
# opt-out. Ignored entirely when enabled = false.
allow_insecure_grpc_h2c = false

# ── Storage & WAL (6 of 11 settings) ──────────────────────────────────────────

[storage]

# WAL fsync strategy. Controls the durability/throughput trade-off.
#
#   "sync"    — fsync before every acknowledgement (one fsync per bulk
#               request — group commit, same granularity as Elasticsearch's
#               per-request translog fsync). Maximum durability; lowest
#               throughput. Use for financial or compliance workloads.
#   "batched" — writes reach the kernel before the ack (process-crash
#               durable); a background loop fsyncs every wal_batch_ms,
#               bounding the power-loss window to wal_batch_ms.
#               Default and recommended for most workloads.
#   "async"   — never fsync; OS decides when to flush. Maximum throughput.
#               Power loss can lose un-flushed data; a process crash alone
#               loses nothing (writes are in the kernel page cache).
wal_sync = "batched"

# How often to fsync the WAL when wal_sync = "batched" (milliseconds).
# Lower values reduce data loss window; higher values increase write throughput.
# Range: 1 – 10000. Default: 100 ms.
wal_batch_ms = 100

# Maximum WAL file size before it is rolled over to a new segment (MiB).
# After a rollover, the old WAL file is retained until a flush checkpoint
# advances past it. Larger values reduce rollover overhead at the cost of
# longer recovery times after a crash.
wal_max_size_mb = 1024

# In-memory buffer size that triggers a segment flush to disk (MiB).
# When the memtable for an index reaches this size, it is flushed to a
# durable on-disk segment. Larger values improve write throughput but
# increase recovery time and memory usage.
flush_size_mb = 512

# Maximum time between flushes, regardless of buffer size (seconds).
# Ensures data is durable even during low-write periods.
flush_interval_secs = 30

# Flush a NON-EMPTY memtable whose contents have not changed for this many
# seconds, regardless of how small it is (0 disables). Without this, a dataset
# that never reaches flush_size_mb stays in memory for the life of the process,
# pins its WAL generations on disk, and replays them on every start — the cost
# is largest when one node holds many small indices, which is exactly what
# `xerj autoindex` produces. Detection rides the flush_interval_secs sweep, so
# worst-case latency is flush_idle_secs + flush_interval_secs and writes pay
# nothing.
flush_idle_secs = 300

# ── Object-store backend (6 settings; all defaults shown) ────────────────────
#
# Issue #965 wires storage.backend = "s3" as a real index backend: each
# flushed segment family is packed into ONE immutable bundle object plus a
# per-index snapshot.json catalogue, merges publish before retiring, and a
# fresh node hydrates families from the bucket on demand. Local stays the
# default — object storage is an opt-in deployment shape, not a tuning knob.
#
# Single-writer v1: one node per index at a time (two writers would clobber
# each other's catalogue). The WAL stays local, bundles are packed in memory
# (single-PUT ceiling), and there is no bucket GC command yet. The contract
# and the unwired remainder: docs/OBJECT_STORAGE.md.
#
# backend = "local"          # "local" (default) or "s3"
# s3_bucket = ""             # required when backend = "s3"; must already
#                            # exist — xerj never creates one
# s3_prefix = "xerj/"        # every key lives under this; each index gets
#                            # its own <prefix>indices/<name>/ namespace
# s3_region = "us-east-1"    # Cloudflare R2 wants the literal "auto"
# s3_endpoint = ""           # "" = AWS S3; "https://<acct>.r2.cloudflarestorage.com"
#                            # for R2, "http://127.0.0.1:9000" for MinIO. When
#                            # set, requests are path-style (<endpoint>/<bucket>/<key>)
# local_cache_dir = "./cache" # DORMANT as of #965: families materialize in
#                            # data_dir/segments; the bounded cache that will
#                            # reuse this path is designed, not shipped

# ── Segment Merging (8 settings) ──────────────────────────────────────────────
#
# Three of these are DORMANT: accepted and validated, but no code path in this
# build reads them. Setting one away from its default logs a warning at startup.
# They are marked below. The merge that runs reads max_segment_mb, tier_floor_mb,
# min_merge_count and max_merge_count, and nothing else.

[merge]

# Merge strategy for combining small segments into larger ones.
#
#   "size_tiered" — merges segments of similar size. Best for write-heavy
#                   workloads with infrequent reads.
#
# Only size_tiered is implemented. "log_structured" is refused at startup rather
# than silently running size-tiered merging.
strategy = "size_tiered"

# DORMANT — nothing reads this. The merge trigger is per-tier and comes from
# min_merge_count below.
# Minimum number of segments that must exist before a merge is triggered.
# Must be >= 2. Default: 10.
min_segments = 10

# Maximum size of a merged segment (MiB). Segments at or above this size are
# never merged again. 8192 MiB = 8 GiB.
max_segment_mb = 8192

# DORMANT — merge I/O is NOT throttled in this build. The rate limiter that
# honours this value is wired only into an unused storage-crate merge executor,
# so setting it buys nothing today.
# I/O rate cap for merge operations (MiB/s).
io_rate_mb_per_sec = 100

# DORMANT — nothing reads this. Merge parallelism comes from the
# XERJ_MERGE_PARALLELISM environment variable, which also defaults to 1.
# Maximum number of concurrent merge operations.
max_concurrent = 1

# Tier boundary base for the size-tiered policy (MiB). Segments group into tiers
# by floor(log2(size / tier_floor_mb)).
tier_floor_mb = 4

# Minimum segments in one tier before that tier is merged.
min_merge_count = 4

# Maximum segments merged per batch. Caps peak merge RAM.
max_merge_count = 16

# ── Compression (3 settings) ──────────────────────────────────────────────────

[compression]

# ACCEPTED BUT NOT WIRED. Every durable artifact xerj writes is a compressed
# envelope — stored (ZBS2), .meta (ZFM4), .post (ZPS1), .dv — and none of them
# has an uncompressed write path; the legacy uncompressed layouts survive only
# so old segments stay readable. Setting this to false logs a warning at
# startup and changes nothing on disk.
enabled = true

# Zstandard effort level, applied when segments are re-encoded AT MERGE.
#
#   "fast"     — Zstd level 1. Fastest encode, loosest ratio.
#   "balanced" — Zstd level 3. Recommended for most workloads.
#   "best"     — Zstd level 6. Tightest measured ratio per byte of decode
#                window. Best for cold storage or archival indexes.
#
# Flush ignores this and always writes level 3. Flush is the back-pressure-
# critical bound on sustained ingest: raising its level to 19 once collapsed
# throughput from 1.55M docs/s to 21k docs/s with 75% of documents rejected
# (reports/2026-04-25T21-50-00_ingest_perf_regression_zstd19.md). Merge runs
# off that path and produces the long-lived segments where footprint matters.
#
# A change therefore takes effect as segments merge, not at restart. To apply
# it to data already on disk, re-merge: POST /{index}/_forcemerge. Segments
# written at different levels coexist — zstd decode does not consult the level
# a payload was written at, so no migration or reindex is needed.
level = "balanced"

# ACCEPTED BUT NOT WIRED. The stored codec is columnar over the whole segment
# section rather than blocked by document count, so there is no doc-block for
# this to size. Still range-checked (16 – 4096) and warned about when moved off
# the default, so a typo fails at startup instead of being ignored.
block_size_docs = 128

# ── Full-Text Search (1 setting) ──────────────────────────────────────────────

[fts]

# Default analyzer applied to `text` fields when no per-field analyzer is set.
#
# Built-in analyzers:
#   "standard"   — Unicode word boundaries + lowercase. Good for most languages.
#   "whitespace" — Split on whitespace only; preserves case.
#   "simple"     — Split on non-letter characters + lowercase.
#   "english"    — Standard + English stemmer + stop-word removal.
#
# Custom analyzers (with tokenizer + filter chains) can be defined at index
# creation time via the mappings API.
#
# NOT WIRED in this build: nothing reads this key. A text field uses its own
# analyzer, else the index's analysis.analyzer.default, else "standard".
# Setting it away from the default logs a warning at startup.
default_analyzer = "standard"

# ── Vector Search / HNSW (6 settings) ─────────────────────────────────────────

[vector]

# Default similarity metric for dense vector fields.
#
#   "cosine"      — Cosine similarity (vectors normalised before indexing).
#                   Best for text embeddings and semantic search.
#   "dot_product" — Raw dot product. Fastest; requires unit-norm vectors.
#   "euclidean"   — L2 (Euclidean) distance. Best for image/audio features.
#
# NOT WIRED in this build: a dense_vector field takes `similarity` from its
# mapping, and a mapping without one gets "cosine" whatever this says.
default_metric = "cosine"

# The three hnsw_* keys are validated but NOT WIRED in this build: the graph
# builds with a fixed M = 16 and ef_construction = 200, and the query-time
# beam width comes from the request's num_candidates (floored at 800).
# Setting any of them away from the default logs a warning at startup.

# HNSW M parameter — number of bi-directional edges per node per layer.
# Higher M → better recall at the cost of more memory and slower index builds.
# Typical range: 8 – 64. Default: 16.
hnsw_m = 16

# HNSW ef_construction — search beam width during index construction.
# Higher values → better recall at the cost of slower inserts.
# Must be >= hnsw_m. Typical range: 100 – 500. Default: 200.
hnsw_ef_construction = 200

# HNSW ef — search beam width at query time.
# Higher values → better recall at the cost of slower queries.
# Must be >= the number of neighbors requested (k).
# Typical range: 50 – 1000. Default: 100.
hnsw_ef_search = 100

# Default quantization scheme for vector index storage.
#
#   "none"    — Full float32 (highest accuracy). The default.
#   "scalar8" — 8-bit scalar quantization: the kNN scan scores from
#               1-byte-per-dimension codes (~1–2% accuracy loss). This buys
#               PRECISION, NOT MEMORY — the scan reads the document's
#               full-precision vector from `_source` and quantizes it per
#               query, so resident memory is unchanged and the field also
#               gives up HNSW-served kNN. See issue #392 before opting in.
#
# "binary" (1-bit) is recognised but NOT implemented in this build — the
# engine rejects it at startup rather than silently storing full-precision
# vectors while claiming a 32× saving. 4-bit ("scalar4") quantization and
# automatic quantization downgrade are not implemented either and have no
# settings here.
#
# NOT WIRED as a node-wide default: only the "binary" refusal reads this key.
# Quantization comes from each field's mapping (index_options.type: int8_hnsw
# or int8_flat); "scalar8" here does not quantize any field.
default_quantization = "none"

# Maximum supported vector dimensionality.
# NOT WIRED in this build: validated (must be >= 1), but no mapping or
# document is checked against it. Setting it away from the default logs a
# warning at startup.
# Common values: 384 (MiniLM), 768 (BERT), 1536 (OpenAI ada-002), 3072 (GPT-4o).
max_dimensions = 16384

# ── Log / Time-Series Retention (2 settings) ──────────────────────────────────

[logs]

# NOT WIRED in this build: nothing reads either key, no retention job runs,
# and log indices are not partitioned by time. Log data is kept until you
# delete it. Setting either key away from its default logs a warning at
# startup.

# How many days to retain log index data before automatic deletion.
# Set to 0 to disable automatic deletion (retain forever).
retention_days = 90

# Time-based partition granularity for log indices.
#
# Valid values: "1m", "5m", "15m", "1h", "6h", "1d"
time_partition = "1h"

# ── External Embedding Service (4 of 19 settings) ─────────────────────────────
#
# NOTE: Token limits are model-specific, not xerj-specific.
#
# xerj delegates embedding generation to the configured external API.
# Ensure your input text fits within the model's token window:
#   - OpenAI text-embedding-ada-002:  8,191 tokens
#   - OpenAI text-embedding-3-small:  8,191 tokens
#   - OpenAI text-embedding-3-large:  8,191 tokens
#   - Ollama nomic-embed-text:        model-dependent (typically 2,048–8,192)
#
# The xerj-ai chunker automatically splits long documents into windows that fit
# the model's token limit before calling the embedding API.

[embedding]

# OpenAI-compatible embeddings URL. Leave empty to disable automatic
# embedding (vectors must be provided by the client). Accepted forms,
# trailing slash optional (#2355):
#   - a base ending in /v1 — /embeddings is appended
#       "http://localhost:8000/v1"  →  http://localhost:8000/v1/embeddings
#   - a bare host — /embeddings is appended
#       "http://localhost:8000"     →  http://localhost:8000/embeddings
#   - the full embeddings path — used unchanged
#       "https://api.openai.com/v1/embeddings"
#       "http://localhost:11434/v1/embeddings"  (local Ollama)
# Any other path refuses to start when mode = "proxy" and names this URL
# plus the {origin}/v1/embeddings path to set. The string stored here is
# also the proxy embedder identity, so keep it stable once a corpus is indexed.
default_endpoint = ""

# Model name to request from the embedding endpoint.
# Example: "text-embedding-ada-002"  (OpenAI)
# Example: "nomic-embed-text"        (Ollama)
default_model = ""

# Maximum number of documents sent in a single embedding API call.
# Larger batches reduce round-trip overhead; smaller batches reduce latency
# for individual documents. Range: 1 – 2048.
batch_size = 64

# HTTP request timeout for embedding API calls (milliseconds).
# If the embedding service does not respond within this window, the ingest
# request fails with a timeout error.
timeout_ms = 5000

# Neural backend (`--embed-mode neural`): how many scheduling windows of one
# _bulk request may run through the embedder concurrently. Default 1 keeps the
# historical strictly-serial window loop. Raise it on a many-core box to let a
# single _bulk stream keep several BERT forward passes in flight on the shared
# model instead of one; outputs are unchanged (each window stays its own batch).
# Range: 1 – 64.
# neural_window_concurrency = 1

# ── Resource Limits (7 of 15 settings) ────────────────────────────────────────

[limits]

# Process-wide memory ceiling (MiB) that bounds every internal budget — segment
# hydration, query working sets, and the ingest circuit breaker. OMIT it (the
# default) to AUTO-size the cap from the machine: half of RAM under 16 GiB,
# then 8 / 16 / 32 GiB. An 8 GiB host gets 4 GiB, so a merge has room; a
# 16 GiB host stays at 8 GiB and a large box climbs. Set an explicit
# MiB ceiling to raise headroom on a big host — e.g. when a large `xerj autoindex`
# trips `429 circuit_breaking_exception`. Set 0 to uncap to the whole machine
# (not recommended). Env override: XERJ_MAX_PROCESS_MEMORY_MB=auto|off|<MiB>.
# max_process_memory_mb = 0

# Maximum memory a single query may allocate for intermediate results (MiB).
# Queries that exceed this limit are cancelled with a resource-exceeded error.
# Increase for aggregation-heavy workloads; decrease to protect shared nodes.
max_query_memory_mb = 512

# Maximum number of search queries executing concurrently across all indices.
# Additional requests are queued. This prevents unbounded memory growth under
# burst traffic. Range: 1 – 65535.
max_concurrent_searches = 64

# Maximum number of mapped fields per index (mapping explosion protection).
# Indices that exceed this limit reject new field additions.
# Elasticsearch uses 1000 as its default; 500 is intentionally stricter.
max_fields_per_index = 500

# Maximum number of actions in a single _bulk request (DoS protection).
# Each action materializes ~300 B of parse-phase heap; an unbounded bulk
# can amplify a 100 MiB body to ~7.5 GiB of heap before admission checks
# fire. 50 000 actions × ~300 B ≈ 15 MiB — well bounded. Set to 0 to
# disable the cap (not recommended in production).
max_actions_per_bulk = 50000

# Filesystem roots a snapshot repository's settings.location may resolve under
# (an Elasticsearch path.repo equivalent). Empty = only data_dir is permitted.
# Without this bound, a write-capable client can PUT a snapshot repo whose
# location is any absolute path and then read/write index data outside data_dir.
# Add absolute base paths here only to allow snapshots on external/backup roots.
# Example: snapshot_repo_allowlist = ["/mnt/backups"]
snapshot_repo_allowlist = []

# Let a snapshot RESTORE (never a create) read from the Corpus Hub pack cache of
# the user this server runs as: $XERJ_HUB_HOME/packs, else ~/.xerj/hub/packs.
# That is where `xerj hub pull` / `xerj ask` extract a verified, signed pack
# before asking the server to restore it, so this is what lets a pull work
# against a server you started yourself. Honoured only while that directory is
# a real directory (not a symlink) owned by this server's user; symlinks inside
# it that point elsewhere are refused. false = only data_dir and the allowlist.
# A server running as another user, in a container or on another machine does
# not share your cache: add the directory to snapshot_repo_allowlist there.
hub_pack_restore = true

# Process-wide retained-payload budget for the seven immutable segment
# hydration caches (MiB). 0 derives 20% of the effective cgroup/system memory
# limit with no minimum floor. This is not an RSS limit: query-owned results,
# decode scratch, mmaps, allocator fragmentation, and other caches are separate.
max_segment_hydration_cache_mb = 0

# ── Turbo Indexing (3 settings) — opt-in high-throughput mode ─────────────────
#
# Turbo mode is enabled per-request, not globally:
#   - POST /v1/indices/{name}/turbo-ingest  (dedicated endpoint)
#   - X-Turbo: true header on standard _bulk requests
#
# NOT WIRED in this build: none of the three keys below changes anything.
# A turbo request is indexed as one batch, turbo ingest no longer
# pre-tokenises (so there is nothing to parallelise), and the fast-analyzer
# flag reaches a parameter the turbo path ignores. The standard _bulk path
# takes the batched route for every request, header or not. Setting any key
# away from its default logs a warning at startup.

[indexing]

# Number of documents accumulated per batch in turbo mode.
# Larger batches amortise WAL and fsync overhead across more documents,
# increasing throughput at the cost of slightly higher per-batch latency.
# Recommended range: 500 – 5000.
turbo_batch_size = 1000

# Enable parallel tokenisation in turbo mode using Rayon's thread pool.
# Disabling this is useful only for debugging or on single-core machines.
turbo_parallel = true

# Skip stemming and stopword removal for maximum tokenisation speed.
# When true, the FastTokenizer is used instead of the configured FTS analyzer.
# This increases ingest throughput at the cost of reduced search recall
# (e.g. "running" will not match "run").
turbo_fast_analyzer = false

# ── Engine (6 settings; worker counts stay machine-derived) ──────────────────
#
# `ingest_shards`, `flush_workers`, `merge_workers` and `search_workers`
# default from the host's core count (see EngineConfig). The two deadlines
# below are absolute: they are what stops a wedged flush from parking
# `_refresh` and `finalize-refresh` forever (#1635).
# `XERJ_FLUSH_ADMIT_TIMEOUT_SECS` and `XERJ_FLUSH_TIMEOUT_SECS` override
# them for one run.

[engine]

# How long a shard flush waits for a flush-admission permit before failing.
# The wait is before the memtable is frozen, so a timeout loses no documents
# and the flush can be retried.
flush_admit_timeout_secs = 120

# How long one index's flush may run before refresh reports that index as
# failed and moves on. A publication already past the freeze is not cancelled.
# Must be at least flush_admit_timeout_secs.
flush_timeout_secs = 300

# ── Cluster (5 settings, all commented out below) ─────────────────────────────
#
# Multi-node cluster mode is OFF by default and is experimental. The whole
# block is commented out; uncomment it only if you are evaluating clustering.
#
# The cluster port carries Raft control messages. Every frame on it is
# authenticated with a cluster-wide shared secret (HMAC-SHA256 over a
# per-connection challenge), so `auth_secret` is mandatory whenever
# `enabled = true` — a node with cluster mode on and no secret refuses to
# start rather than expose an unauthenticated control port. Supply it here or
# via the XERJ_CLUSTER_AUTH_SECRET environment variable (this file wins if
# both are set), use the SAME value on every node, and generate it with
# `openssl rand -hex 32`. Minimum 16 characters.
#
# Note: the HMAC authenticates frames, it does not encrypt them. Cluster
# traffic is still plaintext — keep the cluster port on a trusted network.
#
# [cluster]
# enabled     = true
# port        = 9300
# peers       = ["10.0.0.2:9300=10.0.0.2:9300", "10.0.0.3:9300=10.0.0.3:9300"]
#               # label must equal address, or the node refuses to start (#1171)
# tick_ms     = 50
# auth_secret = ""

# ── Logging (2 settings) ──────────────────────────────────────────────────────

[logging]

# Log line format:
#   "text" — human-readable compact one-liners (default).
#   "json" — one JSON object per line, for structured log shippers
#            (Loki / Elastic / Datadog).
format = "text"

# Emit an INFO-level access log line per HTTP request (method, path, status,
# latency). Default false: request tracing stays at DEBUG (silent under the
# default `info` filter). Turn on for request-level observability without
# dropping the global log filter down to debug.
access_log = false

# ── WAL tap: push a filtered subset of indices to an external target ──────────
# (10 settings, issue #320)
#
# One-directional, single-node, near-real-time push of selected indices to any
# ES-compatible cluster (Elasticsearch, OpenSearch, or another XERJ node). The
# wire format is `_bulk`, so the target needs nothing installed. This is NOT
# cross-cluster replication: nothing flows back, and there is no follower state
# machine.
#
# Before turning it on, three behaviours you are agreeing to:
#
#  * No backfill. A new index (nothing pruned from its WAL yet) is shipped
#    whole; an established one starts from the moment it is allowlisted. If it
#    needs the pre-existing documents, seed the target first: snapshot/restore
#    only works when the target is another XERJ node (the snapshot format is
#    engine-specific). For an Elasticsearch/OpenSearch target, seed with an
#    external scan-and-push of the current documents (_search/PIT -> _bulk).
#  * At-least-once. Each action carries `version_type=external` with the WAL
#    seq_no, so redelivery is a no-op on a target that honours it.
#  * Retention never waits for the target. WAL generations are pruned once they
#    are durable in a segment, whether or not the tap has shipped them — a slow
#    remote must not be able to fill this node's disk. A tap that falls that far
#    behind loses entries and reports `gaps` in GET /_xerj/wal_tap/_stats.
#    `min_retained_generations` buys BOUNDED slack (a floor, not a lease): at
#    the default 0, an outage longer than one flush interval loses data.
#
# System indices (every .xerj* name, not just .xerj-memory-*) are never
# shipped, whatever `indices` says.
#
# `target_url` must NOT carry credentials (https://user:pass@host is refused at
# startup): it is echoed by GET /_xerj/wal_tap, by _stats and in the log.
# `target_auth` is the credential field and is write-only.
#
# Everything here is also settable at runtime, without a restart, via
# PUT /_xerj/wal_tap — which persists the patch, so it survives a restart.
# DELETE /_xerj/wal_tap drops the runtime overlay and reverts to this file.
# All three endpoints are superuser-only.
#
# [wal_tap]
# enabled                  = true                      # not a default (false)
# target_url               = "https://central:9200"    # not a default ("")
# target_auth              = "ApiKey abc123"           # not a default ("")
# indices                  = ["edge-*", "metrics"]     # not a default ([])
# poll_interval_ms         = 500                       # 50..=60000
# max_batch_docs           = 1000                      # >= 1
# max_batch_bytes          = 5242880                   # >= 1
# request_timeout_secs     = 30                        # >= 1
# max_retry_backoff_secs   = 60                        # 1..=86400 (one day)
# min_retained_generations = 0                         # <= 64
#
# The ranges above are enforced at startup, not just by PUT /_xerj/wal_tap: an
# out-of-range value here refuses the boot rather than becoming a disk-full
# page later. `min_retained_generations` is capped at 64 because it holds that
# many rotated WAL files per shard per index — up to n * storage.wal_max_size_mb
# of disk each — whether or not a tap is running.

# ── Rerank provider ─────────────────────────────────────────
# `"rerank": {...}` on _search sends the text of the top-N hits to a
# third-party judge (TypeSafe AI's Jev) and reorders them by the relevance
# probability that comes back. It is the only SEARCH-TIME feature that sends
# document text off this node. Two other features send text off it, both off
# by default: [embedding] default_endpoint (document text at write time, query
# text at search time) and the WAL tap. The node's remaining outbound
# connections (neural model download, cluster Raft) carry no document text;
# docs/RERANK.md lists every one. Reranking does nothing until a key is
# supplied here or in the TYPESAFE_API_KEY environment variable. A value in
# this file wins over the environment. `enabled = false` refuses every rerank request (403) whatever
# the environment holds. The key is never echoed: GET /_xerj/rerank (superuser
# only) reports whether one is set and where it came from, nothing more.
# `endpoint`, from here or from TYPESAFE_ENDPOINT, must be an absolute
# http(s):// URL with no user:password@ in it, or the node refuses to start.
# See docs/RERANK.md.
#
# [rerank]
# enabled  = true
# api_key  = "ts-..."                                  # not a default ("")
# endpoint = "https://api.typesafe.ai/v1/systemone"    # not a default ("")

# ─────────────────────────────────────────────────────────────────────────
# Decisions — typed answers from your own labelled history, no model call.
#
# Index the examples you already have (one document per example: the text and
# its label), and POST /v1/systemone answers System One-shaped questions with
# a weighted nearest-neighbour vote over that index — same interface as a
# judge model, nothing leaves the node. POST /_decide is the same vote with
# the evidence in the response: neighbours, labels, weights, and an abstain
# below min_confidence. Empty `index` (the default) leaves both answering 503.
# See docs/RERANK.md and benchmarks/decisions-as-retrieval.
#
# [decisions]
# index          = "judgements"   # not a default ("") — an index of labelled examples
# k              = 10             # neighbours that vote
# label_field    = "label"
# text_field     = "text"
# positive_label = "true"         # the label a noul's probability is the share of
# min_confidence = 0.0            # /_decide abstains below this
# escalate_below = 0.8            # escalate tier-1 vote to tier-2 local head below this winning share (0.0 disables; #1094)
# human_weight   = 2.0            # vote-weight multiplier for history docs carrying human: true
# calibration    = "none"         # none | isotonic | temperature — p_cal beside every p_raw (#1063)

# ─────────────────────────────────────────────────────────────────────────
# Corpus Hub — hosted read-only endpoints.
#
# Four GET routes under /_hub/v1/ answer from the pre-indexed corpus packs
# restored on this node: /catalogue, /def/{slug}/{symbol}, /code/{slug} and
# /search. They are served on the ES-compatible port (es_compat_port), are
# read-only, only ever query xc-* indices, and are rate limited to 60
# requests a minute per client address (429 + Retry-After).
# By default every route needs an API key like the rest of the node.
# `public = true` lets exactly those four routes answer without one; every
# other route keeps authentication, authorization and the audit log.
# `catalogue_path` is the signed catalogue.json the node serves and checks
# every corpus name against; it is required when `public = true`, or the
# node refuses to start. Behind a reverse proxy, also list the proxy in
# [server] trusted_proxies, or every client shares the proxy's one budget.
#
# [hub]
# public         = false
# catalogue_path = ""    # not a default ("/srv/hub/catalogue.json") — required when public = true