> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Memory Versioning and History

> How Cognee versions memories for AI agents: version counters and timestamps on every node, superseded facts that stay in the graph, and an opt-in audit ledger with a full revision history.

Cognee keeps the **current state** of memory and records how it changed. Every node carries a `version` counter and `created_at` / `updated_at` timestamps. Conflict review keeps outdated facts in the graph and marks them `superseded` instead of deleting them. An opt-in provenance ledger records when, by whom and in which run each document was stored, and when it was deleted. Cognee does not keep old copies of nodes or documents, so to roll back to an earlier state, export a snapshot first.

## What Cognee keeps

| Layer | What is kept | How you read it | On by default |
| - | - | - | - |
| Every node | `version` (starts at 1), `created_at`, `updated_at` | The node's properties | Yes |
| Every fact `cognify()` extracts | Which document, chunk and pipeline run produced it | The `provenance_edge_evidence` table in the relational database | Yes |
| Conflicting facts | Old and new facts side by side, marked `current`, `superseded` or `conflicting`, with an as-of date | Labels in `recall()` context, `FactConflict` nodes | Yes, in every `improve()`, including the automatic one after `remember()` |
| Document revisions | One ledger row per data item, with its content hash, acting user and pipeline run; a new version when the content hash changes, and a tombstone when the item is deleted | `revision_history()`, `cognee-cli provenance history` or `GET /api/v1/provenance/history/{key}` | No, set `PROVENANCE_TRACKING=true` |
| Operations | One record per `remember`, `recall`, `forget` and other operation, with user, outcome and timestamps | `GET /api/v1/activity/pipeline-runs` | Yes |

## Version a memory you write yourself

