Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Partitions & scopes

How Telys partitions a collection by a single key column, why partition_by is never composite, and how scope_key composes one string key from several parts.

A collection is split into partitions by a single key column you name at create time. Partitions give isolation (one tenant or user can't see another's records) and speed (a scoped search walks only the matching partition). The sharp edge: partition_by is not composite — it names exactly one physical column. For a compound scope like tenant + user, compose a single string key with scope_key(...).

What partition_by does

partition_by names the physical partition-key column for the whole collection. Every record's metadata must carry a value under that name; the runtime groups records by it and can restrict a search to one value.

from telys import Telys

db = Telys("./memory")
col = db.create_collection("notes", dim=384, partition_by="scope")
# every record now carries a "scope" value; searches can be pinned to one scope

partition_by is a single column — not composite

Pass a list or tuple to partition_by and Telys uses only the first element as the physical key. It is not a composite key — the rest are silently ignored.

# WRONG — looks composite, is not. Only "tenant_id" is used.
col = db.create_collection("docs", dim=384, partition_by=["tenant_id", "user_id"])

Compose one key with scope_key

scope_key(*parts) joins its arguments into one string with the unit-separator byte \x1f as delimiter. That byte is not something users type, so it won't collide with your data — a safe, reversible compound key.

scope_key is available as the top-level import above and as a handle method (db.scope_key(...)); they behave identically. The idiom: partition by a single column (say "scope") and store a composed key in that column on every record.

Searching and listing within a scope

To keep a query inside one partition, pass where= with an Eq on the partition column (or a single-key dict). Only records whose partition key matches are considered:

The same filter scopes an id listing:

Eq (or a single-key dict) is the whole filter surface. scope_key is deterministic, so Eq("scope", scope_key(...)) matches exactly the records you added with that key — reconstruct the key the same way when you query.

Why partition at all

Benefit
What it buys you

Tenant / user isolation

A scoped search can only return records from that scope — a hard boundary for multi-tenant memory.

Faster scoped search

A partitioned query walks only the matching partition, not the whole collection.

Cleaner lifecycle

You can list (ids) or reason about one scope's records without scanning everything.

Choose the partition column by your unit of isolation: one tenant → partition_by="tenant_id"; one user within a tenant → partition_by="scope" with scope_key(tenant, user); one agent session → scope_key(agent, session). The partition key is fixed for the collection's lifetime, so match the granularity to how you will query.

Next steps

Last updated

Was this helpful?