Versioning & compaction
How Telys layers versioned updates and deletes over a sealed base image, why deletes are logical until you compact, and what save() commits.
A Telys collection is not overwritten in place on every write. Your first batch seals a base image; every later batch layers on top as changes — brand-new rows and versioned replacements. Deletes are logical until compact() reclaims their space, and nothing touches disk until save(). Understand this model and the results of search, ids, and len(col) are never a surprise.
The layered model
Think of a collection as a sealed base plus an ordered stack of deltas:
The base is the image written the first time you ingest and
save(). It is the baseline every later change is measured against.Each later batch is layered as deltas. A row whose external id has never been seen is a delta-insert; a row whose id already exists is a versioned-update that supersedes the base (or an earlier delta) for that id.
A delete marks an id as removed from the live set without physically rewriting the base.
Compaction folds the deltas back into a fresh base and drops everything superseded or deleted.
The live set — what queries see — is always "the base, with versioned-updates applied and deleted ids removed."
Which write does what
Every ingest call returns the list of external ids it touched. What happens to an id depends on whether it already exists:
add_texts / add
inserts a new row (delta-insert)
raises KeyError
add_texts yes, add no
upsert_texts / upsert
inserts a new row
replaces the row (versioned-update)
upsert_texts yes, upsert no
update_texts
— targets existing rows
replaces the row (versioned-update)
yes
delete
—
removes the id from the live set
no
add* is strict: it refuses to clobber an existing id, so double-ingestion fails loudly. upsert* is insert-or-replace. update_texts refreshes the vector and payload of an id you know exists.
Soft-delete
delete(ids) removes only the ids present and ignores unknown ones — passing a missing id is not an error. The effect is immediate: a deleted id disappears from ids(), search/search_text results, len(col), and the in operator.
The delete is logical: the row leaves the live set at once, but its bytes in the base slab are not reclaimed until you compact. No query returns it, yet the physical footprint stays until a rewrite.
Compaction
compact() rewrites the collection into a fresh base: versioned-updates are folded in, superseded and deleted rows are dropped, and their space is reclaimed. It does not change what queries return — the live set is identical before and after — it only shrinks and tidies the on-disk representation.
Run compact() after a large batch of upserts or deletes, or on a schedule for long-lived collections. Between compactions, high churn just stacks more deltas over the base — correctness is unaffected, only physical size and scan cost.
Persistence: save() is the commit point
None of the above reaches disk until you call save(). create_collection builds and caches the collection in memory; save() writes the id_map.npy sidecar first and then collection.json last — that final write is the atomic commit point, so a crash mid-save never leaves a half-written collection.json. Only saved collections appear in db.collections().
save() persists the collection's identity and durable state: name, dim, dtype, key_name, filter_columns, the id-map sidecar, telys_version, default_target_recall, applied_tuner, lexical, and the embedder_profile.
Next steps
Last updated
Was this helpful?