Skip to main content

What is the forget operation

forget is the delete entry point of the memory API. It removes memory at the scope you name and keeps the stores consistent with each other.

What happens under the hood

Removes memory: a whole dataset, a specific data item, or everything. Cascades across the relational, graph, and vector backends and file storage. rustdoc: api::forget. Deleting a data item removes what no other data item still claims in the ownership ledger: an entity, an entity type or a chunk goes with the last document that produced it (or, for an entity or ontology edge, reached it through an ontology lookup). An edge is counted by its (source, target, relationship) triple and goes with the last document that produced it even when both its endpoints stay — an is_a edge with the last document that declared that entity with that type, a semantic edge with the last document that extracted it — and its EdgeType point goes once no surviving edge produces its text. Only a per-document ledger row says no other document holds an edge: an edge only an older or Python-written row names (one row per edge, its first writer’s) leaves the graph only with an endpoint. Ledger rows with a nil data_id, which databases written by earlier releases hold for every entity type and structural edge, still claim their artifact until its dataset is deleted; re-cognifying the data does not remove them. A delete does not lock against a running cognify of the same data.

What you can forget

The Rust API takes a ForgetTarget (cognee::api::forget): A dataset is named by DatasetRef::Name or DatasetRef::Id. Either way it must be the owner’s dataset in the caller’s tenant: a name never reaches a dataset in another tenant, and an id of another owner’s dataset fails as Dataset <id> not found, the same answer as an unknown id. The resolved dataset is then deleted by id. forget is a thin wrapper over DeleteService (cognee-delete) and always deletes in soft mode: the data, its chunks and their graph and vector entries are removed, but entity nodes left orphaned by the deletion are not swept. To sweep them, use delete in hard mode (cognee-cli delete --mode hard, or DeleteMode::Hard on DeleteService). The returned ForgetResult carries a target label and the DeleteResult. Forgetting a code repository row, or a dataset that holds one, also cleans up its folders on disk: the dataset’s cluster snapshot (<repo>/.enola-<dataset_id>) is removed from the repository, and a clone cognee made that no remaining row points at is removed, together with that repository’s other branch clones beside it that no row names (a re-add on another branch moves the URL’s one row to that branch’s clone and leaves the old clone until then). A directory you added yourself is never removed. The cleanup runs after the delete has committed; a failure is logged and does not fail the delete. See Configuration: code graph. The CLI’s cognee-cli forget takes --dataset-name (-d), --data-id (needs --dataset-name) or --all, plus --tenant-id. The bindings’ forget takes a target object whose kind is item, dataset or all; any other kind is rejected. The memory-only targets are available from the Rust API only. For a dry-run preview of what a delete would remove, use delete directly.

delete

The lower-level delete behind forget cascades removal of data and datasets across relational → graph → vector → file storage, with a dry-run preview. Entry: DeleteService in cognee-delete; CLI cognee-cli delete, bindings delete*(). In hard mode (DeleteMode::Hard, --mode hard), delete then sweeps the graph for Entity and EntityType nodes left with a single edge, and keeps every node a ledger row still names, a nil-data_id row included. A degree-one node another document claims is not an orphan: an ontology class such as organization, whose only edge is its is_a, or a type a surviving entity still has. What the sweep removes is a node no ledger row names, such as one in a graph written before the ledger. A type or ontology class only a nil row claims stays until its dataset is deleted. Soft delete runs no sweep.
Earlier, the hard sweep kept only entity types a document still claimed, so hard-deleting one document could remove another document’s ontology class entities. Custom DeleteDb implementations must rename get_node_slugs_owned_by_data to get_claimed_node_slugs, which now also counts nil-data_id rows.

Datasets

The scope forget works in

Remember

Store memory

Operations

Every operation and interface