> 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

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](/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](/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](/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="/pages/3IabEB7rmGWO2uCD2t8X">/pages/3IabEB7rmGWO2uCD2t8X</a></td></tr><tr><td><strong>Update records</strong></td><td>Replace existing rows instead of removing them.</td><td><a href="/pages/IEihttmP8r8zxpFDyjgd">/pages/IEihttmP8r8zxpFDyjgd</a></td></tr><tr><td><strong>Versioning &#x26; compaction</strong></td><td>Why deletes are soft and what compaction reclaims.</td><td><a href="/pages/6OLpYuGrmMrjReVdWDhE">/pages/6OLpYuGrmMrjReVdWDhE</a></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.telys.ai/working-with-data/delete-and-compact.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
