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

> Visualize the ownership and data-flow story behind your memory — tenants, users, agents, datasets, and files

`visualize_memory_provenance()` renders the *ownership and data-flow* story behind your memory — Tenant → User → Agent → Dataset → file, plus agent read/write access and agent-written sessions — to a self-contained HTML file.

**Before you start:**

* Complete [Quickstart](getting-started/quickstart) to understand basic operations
* Have some ingested data (the projection reads the relational database, so no graph backend is required)

## Code in Action

```python theme={null}
import os
import cognee

# Data must be remembered/loaded into cognee before projecting provenance,
# e.g. via cognee.remember() or cognee.add() + cognee.cognify().
dest = os.path.join(os.path.expanduser("~"), "memory_provenance.html")

await cognee.visualize_memory_provenance(
    destination_file_path=dest,
    include_memory=False,   # when True, fold in extracted entities/relationships
)
```

This projection is read **purely from the relational database** — it does not require the graph backend or an LLM, so it works even when the graph database is unavailable. Set `include_memory=True` to also fold in the extracted entities/relationships (from the relational `nodes`/`edges` tables) and link them back to the files they were extracted from.

## Raw graph data

If you only need the projected graph data (in the same `(nodes, edges)` shape the renderer consumes) rather than HTML, call `get_memory_provenance_graph()`:

```python theme={null}
nodes, edges = await cognee.get_memory_provenance_graph(include_memory=True)
```

## Scoping in multi-tenant deployments

Both functions accept `scope_tenant_ids` and `scope_user_ids` to restrict the projection to a tenant or user. In **multi-tenant deployments you must pass a scope** — an unscoped read returns every tenant's actors, datasets, and files. When neither scope is given the read is global, which is the intended behavior only for single-user / OSS installs where one user owns everything.

## Over HTTP

The HTTP endpoint `GET /api/v1/schema/provenance` (query param `include_memory`) always scopes to the authenticated caller's tenant (or user).

## Full Example

A richer demo drives the production projection against representative records — so it runs without an LLM or a graph database — and writes a standalone HTML file to your home directory:

* [`examples/demos/memory_provenance_demo.py`](https://github.com/topoteretes/cognee/blob/main/examples/demos/memory_provenance_demo.py) → `~/cognee_provenance_demo.html`

The complete flow — remember data, render the provenance HTML, and read the raw projection is in the following code:

<Accordion title="Memory provenance">
  ```python theme={null}
  import asyncio
  import os

  import cognee


  async def main():
      # Prune data and system metadata before running, only if we want "fresh" state.
      await cognee.forget(everything=True)

      # Data must be remembered/loaded into cognee before projecting provenance.
      await cognee.remember(
          ["Alice knows Bob.", "NLP is a subfield of CS."],
          self_improvement=False,
      )

      dest = os.path.join(
          os.path.dirname(__file__), ".artifacts", "memory_provenance.html"
      )
      await cognee.visualize_memory_provenance(destination_file_path=dest)

      # Raw (nodes, edges) projection, folding in the extracted memory.
      nodes, edges = await cognee.get_memory_provenance_graph(include_memory=True)
      print(f"provenance nodes={len(nodes)}, edges={len(edges)}")


  if __name__ == "__main__":
      asyncio.run(main())
  ```
</Accordion>

<Columns cols={2}>
  <Card title="Graph Visualization" icon="network" href="/guides/graph-visualization">
    Render your knowledge graph to an interactive HTML file
  </Card>

  <Card title="Schema Inventory" icon="table" href="/guides/schema-inventory">
    Summarize the knowledge graph by semantic type
  </Card>
</Columns>
