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 scopepartition_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:
Why partition at all
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?