Treat a backup as a candidate generation: verify its metadata, replay later changes and test search quality before cutover.
Restore a retrieval index with schema, deletion and relevance proofs
A snapshot is not an answer-ready index
A backup can preserve index bytes while still being too old, mapped to the wrong embedding model or missing the latest permission and deletion events. Define recovery point and recovery time objectives for the retrieval service, then name every component needed to meet them: source documents, lexical and vector indexes, analyzers, embedding version, access-control state, aliases and change logs. An index archive alone cannot prove that restored results are safe. Embedding version contracts must match the query encoder before vector traffic returns.
Capture a consistent generation
Record an index generation ID, source watermark, schema revision, tokenizer or analyzer revision, embedding dimension, metric and document count with the backup. Use the backend's supported snapshot mechanism rather than copying live index files while writers are active. Protect the backup repository and test that its credentials and keys are available during recovery. A snapshot taken before an ingestion event is valid only if later events can be replayed from a durable log. Watermarks show what the restored service has and has not seen.
Restore beside production first
Restore into a separate generation or name so the current serving alias remains unchanged. Verify manifest checksums and active document IDs, then replay updates and tombstones through the target watermark. A stale backup must not revive a deleted document, even temporarily. Apply the current permission policy and compare source revisions, not just document totals; equal counts can conceal one missing and one duplicated record. Deletion proof is mandatory before the target accepts user queries. The old serving generation remains available until cutover checks pass.
Run retrieval and access canaries
A restored index may open successfully but rank badly because field norms, vector metric, analyzers or reranker inputs changed. Run exact identifier queries, phrase queries, filtered ANN probes and judged answer-support tests under the restored generation. Include forbidden-document canaries and intentionally deleted IDs. Compare top-K overlap and important slices against the last known good release, while allowing expected freshness changes after replay. Release gates define minimum quality; a green cluster status is not a relevance proof.
Switch, observe, and rehearse
Move the serving alias only after eligibility, freshness and quality checks pass. Pin or finish in-flight requests so a single answer does not combine evidence from different generations. Keep a rollback target only if it also applies the current tombstones and permissions; an unsafe rollback is not a recovery path. Alias cutover covers the pointer switch. Rehearse restore regularly, measuring time to first safe query, missing-event replay duration and storage headroom. A backup that has never been restored is an untested assumption.
Worked contract
from dataclasses import dataclass
from hashlib import sha256
@dataclass(frozen=True)
class IndexedRecord:
document_id: str
revision: int
content_digest: str
@dataclass(frozen=True)
class RestoreManifest:
source_watermark: int
schema_revision: str
embedding_revision: str
active_digest: str
def active_digest(records: list[IndexedRecord],
deleted_ids: set[str]) -> str:
active = [record for record in records
if record.document_id not in deleted_ids]
keys = [(record.document_id, record.revision, record.content_digest)
for record in active]
if len({key[0] for key in keys}) != len(keys):
raise ValueError("duplicate active document")
payload = "\n".join(f"{item[0]}:{item[1]}:{item[2]}"
for item in sorted(keys))
return sha256(payload.encode()).hexdigest()
def verify_restore(records: list[IndexedRecord],
manifest: RestoreManifest, deleted_ids: set[str],
required_watermark: int) -> None:
if manifest.source_watermark < required_watermark:
raise ValueError("event replay is incomplete")
if (manifest.schema_revision != "schema-7" or
manifest.embedding_revision != "encoder-4"):
raise ValueError("incompatible retrieval contract")
if any(record.document_id in deleted_ids for record in records):
raise ValueError("deleted document remains in index")
if active_digest(records, deleted_ids) != manifest.active_digest:
raise ValueError("restored content differs from manifest")
restored = [IndexedRecord("manual-47", 3, "sha-47")]
manifest = RestoreManifest(219, "schema-7", "encoder-4",
active_digest(restored, set()))
verify_restore(restored, manifest, {"withdrawn-81"}, 219)Performance and operating cost
Sorting N active record descriptors for the digest takes O(N log N) time and O(N) memory; a backend can use ordered scans and streaming hashes to reduce extra memory. Snapshot creation, transfer, replay and vector reconstruction have separate I/O and CPU costs that depend on the engine. The code checks metadata and a manifest digest but does not perform storage-level restore, cryptographic signature verification, authorization or relevance tests. Those remain required gates before alias cutover. Track both recovery time and the age of the latest safe recovered watermark.
Common Mistakes
- Copying a live index directory as if it were an atomic backup.
- Restoring old data without replaying later deletions and permission changes.
- Checking document counts but not IDs, revisions, schema and model compatibility.
- Switching the serving alias before access canaries and judged retrieval tests pass.
Validation drill
Restore a backup from 47 ingestion events before the current watermark into a separate generation. Replay those events, delete seven records, run permission canaries and 39 judged queries, and record the time until the restored service can answer safely.
