backends/cascade.py
Result-aware CASCADE backend
Runs free ~10 ms sparse first, inspects the score profile — the top-1 floor and the relative margin between the top and k-th hit — and only pays for dense embedding + RRF when lexical evidence is weak. It decides on measured results, not query shape, so it doesn't degrade as corpus vocabulary grows.
sparse.top1 < floor or margin(top, k) < δ → escalate to dense + RRF
index/cache.py
Disk-cached dense index
FAISS index + doc map keyed by SHA-256(doc_id, content). Corpus edits auto-invalidate. First boot embeds (~$0.0003); later boots load from disk in milliseconds.
cache/ttl_lru.py
Thread-safe TTL + LRU cache
On the hot path: long TTL for embeddings (saves an OpenAI round trip), short TTL for web results (freshness). ttl=0 disables cleanly via env.
bench/pipeline.py
2-phase benchmark pipeline
Sync retrieve across all four backends, then async LLM-judge on a 1/2/3 rubric — checkpointed every 50 queries, so a mid-run crash loses nothing.
POST /answer
Streaming RAG with citations
Returns inline [n] citations. stream=true emits SSE — meta → delta → done — with token usage and cost in the final event.
obs/logging.py
Structured per-retrieve logging
One JSON line per /retrieve: query_hash (sha1, first 8 hex — correlate without leaking query text), backend, latency_ms, cost_usd.
enterprise/ · optional
Optional enterprise layer
Everything above ships open. When you need more, it's already wired:
RBAC · reader/indexer/benchmark/admin
per-tenant quotas + daily cost caps
hashed API keys
JSONL audit log
OpenTelemetry tracing
SLO targets
FAISS flat | HNSW
ML router (refuses to train on eval)
cross-encoder / overlap reranker
S3 connectors
shared index root · horizontal scale