A [DataPoint](https://docs.cognee.ai/core-concepts/building-blocks/datapoints.md) has a `version` field that starts at 1. Cognee never increments it on its own. Call `update_version()` when a change should count as a new revision, then write the DataPoint back. `update_version()` adds 1 to `version` and sets `updated_at` to now.

Writing a DataPoint with the same id updates the stored node in place. Here `identity_fields` derives the id from `user` and `key`, so a new value for the same preference updates the same node:

```python theme={null}
import asyncio

from cognee.infrastructure.databases.graph import get_graph_engine
from cognee.low_level import DataPoint, setup
from cognee.tasks.storage import add_data_points


class Preference(DataPoint):
    user: str
    key: str
    value: str
    # Same (user, key) gives the same node id, so a rewrite updates one node.
    metadata: dict = {"index_fields": [], "identity_fields": ["user", "key"]}


async def main():
    await setup()
    graph = await get_graph_engine()

    pref = Preference(user="alice", key="editor", value="vim")
    await add_data_points([pref], graph_only=True)

    stored = await graph.get_node(str(pref.id))
    print("v1:", stored["value"], "version", stored["version"])

    pref.value = "helix"
    pref.update_version()  # version += 1, updated_at = now
    await add_data_points([pref], graph_only=True)

    stored = await graph.get_node(str(pref.id))
    print("v2:", stored["value"], "version", stored["version"])


asyncio.run(main())
```

The example needs no LLM or embedding key, because `graph_only=True` skips embeddings. It prints:

```
v1: vim version 1
v2: helix version 2
```

After the second write, the node reads `helix` at version 2. The earlier value `vim` is gone: the version counter tells you the node changed, not what it was before. The [provenance ledger](#keep-an-audit-trail-of-writes) wouldn't keep it either: it records data items (documents), not node values, and a direct `add_data_points()` call outside a pipeline names no data item, so the ledger records nothing for it. To keep earlier values, [export a COGX snapshot](https://docs.cognee.ai/core-concepts/further-concepts/cogx.md) before changing them.

## Update a document

When a document you added with `remember()` changes, use [`cognee.update()`](https://docs.cognee.ai/python-api/update). It replaces the document under the same `data_id`, re-extracts what the edit touched and removes relationships that no longer hold.

Adding the changed file with `remember()` again doesn't create a second copy. If the dataset already holds a file from the same path (or an upload with the same filename) with different content, `remember()` raises `DocumentUpdateRequiredError` and points you to `update()`. Raw text has no file name, so changed text is always added as a new document, with no link to the old one. Adding the exact same content again is a no-op, since Cognee deduplicates documents by content hash.

## Keep outdated facts instead of overwriting them

When new data contradicts what Cognee already knows, conflict review keeps both facts and records which one is current. It runs in every `improve()`, including the automatic one after `remember()`; set `IMPROVE_REVIEW_CONFLICTS=false` to turn it off. In 1.6.5 and earlier it is opt-in: run `improve(review_conflicts=True)` or set `IMPROVE_REVIEW_CONFLICTS=true`. The date that decides which fact is newer comes from the `effective_date` in the document's metadata.

Superseded facts stay in the graph and in `recall()` results. They are sorted after current facts and labelled, for example `[superseded; as of 2025-03-01]`, so the LLM sees what changed and when. The exception is a conflict you settle yourself with `resolve_conflict()`: the facts you reject stay in the graph as superseded, but graph-completion and hybrid search drop them from their context and state the accepted fact instead. See [Review Conflicting Facts](https://docs.cognee.ai/guides/review-conflicts.md) for a walkthrough and [Resolve Conflicting Facts](https://docs.cognee.ai/guides/resolve-conflicts.md) for settling a conflict yourself.

## Keep an audit trail of writes

For an audit trail of which documents were stored, when, by whom and in which run, enable the provenance ledger before the first `cognify()` or `remember()` call:

```bash theme={null}
PROVENANCE_TRACKING=true
```

Cognee then records, in an append-only, hash-chained ledger, every data item that a pipeline stores output for: `cognify()` and `remember()`, chunk-level `update()`, and custom pipelines that run per data item. `improve()` stages run without a data item, so they add no rows. There is one row per data item, keyed `"{dataset_id}:data_item:{data_id}"`, holding its content hash, the acting user's id and the pipeline run. The nodes and edges the item produced are not in the ledger; the graph's source refs link them to the item. When the item's content hash changes, the ledger archives the previous row and versions the live one, instead of overwriting it. When the item is deleted with `forget()` (or a dataset delete), the ledger adds a tombstone instead of removing the row. `revision_history()` returns the versions oldest first, each with `version`, `valid_from`, `valid_until` and `recorded_at`, and `verify_chain()` checks that no row was edited or removed:

```python theme={null}
from cognee.modules.provenance import get_provenance_manager

manager = get_provenance_manager()

history = await manager.revision_history(f"{dataset_id}:data_item:{data_id}")
for entry in history:
    print(entry["version"], entry["valid_from"], entry["valid_until"])

print((await manager.verify_chain())["valid"])
```

The same reads are available over HTTP under `/api/v1/provenance/` and from `cognee-cli provenance`. Those surfaces need read access to the row's dataset, and reading the whole ledger is superuser-only. See [Provenance ledger](https://docs.cognee.ai/python-api/cognify.md#provenance-ledger) for the routes, failure behavior and external anchoring.

## What Cognee doesn't keep

* **Previous node values.** Writing a node again overwrites its properties in the graph and vector stores. The ledger records documents, not node values.
* **Previous document content.** `update()` replaces the document's content and file.
* **Point-in-time queries.** `recall()` reads the current graph. There is no "as of" filter.
* **Deleted data.** [`forget()`](https://docs.cognee.ai/core-concepts/main-operations/forget) deletes permanently. There is no soft delete. With the provenance ledger on, the deleted document's row stays in the ledger with a tombstone, which records that it was deleted. The row doesn't hold the deleted content.

To keep a restorable copy of a dataset at a point in time, export it as a [COGX archive](https://docs.cognee.ai/core-concepts/further-concepts/cogx.md) before making changes:

```python theme={null}
await cognee.export("main_dataset", format="cogx", destination="snapshots/2026-10-14")
```

## Next steps

> [card] [DataPoints](https://docs.cognee.ai/core-concepts/building-blocks/datapoints.md)
>
> Fields, identity and updating custom DataPoints

> [card] [Review Conflicting Facts](https://docs.cognee.ai/guides/review-conflicts.md)
>
> Mark outdated facts as superseded

> [card] [Update](https://docs.cognee.ai/python-api/update.md)
>
> Replace a document under the same id

> [card] [Memory Provenance](https://docs.cognee.ai/guides/memory-provenance.md)
>
> See where each fact came from


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.