Operations

Demo day is easy. Day 400 is the job — upserts, sizing, tenants, and the restore you pray you'll never need.

▶ Watch this reel

What you'll learn

  1. Indexing & updates
  2. Sizing & cost
  3. Multi-tenancy & security
  4. Backup & DR

Remember this

Indexing & updates

Sizing & cost

Multi-tenancy & security

Backup & DR

Code: The operations layer — writes, tenancy, restore drill

from hashlib import sha1

# --- 1. Deterministic upserts --------------------------------------
def chunk_id(doc_id: str, idx: int) -> str:
    return sha1(f"{doc_id}:{idx}".encode()).hexdigest()[:16]

for doc in changed_docs():              # from CDC events, not a rebuild
    for i, chunk in enumerate(chunk(doc.text)):
        store.upsert(id=chunk_id(doc.id, i),
                     vec=embed(chunk),
                     payload={"doc_id": doc.id, "v": doc.version,
                              "tenant": doc.tenant, "text": chunk})

# --- 2. Tenant enforcement (one path, tested) ----------------------
def search(q, tenant: str, k=5):
    assert tenant, "tenant is mandatory"
    return store.search(embed(q), k=k, where={"tenant": tenant})

# test:  search(q, tenant=None) must raise — CI enforces it

# --- 3. Restore drill (quarterly, timed) ---------------------------
def restore_drill():
    t0 = time.time()
    for doc in source_store.list_all():          # the crown jewels
        reindex(doc)                              # embed + upsert
    elapsed = time.time() - t0
    assert elapsed < RTO_SECONDS, f"rebuild {elapsed:.0f}s > RTO"
    # Snapshot alternative: store.snapshot() → restore in minutes

# --- 4. Delete = tombstone + compact -------------------------------
# store.delete(ids) marks; a scheduled job runs store.compact()
# off-peak — latency stays smooth, graph gets repaired.