> For the complete documentation index, see [llms.txt](https://docs.telys.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.telys.ai/working-with-data/delete-and-compact.md).

# Delete & compact

Remove records with delete, reclaim their space with compact, and commit the result to disk with save.

Removing data from Telys is two steps. `delete(ids)` drops rows from the live set so they stop appearing in searches and listings; `compact()` reclaims the space those deleted and superseded rows held. Finish with `save()` to write the result to disk.

{% hint style="info" %}
These operations run on the signed native runtime. If a call raises `RuntimeNotInstalled`, install and verify it first with `telys login` and `telys runtime verify` — see [Verify your install](https://docs.telys.ai/start-here/verify-install.md).
{% endhint %}

## Delete records — `delete(ids)`

`delete(ids)` removes only the IDs that are currently present. Missing IDs are ignored, so a delete is safe to retry and never raises for a missing ID.

```python
from telys import Telys

telys = Telys("./telys-data")
col = telys.open_collection("notes")   # no embedder needed to delete

before = len(col)
col.delete(["note-3", "note-9"])
after = len(col)

print(before, "->", after)
```

After a delete the IDs are gone from the live set:

```python
"note-3" in col              # -> False
col.ids(where=None)          # no longer lists note-3 or note-9
```

Deleting an ID that is not present is a no-op:

```python
col.delete(["never-existed"])   # ignored, no error
```

## Compact — `compact()`

Deletes and [updates](https://docs.telys.ai/working-with-data/update-records.md) are versioned: a removed or replaced row is soft-deleted rather than erased, so the on-disk footprint does not shrink immediately. `compact()` rewrites the collection to drop those dead rows and reclaim their space.

```python
col.compact()
```

Compaction leaves the live set unchanged — `len(col)` and `ids()` are the same before and after; only storage shrinks. Run it after a batch of deletes or updates, not after every mutation. See [Versioning, soft-delete & compaction](https://docs.telys.ai/understand-telys/versioning-soft-delete-compaction.md) for the full model.

## Commit — `save()`

`delete` and `compact` change the in-memory state; `save()` writes it to disk and is the commit point.

```python
col.save()
```

## Expected result

A delete lowers the live count and drops the IDs from listings; compaction reclaims space without changing the count; `save()` persists it all:

```
1240 -> 1238
False
```

## Next steps

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Snapshots &#x26; persistence</strong></td><td>Save the commit point and take a point-in-time copy.</td><td><a href="https://docs.telys.ai/working-with-data/snapshots-and-persistence.md">Save &amp; snapshots</a></td></tr><tr><td><strong>Update records</strong></td><td>Replace existing rows instead of removing them.</td><td><a href="https://docs.telys.ai/working-with-data/update-records.md">Update records</a></td></tr><tr><td><strong>Versioning &#x26; compaction</strong></td><td>Why deletes are soft and what compaction reclaims.</td><td><a href="https://docs.telys.ai/understand-telys/versioning-soft-delete-compaction.md">Versioning &amp; compaction</a></td></tr></tbody></table>
