Use a durable deletion ledger, generation-stamped index records, and query-time suppression for internal healthtech documentation; physical removal can follow asynchronously once every derived index has acknowledged the same delete.

Short answer: treat deletion as a state transition that must propagate through retrieval, not as a best-effort call to an index, because a document that has disappeared from the source but remains retrievable is a correctness failure.

This architecture decision record covers a healthtech catalog that aggregates provider, facility, and service listings from several internal sources. Its primary constraint is index cost at scale: rebuilding every embedding and lexical index after each source change is operationally simple, but it repeatedly pays to recompute records that did not change. The proposed design pays for changed generations, while preserving an auditable answer to the question that matters during reconciliation: which logical listing was visible to retrieval at a given generation?

What delete semantics should internal engineering documentation retrieval enforce?

The unit of deletion must be a stable logical document ID, not a chunk ID and not a source URL. A URL can change, while one source document can produce dozens of chunks. Each ingest operation assigns a monotonically increasing generation to that logical ID; every derived chunk carries the logical ID and generation, and a durable ledger records either active or deleted for the latest generation. Query results are admissible only when their generation matches the current active ledger row.

Four invariants follow. First, once generation 18 is deleted, no chunk from generation 18 or earlier may enter answer context. Second, replaying the same delete must have no additional effect. Third, a delayed indexing worker may not resurrect an older generation after generation 19 has been accepted. Fourth, reconciliation must be able to distinguish “the delete has been committed” from “all physical copies have been reclaimed.” These are exactly-once outcomes built from at-least-once messages; the claim is about observable state, not magical delivery guarantees.

The failure boundary is the ledger commit. Before that commit, the old generation remains authoritative. After it, retrieval suppresses the record even if an embedding row, lexical posting, or cache entry still exists. That temporary storage is garbage, but it is no longer live data. This separation matters because a multi-index delete cannot be made atomic merely by placing three remote calls next to one another.

Be strict here.

For compliance, retention, and legal-hold limits, the application team should obtain explicit policy values from its own compliance program; I'm not sure a generic duration would be defensible across jurisdictions or data classes. Store those policy decisions alongside the deletion event, and never infer permission to erase an audit record from permission to hide a listing from retrieval. Visibility deletion and evidence retention are separate controls.

Record invariants and failure boundaries

The ledger needs little data: tenant, logical document ID, generation, state, source version, event ID, and committed time. The event ID supplies idempotency. A unique constraint on (tenant_id, event_id) turns redelivery into a read of an already accepted decision, while a conditional update prevents generation 17 from overwriting generation 18. Keep the transaction short; embedding generation and index mutation happen after commit.

Consider a provider listing assembled from a scheduling feed and a credentialing feed. The scheduling source withdraws location clinic-204, emits event evt-8f31, and the ledger commits generation 43 as deleted. A lexical worker has already removed its postings, the vector worker is delayed, and a cache still holds the old candidate. Without query-time validation, the answer builder can quote a location the authoritative system withdrew. With validation, all three candidates fail the same generation check immediately; cleanup latency changes storage cost, not user-visible truth. Later, if a corrected listing arrives as generation 44, it becomes visible only after its derived records carry 44 and the ledger marks 44 active. The older delete cannot win on retry because its generation is lower.

That example also defines the audit trail. Log the decision tuple (tenant, document, generation, event, prior state, new state) and the acknowledgements from each derived store. Don't log the document body merely to prove that deletion happened; identifiers and state transitions are enough for reconciliation, and duplicating content into operational logs creates another retention surface.

The read path must fail closed on ambiguous authority. A candidate with no matching ledger row, a stale generation, or a deleted state is excluded. This can lower recall while an ingest is incomplete, but returning no listing is preferable to returning a withdrawn one in a clinical directory. Your mileage may vary for low-consequence corpora, where availability can reasonably win over strict suppression.

Compare the deletion strategies

