> 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/update-records.md).

# Update records

Replace the contents of existing records with update\_texts, and understand how it differs from add\_texts and upsert\_texts.

`update_texts(texts, ids, metadata)` replaces the content of rows that **already exist**. It re-embeds each text and swaps the stored vector and metadata for the matching external ID, leaving the ID and the live row count unchanged. Use it when every ID is present and you want to correct or refresh its content.

{% hint style="info" %}
`update_texts` embeds text, so the collection needs an attached embedder, and the lexical embedders need the native kernel. A `RuntimeError` means no embedder is attached; an `ImportError` means the kernel is missing. Run `telys runtime verify` — see [Verify your install](https://docs.telys.ai/start-here/verify-install.md).
{% endhint %}

## Choose the right write method

Telys has three text-ingest methods. They differ only in how they treat new versus existing IDs.

| Method         | New IDs     | Existing IDs | Needs embedder |
| -------------- | ----------- | ------------ | -------------- |
| `add_texts`    | inserted    | `KeyError`   | yes            |
| `upsert_texts` | inserted    | replaced     | yes            |
| `update_texts` | not created | replaced     | yes            |

`update_texts` is the strict counterpart of `add_texts`: `add_texts` writes only new IDs, `update_texts` writes only existing ones. For a batch that mixes new and existing IDs, use `upsert_texts` instead — see [Add & upsert records](https://docs.telys.ai/working-with-data/add-and-upsert.md).

## Update existing rows

```python
from telys import Telys
from telys.embedding import AlgentaMultigramEmbedder

telys = Telys("./telys-data")
# "notes" was created with filter_columns=("scope", "topic", "rev"), so those
# keys round-trip through with_metadata=True (see the Expected result below).
col = telys.open_collection("notes", embedder=AlgentaMultigramEmbedder())

col.update_texts(
    texts=["Q3 planning moved to the first week of August."],
    ids=["note-42"],
    metadata=[{"scope": "user:42", "topic": "planning", "rev": 3}],
)
```

The return value is the list of updated external IDs. The metadata you pass **replaces** the previous metadata for that row — it is not merged, so include every field you want to keep.

## Versioned-update semantics

Replacing a row does not overwrite the old vector in place. Telys writes a new version and soft-deletes the previous one, so:

* The **live row count stays the same** — `len(col)` and `ids()` are unaffected by an update.
* Searches immediately return the new content; the superseded version is no longer visible.
* The space held by superseded versions is reclaimed by `compact()`.

After a batch of updates or deletes, run `compact()` to reclaim space, then `save()` to commit. See [Delete & compact](https://docs.telys.ai/working-with-data/delete-and-compact.md) and [Versioning, soft-delete & compaction](https://docs.telys.ai/understand-telys/versioning-soft-delete-compaction.md).

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

## Expected result

An update changes content without changing which IDs are live:

```python
print(len(col))                 # unchanged by the update
print("note-42" in col)         # -> True

hits = col.search_text("August planning", top_k=1, with_metadata=True)
print(hits["ids"][0], hits["metadata"][0])
```

```
1240
True
note-42 {'scope': 'user:42', 'topic': 'planning', 'rev': 3}
```

{% hint style="warning" %}
`update_texts` is local-only; it is **not** available over a [RemoteTelys](https://docs.telys.ai/reference/remote-api.md) connection. `RemoteCollection` exposes `add_texts` and `upsert_texts`, so use `upsert_texts` to replace rows remotely.
{% endhint %}

## 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>Delete &#x26; compact</strong></td><td>Remove rows and reclaim the space updates leave behind.</td><td><a href="https://docs.telys.ai/working-with-data/delete-and-compact.md">Delete &amp; compact</a></td></tr><tr><td><strong>Add &#x26; upsert records</strong></td><td>Write new rows, or new-and-existing in one call.</td><td><a href="https://docs.telys.ai/working-with-data/add-and-upsert.md">Add &amp; upsert</a></td></tr><tr><td><strong>Versioning &#x26; compaction</strong></td><td>How soft-delete and compaction work under the hood.</td><td><a href="https://docs.telys.ai/understand-telys/versioning-soft-delete-compaction.md">Versioning &amp; compaction</a></td></tr></tbody></table>
