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

# Schema Inventory

> Summarize your knowledge graph by semantic type with per-type counts, samples, and relationships

`get_schema_inventory()` summarizes your knowledge graph by semantic type instead of rendering every node. It returns deterministic per-type instance counts, a bounded set of representative sample names, and the relationship distribution between types — useful for understanding the shape of a graph at a glance or for driving custom dashboards.

**Before you start:**

* Complete [Quickstart](getting-started/quickstart) to understand basic operations
* Have some remembered data or any existing knowledge graph

## Code in Action

```python theme={null}
import cognee

# Data must be remembered/loaded into cognee before building the inventory,
# e.g. via cognee.remember() or cognee.add() + cognee.cognify().
inventory = await cognee.get_schema_inventory(
    dataset=None,           # optional dataset UUID to scope the graph databases
    samples_per_type=5,     # max sample instance names per type (default 5)
    sort="count",           # "count" (default, descending) or "none" (discovery order)
)
```

Each list entry is a dict describing one semantic type:

```python theme={null}
{
    "type": "Person",           # semantic type name
    "count": 42,                 # total instances of this type
    "samples": ["Carlos", ...],  # up to samples_per_type representative names
    "sample_size": 5,            # number of names actually returned
    "relationships": [           # aggregated edges involving this type
        {"to_type": "Broker", "relation": "works_at", "count": 12},
        # incoming edges are shown with a "← " prefix on the relation name
    ],
}
```

## How types are resolved

Extracted entities are grouped under their resolved semantic type (the `EntityType` reached via the `is_a` edge) rather than the generic `"Entity"` label, and the internal `EntityType` taxonomy nodes are not surfaced as their own group. Passing a negative `samples_per_type`, or a `sort` value other than `"count"`/`"none"`, raises `ValueError`.

## Over HTTP

The same projection is available at `GET /api/v1/schema/inventory` (query params `dataset_id`, `samples_per_type`, `sort`). The endpoint is caller-scoped: it returns `403` when the caller is not authorized to read the dataset, and `409` if the inventory cannot be built.

## Full Example

A richer demo builds a representative graph in code — so it runs without an LLM or a graph database — and writes a standalone HTML file with the schema side panel to your home directory:

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

The complete flow — remember data, then summarize the graph by type is in the following example:

<Accordion title="Schema inventory">
  ```python theme={null}
  import asyncio
  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 building the inventory.
      await cognee.remember(
          ["Alice knows Bob.", "NLP is a subfield of CS."],
          self_improvement=False,
      )

      inventory = await cognee.get_schema_inventory(samples_per_type=5, sort="count")

      for entry in inventory:
          print(f"{entry['type']}: {entry['count']} instance(s), samples={entry['samples']}")
          for rel in entry["relationships"]:
              print(f"  {rel['relation']} -> {rel['to_type']} ({rel['count']})")


  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="Memory Provenance" icon="folder-tree" href="/guides/memory-provenance">
    Visualize the ownership and data-flow story behind your memory
  </Card>
</Columns>