Strategy Retrieval correctness boundary Index cost at scale Operational trade-off
Full rebuild New snapshot publication Recomputes unchanged documents Simple state model; expensive when changes are sparse
Immediate fan-out delete Completion of every index call Touches only affected records Partial completion needs durable coordination
Ledger tombstone plus asynchronous purge Ledger commit and query filter Touches changed records; retains garbage until purge Adds a read-path check and reconciliation job
Time-to-live only Expiration in each store Low write coordination Deletion latency is intentionally nondeterministic

The decision is the ledger-and-purge design. It makes the correctness boundary local and inspectable, and its marginal indexing work follows the change set rather than corpus size. The catch is read amplification: candidate IDs must be checked against authoritative state, preferably in a bounded batch. It is not suitable when the retrieval store cannot return stable IDs or when the extra lookup violates a hard latency budget. In those cases, use versioned full snapshots with an atomic alias swap; the higher rebuild cost buys a smaller query path.

Time-to-live remains valid for disposable caches whose contents are already filtered against the ledger. It is not a delete protocol for the authoritative retrieval surface because expiration expresses age, not intent.

Intent wins.

Critical path in Go

The following Go sketch keeps storage interfaces generic. Apply serializes state changes in a database transaction, writes an outbox record in that same transaction, and treats an already-recorded event as success. Workers can then fan out physical deletion without owning visibility semantics.

package deletion import ( "context" "errors" ) var ErrStaleGeneration = errors.New("stale generation") type Event struct { TenantID string DocumentID string EventID string Generation int64 } type State struct { Generation int64 Deleted bool } type Tx interface { SeenEvent(ctx context.Context, tenantID, eventID string) (bool, error) LockState(ctx context.Context, tenantID, documentID string) (State, error) PutDeleted(ctx context.Context, event Event) error AppendPurge(ctx context.Context, event Event) error Commit() error Rollback() error } type Store interface { Begin(ctx context.Context) (Tx, error) } func Apply(ctx context.Context, store Store, event Event) (err error) { tx, err := store.Begin(ctx) if err != nil { return err } defer func() { if err != nil { _ = tx.Rollback() } }() seen, err := tx.SeenEvent(ctx, event.TenantID, event.EventID) if err != nil { return err } if seen { return tx.Commit() } current, err := tx.LockState(ctx, event.TenantID, event.DocumentID) if err != nil { return err } if event.Generation < current.Generation { return ErrStaleGeneration } if err = tx.PutDeleted(ctx, event); err != nil { return err } if err = tx.AppendPurge(ctx, event); err != nil { return err } return tx.Commit() } 

The corresponding query path over-fetches candidates, loads current states in one batch, and admits only exact active-generation matches. Over-fetching is bounded; otherwise a heavily deleted result set can turn one query into an unbounded scan. Record the requested candidate count, rejected count by reason, ledger latency, and final context count. Those measurements reveal whether purge lag is becoming a cost problem without weakening the visibility rule.

Test the state machine, not just individual functions. Generate reordered create, update, and delete events; duplicate every event; interrupt workers between ledger commit and physical purge; then assert that no admitted candidate has a generation different from the active ledger. A deployment should also run a shadow reconciliation query that compares sampled index records with ledger state before the new filter becomes authoritative.

Rejected option and the decision rule

An index-wide rebuild was rejected for this catalog because the decision axis is index cost under sparse source changes. It is still the better choice for a small corpus, a retrieval engine without stable metadata filters, or a system whose snapshot can be built cheaply and published atomically. The simplicity is real. Don't add a deletion ledger merely to imitate a larger system.

Use a quantitative decision rule based on inputs your team can measure: changed documents per publication interval, chunks per document, cost to regenerate one chunk, retained tombstone bytes, purge throughput, and read-path validation latency. Compare the projected incremental work with a full snapshot build, then include the engineering cost of reconciliation and on-call diagnosis. No universal crossover point can be claimed without those measurements.

The final acceptance test is concise: after a committed delete, any cached, lexical, or vector candidate from that logical document is rejected before answer construction; a repeated event leaves state unchanged; a stale event cannot resurrect content; and the audit record connects the source event to every purge acknowledgement. If all four properties hold, physical cleanup can be optimized independently without changing delete semantics.

References