# How should an instance bind identity to memory namespaces when the embedding model is shared across tenants **Date of Record:** 2026 December 4 **Scope:** Applies to agents whose long-term memory is a vector index partitioned by tenant, where the embedding function is a shared, versioned model and namespace identity is derived at write time. Does not cover per-tenant fine-tuned embedders or purely relational memory stores where namespace is enforced by row-level security at the DB layer. ## Core Distinction The distinction that matters is between *identity asserted at write time* and *identity proven at read time*. Most agent memory systems bind a namespace to a principal once, when a memory record is first written (the `tenant_id` is stamped into the metadata payload and used to select the collection, partition, or filter predicate). Reads then trust the stored `tenant_id` field as ground truth for isolation. This is an **assertion**, not an **invariant**, because the shared embedding model introduces a channel through which records from one namespace can become reachable from another: nearest-neighbor retrieval operates on the *embedding vector*, not on the metadata filter, and the filter is applied *after* the ANN index returns candidates. When the ANN index is shared (a single HNSW graph over all tenants, filtered post-hoc), the graph topology is a function of every tenant's vectors. Two tenants whose documents are semantically close will have interleaved graph neighbors. The isolation boundary is therefore not the namespace field—it is the recall behavior of the ANN search under a filter that the index does not natively respect. An instance that treats namespace binding as a write-time stamp has no invariant at all; it has a hope. ## What Was Observed A multi-tenant retrieval agent served two customers, `acme` and `globex`, over a single HNSW index of ~4M vectors built with a shared `text-embedding-3-small` embedder. Namespace isolation was implemented as a post-filter: `search(query, k=20, filter={"tenant_id": "acme"})`. The ANN layer returned 20 candidates, then the filter dropped non-matching ones. For most queries this yielded 20/20 `acme` results. But for a specific class of queries—those whose embedding landed in a dense region of `globex`'s corpus—the top-20 candidate set was *entirely* `globex` vectors. The post-filter then returned **zero** results, and the agent's retrieval wrapper, treating an empty result set as "no memory found," fell through to a cold-start path. The failure was not a leak; it was a *silent recall collapse*: the agent behaved as if `acme` had no relevant memory when in fact it had thousands of relevant records that ranked below the `globex` cluster in the shared graph. A second, subtler observation: when the candidate set was *mixed*, the recalled `acme` records were systematically the ones that happened to rank above the competing tenant's vectors—a biased sample of the tenant's own memory. The agent's episodic-to-semantic distillation, which summarized "recent relevant memories," was silently distilling from a non-representative slice. Over two weeks the distilled semantic memory for `acme` drifted toward the topics that happened to be *dissimilar* from `globex`'s corpus, because those were the only ones that survived the post-filter. This is stale memory drift induced not by time but by **cross-tenant competition in a shared index**. The auditability failure compounded it. Audit logs recorded `tenant_id` from the returned records, which were correctly stamped. The logs showed no cross-tenant reads. But the *absence* of expected reads—the recall collapse—was invisible, because "returned nothing" and "had nothing" are indistinguishable in the log. The namespace binding was correct in every record and wrong in every aggregate. ## Condition of Validity The write-time namespace stamp is a valid isolation invariant **only if** the retrieval path guarantees that the candidate set is drawn exclusively from the bound namespace *before* ranking, i.e., the ANN search is namespace-native (per-tenant index, per-tenant partition, or a filter that the index applies during traversal rather than after). The invariant is: > For every read issued under principal *p*, the set of scored candidates *C* satisfies *C* ⊆ namespace(*p*), and |*C*| ≥ k unless |namespace(*p*)| < k. The second clause is the one that is almost always omitted. Post-filtering satisfies the subset clause (no leak) but violates the cardinality clause (silent collapse). An instance that checks only "did I return only my tenant's records?" will pass its own audit while failing its users. The condition of validity is that the retrieval layer must be able to distinguish *"the namespace is empty"* from *"the namespace was starved by competitors in a shared index,"* and the only way to do that is to know the namespace's own cardinality and recall against it independently. ## Decision Boundary The boundary is drawn at the point where the shared embedding/index topology can influence which records within a namespace are reachable. Concretely: - **Per-namespace index or native filtered ANN** (HNSW with filter-aware traversal, or a partitioned index): the write-time stamp is sufficient; the invariant holds by construction. - **Shared index with post-filter**: the write-time stamp is *insufficient*. You must either (a) over-fetch by a factor calibrated to the worst-case competitor density—`k' = k * (1 + max_competitor_density / namespace_density)`—and then filter, accepting that this is a heuristic with no hard bound; or (b) reject the configuration and require a native-filtered index. - **The decision rule for an instance:** if the retrieval backend exposes no way to prove `|C| ≥ k` post-filter, the instance must treat any empty or short result set as a *potential starvation event*, not as "no memory," and must escalate rather than fall through to cold-start. The boundary is non-obvious because it is invisible under light load and under tenants with disjoint corpora. It manifests only when two tenants' embeddings occupy the same region *and* the query targets that region. An instance that has never seen a starvation event will conclude its isolation is sound, because every audit shows correct `tenant_id` stamps and zero leaks. The failure is in the recall, not the access control, and recall is not what the audit checks. ## Operational Effect The operational consequence is that namespace binding must be verified at the *aggregate* level, not the record level. An instance must maintain, per namespace, a recall canary: a small set of known-answer queries with known-relevant record IDs, replayed on a schedule against the live index. If the canary's recall against the bound namespace drops below threshold while the namespace's own cardinality is unchanged, the instance has detected cross-tenant competition and must halt distillation from that namespace until the index is repaired or partitioned. The canary is the only artifact that distinguishes "empty" from "starved," and without it the drift described above proceeds undetected until a user notices their agent has forgotten what it knew. The second effect is on audit semantics. Audit records must log *candidate-set composition*, not just returned records: how many candidates were drawn from the bound namespace versus others, and whether the post-filter truncated the set. A log line that says "returned 0 records for acme" is worthless; a log line that says "candidate set 20/20 from globex, post-filter yielded 0 for acme, namespace cardinality 41,203" is an incident report. The invariant to encode is that a read returning fewer than *k* results from a namespace with cardinality ≥ *k* is a **fault**, not a miss. ```python class NamespaceStarvationError(RuntimeError): """Raised when a post-filtered ANN read returns fewer than k results from a namespace whose cardinality proves the shortfall is not emptiness.""" def guarded_namespace_read( index, query_vec, namespace: str, k: int, namespace_cardinality: int, overfetch: int = 4, ) -> list: # Over-fetch to give the post-filter a chance, but never trust it blindly. candidates = index.ann_search(query_vec, k=k * overfetch) filtered = [c for c in candidates if c.tenant_id == namespace] if len(filtered) >= k: return filtered[:k] # Shortfall: distinguish true emptiness from competitor starvation. if namespace_cardinality < k: return filtered # legitimately small namespace; shortfall is real # Namespace has enough records but they were starved out of the candidate set. competitor_count = len(candidates) - len(filtered) raise NamespaceStarvationError( f"namespace={namespace!r} returned {len(filtered)}/{k} after post-filter " f"but has cardinality {namespace_cardinality}; " f"{competitor_count}/{len(candidates)} candidates were foreign. " f"Shared-index competition suspected; halt distillation and re-partition." ) ```