Vector store access and lifecycle
Eligibility is a security decision, not a score
A tenant is an isolated customer or organization. An access control list (ACL) identifies which principals or groups can read a record. In this example a trusted server supplies tenant and group membership after authentication; record metadata is maintained by a trusted ingestion service. A record is eligible only when its tenant and embedding revision match, its deletion flag is explicitly False, and at least one approved group intersects the reader groups. Missing ACL or deletion state denies access. A user-provided filter cannot expand this scope. The three records below deliberately share a group name across tenants; only north/a is visible to north/staff. The helper is an illustrative predicate, not an authentication implementation.
def eligible(record, tenant, groups, revision): # Trusted server identity, group membership and record metadata. if not tenant or not revision: return False acl = record.get("groups") return (record.get("tenant") == tenant and record.get("revision") == revision and record.get("deleted") is False and isinstance(acl, list) and all(isinstance(g, str) and g for g in acl) and bool(set(acl) & set(groups)))
records = [dict(id="a", tenant="north", groups=["staff"], revision="r1", deleted=False), dict(id="b", tenant="south", groups=["staff"], revision="r1", deleted=False), dict(id="c", tenant="north", groups=["admin"], revision="r1", deleted=False)]print([r["id"] for r in records if eligible(r, "north", {"staff"}, "r1")])Filter the search scope before ranking
Compose mandatory tenant, ACL, active-state and revision conditions with optional filters using AND. Do not replace the mandatory conditions with a client filter. Use namespace or partition isolation and server-enforced authorization when supported; a metadata filter alone is not proof of isolation. In an exact search, apply eligibility before computing top-k. An ANN engine may internally visit candidates outside a requested filter depending on index implementation; use its documented filtering mechanism, keep raw candidates inside the trusted service and independently enforce policy before returning anything. A global top-k followed by filtering may lose all authorized matches even when many exist. Expand candidates within an approved bounded scope or return fewer results; never weaken access to fill k. Evaluate filtered recall against an exact baseline over the same allowed subset. Avoid exposing unauthorized IDs, distances, counts or text in responses or logs.
Treat stale candidates as hints, not permission
A search index, cache or replica may lag the authoritative record store. Use tenant-qualified keys to prevent collisions when local IDs repeat. At response assembly, resolve candidate IDs against current authoritative state, check tenant, ACL, revision and deletion state again, and fetch only allowed content. The second example returns local IDs for simplicity, deduplicates candidate keys and rejects foreign tenant keys. After the record is marked deleted, the unchanged stale candidate list produces no result. This illustrates a fail-closed read gate; it does not make distributed deletion instantaneous or prove physical erasure. Production must define consistency, authorization race handling, and safe response-time guarantees across services.
def materialize(candidate_ids, authoritative, tenant, groups, revision): # Candidate keys are (tenant, local_id). Never emit cached payloads. results = [] seen = set() if not tenant or not revision: return results for key in candidate_ids: if key in seen or key[0] != tenant: continue seen.add(key) record = authoritative.get(key) if record is None: continue acl = record.get("groups") if (record.get("tenant") == tenant and record.get("revision") == revision and record.get("deleted") is False and isinstance(acl, list) and all(isinstance(g, str) and g for g in acl) and set(acl) & set(groups)): results.append(key[1]) return results
key = ("north", "a")store = {key: dict(tenant="north", groups=["staff"], revision="r1", deleted=False)}cache = [key, ("south", "a"), key]print(materialize(cache, store, "north", {"staff"}, "r1"))store[key]["deleted"] = Trueprint(materialize(cache, store, "north", {"staff"}, "r1"))Manage the index lifecycle
Use stable record and chunk IDs with content and embedding versions. Insert or update from authorized ingestion, verify dimensions and retrieval profile, and record a tombstone or equivalent deletion state before removing vectors from search indexes and invalidating caches. Coordinate retries and out-of-order events so an old update cannot resurrect a deleted record; use monotonically increasing versions or equivalent concurrency control. For model migration, build a separate compatible index, evaluate it and switch an alias or configuration after verification. Retire old data under retention policy. Track deletion propagation across replicas, caches, backups and logs; logical exclusion differs from physical purge. Verify with a formerly allowed query, direct ID lookup and stale cache fixture. Never include private data in a tutorial index. Do not perform destructive actions on a live database for this lab.
Practice: isolate, delete and verify
Use the first lesson exact_top_k on only the records passing eligible. Add a nearer record owned by south and confirm that it cannot displace north/a. Test a north/admin record, missing ACL, stale revision, empty group membership and a duplicate candidate. Mark a previously visible record deleted and replay old candidate IDs through materialize; it must disappear. Measure exact-versus-candidate recall before and after the deletion with updated allowed baseline; if no records are eligible, mark the metric undefined and report the empty query separately. A production test should also cover cache invalidation, denied writes, cross-tenant IDs, concurrent revocation and log redaction. These local fixtures do not exercise a real database or authentication service.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Vector store access and lifecycle quiz
Apply vector retrieval and lifecycle contracts.
Who must determine the mandatory tenant filter?
Why filter before exact top-k selection?
What if a candidate refers to an authoritatively deleted record?
Why use tenant-qualified record IDs?
Does the tombstone check prove physical deletion from backups?