<!-- GENERATED by scripts/build-docs.mjs from the live Commander tree (src/cli/program.ts). Do not edit by hand. -->

# pai kg

> Temporal knowledge graph: backfill, query, list, stats

## Synopsis

```
pai kg <subcommand> [options]
```

## Subcommands

| Command | Description |
|---------|-------------|
| [`pai kg backfill`](#pai-kg-backfill) | Populate the KG from existing session notes (idempotent) |
| [`pai kg query`](#pai-kg-query) | Query KG triples by subject, predicate, object, time, or project |
| [`pai kg list`](#pai-kg-list) | List currently-valid triples |
| [`pai kg stats`](#pai-kg-stats) | Show triple counts and contradiction count |

### pai kg backfill

Populate the KG from existing session notes (idempotent)

**Options**

| Option | Description | Default |
|--------|-------------|---------|
| `--project <slug>` | Restrict backfill to a single project |  |
| `--limit <n>` | Maximum number of notes to process |  |
| `--dry-run` | List notes that would be processed without extracting |  |


### pai kg query

Query KG triples by subject, predicate, object, time, or project

**Options**

| Option | Description | Default |
|--------|-------------|---------|
| `--subject <s>` | Filter by subject |  |
| `--predicate <p>` | Filter by predicate |  |
| `--object <o>` | Filter by object |  |
| `--as-of <date>` | Point-in-time query (YYYY-MM-DD or ISO 8601) |  |
| `--project <slug>` | Restrict to a project slug |  |
| `--json` | Output raw JSON |  |


### pai kg list

List currently-valid triples

**Options**

| Option | Description | Default |
|--------|-------------|---------|
| `--project <slug>` | Restrict to a project slug |  |
| `--limit <n>` | Maximum triples to print | `50` |


### pai kg stats

Show triple counts and contradiction count


## Examples

```bash
# Build the temporal knowledge graph from existing memory
pai kg backfill

# Ask the graph about an entity
pai kg query "Talan"

# List known entities
pai kg list

# Graph size and entity-type breakdown
pai kg stats
```

## See also

[`pai audit`](audit.md) · [`pai backup`](backup.md) · [`pai clear-names`](clear-names.md) · [`pai config`](config.md) · [`pai daemon`](daemon.md) · [`pai db`](db.md) · [`pai end`](end.md) · [`pai help`](help.md) · [`pai identity`](identity.md) · [`pai launch`](launch.md) · [`pai mcp`](mcp.md) · [`pai memory`](memory.md) · [`pai notify`](notify.md) · [`pai observation`](observation.md) · [`pai obsidian`](obsidian.md) · [`pai pause`](pause.md) · [`pai project`](project.md) · [`pai projects`](projects.md) · [`pai registry`](registry.md) · [`pai restore`](restore.md) · [`pai session`](session.md) · [`pai sessions`](sessions.md) · [`pai setup`](setup.md) · [`pai shell-init`](shell-init.md) · [`pai skill`](skill.md) · [`pai task`](task.md) · [`pai topic`](topic.md) · [`pai update`](update.md) · [`pai worker`](worker.md) · [`pai zettel`](zettel.md)

Run `pai help <area>` to read any of these in the terminal.

