> ## 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.

# prune

> Clean up data and system resources

# cognee.prune

Static class with methods for cleaning up Cognee data and system state.

## Methods

### prune.prune\_data()

```python theme={null}
await cognee.prune.prune_data()
```

Removes all raw data files from the file storage backend (local disk or S3,
configured via `DATA_ROOT_DIRECTORY`). Does **not** remove database records —
use `prune_system(metadata=True)` for that.

### prune.prune\_system()

```python theme={null}
await cognee.prune.prune_system(
    graph: bool = True,
    vector: bool = True,
    metadata: bool = False,
    cache: bool = True,
)
```

Cleans up system database resources selectively. Does **not** delete files
from storage — call `prune_data()` first if you also need to wipe raw files.

<ParamField path="graph" type="bool" default="True">Delete all data from the graph database (e.g., Kuzu, Neo4j).</ParamField>
<ParamField path="vector" type="bool" default="True">Delete all data from the vector store (e.g., LanceDB, Qdrant).</ParamField>
<ParamField path="metadata" type="bool" default="False">Delete the relational metadata database (datasets, data records, pipeline state). Defaults to `False` to prevent accidental loss of metadata.</ParamField>
<ParamField path="cache" type="bool" default="True">Clear the cache. This wipes the cache directory (`CACHE_ROOT_DIRECTORY` — e.g. downloaded ontologies and tutorial data) and, when session caching or usage logging is enabled, also prunes the [session cache backend](/core-concepts/sessions-and-caching) (conversation history and usage logs). It does **not** touch graph, vector, or relational data.</ParamField>

<Warning>
  `prune_system` has no permission checks and will wipe **all** graph and vector
  data regardless of which user or dataset it belongs to. Only use it in local
  development or test environments.
</Warning>

<Note>
  **Prune cannot target a single dataset.** Neither `prune_data()` nor
  `prune_system()` accepts a `dataset_id` — both always operate globally across
  every dataset. To remove a single dataset, use
  [`cognee.datasets.empty_dataset(dataset_id)`](/python-api/datasets#datasets-empty-dataset),
  which deletes that dataset's graph content, data records, and the dataset entity
  itself while leaving other datasets untouched. To remove a single data item, use
  [`cognee.datasets.delete_data(dataset_id, data_id)`](/python-api/datasets#datasets-delete-data).
</Note>

## Examples

```python theme={null}
import cognee

# Full reset: remove raw files, databases, and metadata
await cognee.prune.prune_data()           # wipes raw files from disk / S3
await cognee.prune.prune_system(metadata=True)  # wipes graph, vector, relational DB, and cache

# Partial reset: clear graph and vector stores only (keep metadata and files)
await cognee.prune.prune_system(graph=True, vector=True, metadata=False, cache=False)

# Clear only the cache (session history, usage logs, cached files)
await cognee.prune.prune_system(graph=False, vector=False, metadata=False, cache=True)
```

## FAQ

<AccordionGroup>
  <Accordion title="How do I re-cognify data without deleting my PostgreSQL metadata?">
    Keep `metadata=False` (the default) if you want to preserve the relational
    database. But for a true re-cognify of already-processed data, `prune_system()`
    is **not** enough by itself: it clears graph/vector/cache storage, but it does
    not reset the per-data-item `cognify_pipeline` status that incremental
    `cognify()` uses to decide what to skip.

    For the safe rebuild flow, use [`forget(..., memory_only=True)`](/core-concepts/main-operations/forget#forget-only-memory-for-a-dataset-keep-raw-files)
    on the dataset you want to re-process. That preserves raw files, datasets, and
    data records while clearing graph/vector memory and resetting cognify status:

    ```python theme={null}
    # Remove only derived memory for one dataset, keep files + metadata
    await cognee.forget(dataset="my_dataset", memory_only=True)
    await cognee.cognify(datasets="my_dataset")
    ```

    Setting `metadata=True` would delete the datasets, data records, and pipeline
    state from the relational database (PostgreSQL or SQLite), forcing you to
    `add()` your data again before re-cognifying.
  </Accordion>

  <Accordion title="Do I need to prune when switching vector databases?">
    If you switch `VECTOR_DB_PROVIDER`, the new vector store starts empty, so you do
    need to rebuild memory for the datasets you want to query. The safest documented
    flow is dataset-scoped: update `VECTOR_DB_PROVIDER` (see [Vector Stores](/setup-configuration/vector-stores)),
    then clear only the dataset's derived memory and re-cognify it:

    ```python theme={null}
    await cognee.forget(dataset="my_dataset", memory_only=True)
    await cognee.cognify(datasets="my_dataset")
    ```

    This preserves the dataset's files and relational metadata while rebuilding the
    graph and embeddings against the new vector store.

    If you use `prune_system(vector=True, metadata=False)`, remember that it clears
    the vector storage globally but does **not** reset cognify status for existing
    data items, so a plain follow-up `cognify()` may skip them.
  </Accordion>

  <Accordion title="What exactly does cache=True clear?">
    It removes the cache directory (`CACHE_ROOT_DIRECTORY`, holding cached files such
    as downloaded ontologies and tutorial data) and, when session caching or usage
    logging is enabled, prunes the [session cache backend](/core-concepts/sessions-and-caching)
    (conversation history and usage logs). It never deletes graph, vector, or
    relational data, so clearing the cache is safe to combine with any re-cognify
    workflow.
  </Accordion>
</AccordionGroup>
