Verbs:set_tenant · list_sources · sql (the analyzer’s discriminator rewrite) · add_source(tenant_column=…) · generate_embeddings · search · Background: tenant isolation as a property of the catalog + the query analyzer, not a feature flag · Checked: tenancy (rails.tenant / assert_listing_isolated / assert_rows_isolated) + measurement.
The engine’s tenancy contract is short, and this chapter does not restate it as prose — it measures it, live over the ogbn-arxiv papers, as three isolation properties plus one consequence. Every number is a verdict: a hard zero where isolation must hold, a positive count where the honest caveat says data is visible.
The model has exactly two genuine isolation layers and one honest caveat:
catalog-listing isolation — list_sources filters the registry to tenant_id = $cur OR IS NULL; tenant A’s listing excludes B’s registration.
row-level discriminator-column isolation — the analyzer injects tenant_id = $cur OR IS NULL onto a TableScanonly when the queried table carries a discriminator — a tenant_id column, or the column the source declared as its tenant_column when it was registered — so the SAME tagged source returns disjoint rows under A vs B.
the caveat — a discriminator-less source is globally readable: A sees ALL of B’s rows when it names the source. The engine does not authenticate; access-gating lives above it.
The two tenants are an honest, disjoint partition of the papers: every paper belongs to exactly one tenant by its subject class. The tenant ids are opaque UUIDs — the engine validates the form, never who the tenant is.
50.1 The setup — two tenants over one corpus
We reuse jammi_cookbook.rails verbatim — tenant (the bind-in-place/restore context manager), assert_listing_isolated, and assert_rows_isolated, the corrected helpers, not a re-implementation. set_tenant binds the scope to the connection in place; the bound scope drives both isolation layers (tenant_scope is the block-scoped form the tenant helper delegates to).
import tempfileimport jammiimport pyarrow as paimport pyarrow.parquet as pqfrom jammi_cookbook import datasets, encoders, scalefrom jammi_cookbook.claims import claimfrom jammi_cookbook.rails import assert_listing_isolated, assert_rows_isolated, tenantSCALE = scale.current()TENANT_A ="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"TENANT_B ="bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"work = tempfile.mkdtemp()db = jammi.connect(f"file://{tempfile.mkdtemp()}")arxiv = datasets.arxiv(db, SCALE)papers = db.sql(f"SELECT paper_id, title, abstract, subject FROM {arxiv.papers}.public.{arxiv.papers}").to_pylist()subject = {p["paper_id"]: p["subject"] for p in papers}subjects =sorted({p["subject"] for p in papers})a_subjects =set(subjects[::2])a_papers =sorted(pid for pid in subject if subject[pid] in a_subjects)b_papers =sorted(pid for pid in subject if subject[pid] notin a_subjects)def write_src(name, table): path =f"{work}/{name}.parquet" pq.write_table(table, path) db.add_source(name, url=path, format="parquet")print(f"partition: A {len(a_papers)} / B {len(b_papers)} papers (disjoint, tiling the corpus)")
partition: A 21 / B 379 papers (disjoint, tiling the corpus)
50.2 Property 1 — catalog-listing isolation (a hard zero)
Each tenant registers its own source under its own scope. Under tenant A, list_sources must not surface B’s registration.
with tenant(db, TENANT_A): write_src("papers_a", pa.table({"paper_id": a_papers}))with tenant(db, TENANT_B): write_src("papers_b", pa.table({"paper_id": b_papers}))with tenant(db, TENANT_A): a_listed = [s["source_id"] for s in db.list_sources()]assert_listing_isolated(a_listed, {"papers_b"}, tenant_id=TENANT_A)listing_leak =len(set(a_listed) & {"papers_b"})print(f"tenant A lists: {sorted(a_listed)}")print(f"B's 'papers_b' leaked into A's listing: {listing_leak}")
tenant A lists: ['arxiv_cites', 'arxiv_papers', 'papers_a']
B's 'papers_b' leaked into A's listing: 0
50.3 Property 2 — discriminator-column row isolation (a hard zero)
Now the load-bearing layer. We register one shared source as a global (tenant_id IS NULL), carrying a tenant_id discriminator column that tags each row to a tenant. When tenant A reads it, the analyzer injects tenant_id = $cur OR IS NULL onto the scan, so A sees only its own rows — none of B’s.
db.set_tenant("") # register the shared tagged source as a globalwrite_src("papers_tagged", pa.table({"paper_id": [p["paper_id"] for p in papers],"title": [p["title"] for p in papers],"abstract": [p["abstract"] for p in papers],"subject": [p["subject"] for p in papers],"tenant_id": [TENANT_A if p["subject"] in a_subjects else TENANT_B for p in papers],}))with tenant(db, TENANT_A): seen_a = [r["paper_id"] for r in db.sql("SELECT paper_id FROM papers_tagged.public.papers_tagged").to_pylist()]assert_rows_isolated(seen_a, set(b_papers), tenant_id=TENANT_A)discriminator_leak =len(set(seen_a) &set(b_papers))print(f"tenant A reads the shared tagged source: {len(seen_a)} rows")print(f"B-tagged rows that leaked to A: {discriminator_leak}")
tenant A reads the shared tagged source: 21 rows
B-tagged rows that leaked to A: 0
This is the isolation layer that actually scopes data: one physical source, disjoint reads, enforced by the analyzer because the discriminator column exists.
50.4 Property 3 — the caveat: a discriminator-less source is globally readable
The honest limit, asserted as a positive count, not hidden. A source with no discriminator — no tenant_id column and no declared tenant_column — gets no scan rewrite — it is globally readable by any tenant that names it. We register B’s papers under B with no discriminator column, then read it under A: A sees all of B’s rows.
with tenant(db, TENANT_B): write_src("papers_b_nodisc", pa.table({"paper_id": b_papers}))with tenant(db, TENANT_A): seen_global = [r["paper_id"] for r in db.sql("SELECT paper_id FROM papers_b_nodisc.public.papers_b_nodisc").to_pylist()]caveat_visible =len(set(seen_global) &set(b_papers))print(f"tenant A reads B's discriminator-less source: {caveat_visible} of {len(b_papers)} "f"B rows visible")print("the engine does not authenticate — access-gating lives above it")
tenant A reads B's discriminator-less source: 379 of 379 B rows visible
the engine does not authenticate — access-gating lives above it
This is the claim that is easy to overstate and that this chapter must not re-break: a separate per-tenant source is hidden from the listing (Property 1), but its rows are not hidden from a direct named read. Data isolation is the discriminator column (Property 2), not source separation.
claim("a tenant's listing shows no other tenant's source", listing_leak ==0)claim("the discriminator scopes the rows: none of B's reach A", discriminator_leak ==0)claim("a source with no discriminator is globally readable: A reads every one of B's rows", caveat_visible ==len(b_papers), f"{caveat_visible} of {len(b_papers)}")
✓ a tenant's listing shows no other tenant's source
✓ the discriminator scopes the rows: none of B's reach A
✓ a source with no discriminator is globally readable: A reads every one of B's rows (379 of 379)
50.5 Property 4 — the same recipe, scoped per tenant
The consequence worth measuring directly: the same recipe run under each tenant gives that tenant its own answer, over only its own rows. The recipe is the book’s retrieval measurement — embed the papers, build the same-subject golden, and score it with eval_embeddings — run once inside each tenant’s scope. Each embedding table is built from, and each search reads, only the rows the discriminator lets that tenant see; an unscoped session sees none of them.
2026-10-03T07:45:25.865709Z WARN jammi_kernels::admission: fused-kernel domain check failed; falling back to the eager composition op="attention_block_fused" predicate="head_dim_is_attention_block_fixed_head_dim"
tenant A: precision@10 0.325 over 21 rows / 16 queries
tenant B: precision@10 0.375 over 379 rows / 100 queries
scopes tile the corpus: 21 + 379 = 400
claim("the tenant scopes tile the corpus", a_visible + b_visible ==len(subject),f"{a_visible} + {b_visible} = {len(subject)}")claim("the same recipe answers in each tenant's scope, over that tenant's rows", a_queries >0and b_queries >0,f"precision@10 {a_precision:.3f} for A, {b_precision:.3f} for B")
✓ the tenant scopes tile the corpus (21 + 379 = 400)
✓ the same recipe answers in each tenant's scope, over that tenant's rows (precision@10 0.325 for A, 0.375 for B)
The two numbers differ because the tenants hold different subjects, and some subjects are easier to retrieve than others — but the point is the parity: one recipe, the engine scoping the data per tenant, each tenant getting its own measured answer over rows it alone can see.
The session’s work is done, so it is closed. An embedded engine holds its catalog until close() returns, which is why close() comes before anything removes the directory the catalog lives in.
db.close()
50.6 Property 5 — a discriminator under its own name, on both transports
Property 2’s source happened to name its discriminator tenant_id. A federated source usually does not: it carries customer_id, workspace, organization. The source declares that column once, when it is registered — add_source(..., tenant_column=...) — and the declaration is persisted with the source, so every session and every server replica that reads it scopes it the same way.
The measurement is the one Property 2 made, widened to every verb that reads the source: one shared source whose discriminator is workspace, and for each tenant the rows sql returns, the rows generate_embeddings embeds, and the rows search over that embedding table can reach. It runs twice — in process, and against a jammi-server — because the declaration crosses the wire.
from jammi.testing import LiveServerworkspace_path =f"{work}/papers_by_workspace.parquet"pq.write_table(pa.table({"paper_id": [p["paper_id"] for p in papers],"title": [p["title"] for p in papers],"abstract": [p["abstract"] for p in papers],"workspace": [TENANT_A if p["subject"] in a_subjects else TENANT_B for p in papers],}), workspace_path)def per_verb(db) ->dict:"""Each tenant's view of the shared source through `sql`, `generate_embeddings`, and `search`.""" db.add_source("papers_by_workspace", url=workspace_path, format="parquet", tenant_column="workspace") views = {}for tenant_id, own in ((TENANT_A, a_papers), (TENANT_B, b_papers)):with tenant(db, tenant_id): read = db.sql("SELECT paper_id FROM papers_by_workspace.public.papers_by_workspace" ).column("paper_id").to_pylist() table = db.generate_embeddings( source="papers_by_workspace", model=encoders.text(SCALE), columns=["title", "abstract"], key="paper_id", ) embedded = db.sql(f'SELECT _row_id FROM "jammi.{table}"').column("_row_id").to_pylist() hits = db.search("papers_by_workspace", row_key=own[0], k=len(subject), select=["paper_id"]).column("paper_id").to_pylist() other =set(subject) -set(own) views[tenant_id] = {"sql rows": len(read), "embedded rows": len(embedded), "search reach": len(hits),"rows of the other tenant": len((set(read) |set(embedded) |set(hits)) & other), }return viewswith jammi.connect(f"file://{tempfile.mkdtemp()}") as local_db: in_process = per_verb(local_db)with LiveServer(tempfile.mkdtemp()) as server, jammi.connect(server.endpoint) as remote_db: served = per_verb(remote_db)for name, tenant_id, own in (("A", TENANT_A, a_papers), ("B", TENANT_B, b_papers)):print(f"tenant {name} owns {len(own)} papers")for measure in in_process[tenant_id]:print(f" {measure:<26} in process {in_process[tenant_id][measure]:>5}"f" over the wire {served[tenant_id][measure]:>5}")
tenant A owns 21 papers
sql rows in process 21 over the wire 21
embedded rows in process 21 over the wire 21
search reach in process 21 over the wire 21
rows of the other tenant in process 0 over the wire 0
tenant B owns 379 papers
sql rows in process 379 over the wire 379
embedded rows in process 379 over the wire 379
search reach in process 379 over the wire 379
rows of the other tenant in process 0 over the wire 0
claim("the declaration scopes both transports identically", served == in_process)for tenant_id, own in ((TENANT_A, a_papers), (TENANT_B, b_papers)): view = in_process[tenant_id] claim(f"tenant {tenant_id[:8]}… reads none of the other tenant's rows, through every verb", view["rows of the other tenant"] ==0) claim(f"and sql, embedding and search all stay within its own {len(own)} rows", view["sql rows"] == view["embedded rows"] ==len(own) and view["search reach"] <=len(own))
✓ the declaration scopes both transports identically
✓ tenant aaaaaaaa… reads none of the other tenant's rows, through every verb
✓ and sql, embedding and search all stay within its own 21 rows
✓ tenant bbbbbbbb… reads none of the other tenant's rows, through every verb
✓ and sql, embedding and search all stay within its own 379 rows
Every verb reads the source through the same scan, so the one declaration scopes all of them: generate_embeddings embeds only the tenant’s rows, so the table search ranks holds nothing of the other tenant’s. A row whose workspace is empty belongs to no tenant and is read by every tenant, as a tenant_id-tagged row with no tenant is. A declaration the source cannot honour — a column it does not have, or a second discriminator beside its own tenant_id — is refused when the source is registered, never at a tenant’s first query.
50.7 What this chapter does not claim
The engine isolates at the catalog listing and at a discriminator-column scan rewrite — over a tenant_id column or the column a source declared when it was registered. It does not authenticate, and a discriminator-less source is globally readable — the caveat is measured (Property 3), not glossed. Tenant isolation as a complete access-control story is built above the engine (a discriminator column on every tenant-scoped table, or a Flight SQL / gRPC interceptor that binds the scope from an authenticated principal). What the engine guarantees — and what this chapter measures as hard zeros and a positive caveat count — is exactly those two layers and that one honest limit.