Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 10.4 — Keeping Tenants Apart
RAG and Vector Search · Example 1 of 1

The same question, two tenants, two cache keys

Retrieval is isolated in both runs. Only the cache key differs, and only one run leaks.

When one system serves many customers (tenants), no customer may ever see another's data. Isolation must hold in the index, and also in caches, logs, queues and every other place data is remembered.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write cache_key(tenant, question) that returns the tenant, a bar, and the question's lower-case words joined by single spaces. Print the key for two tenants asking the same question, and show that differently capitalised repeats from one tenant share a key.

02

Write no_cross_tenant(answers) where answers maps tenant to answer text and a canary dict maps tenant to a unique phrase. Return the tenants whose answer contains another tenant's canary.

Explain it without notes

01

What is a tenant, and why is cross-tenant leakage more serious than leakage between users of one organisation?

02

Compare a shared index with a tenant filter to an index per tenant.

03

Explain how a cache can leak between tenants even when retrieval is perfectly isolated.

04

List five places besides the index that need tenant isolation.

The same question, two tenants, two cache keys
Sign in to run this example in your browser.

Expected output

cache key = question only
  acme  miss  A ride cancelled at least 2 hours before its start time is refunded in full.
  zippy hit   A ride cancelled at least 2 hours before its start time is refunded in full.
  zippy hit   A ride cancelled at least 2 hours before its start time is refunded in full.
cache key = tenant + question
  acme  miss  A ride cancelled at least 2 hours before its start time is refunded in full.
  zippy miss  A ride cancelled at least 24 hours before its start time is refunded in full.
  zippy hit   A ride cancelled at least 24 hours before its start time is refunded in full.