> ## Documentation Index
> Fetch the complete documentation index at: https://developer.kodexa.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Document Commands

> Reference for the kdx document command suite for working offline with local KDDB files: inspecting, searching, annotating, and extracting structured data.

The `kdx document` command provides a comprehensive set of tools for inspecting, searching, annotating, and extracting structured data from local Kodexa documents (KDDB files). These commands work offline without requiring a connection to the Kodexa platform.

## What are KDDB Files?

KDDB (Kodexa Document Database) files are SQLite-based document containers that store:

* **Document structure** - Hierarchical content nodes with types and content
* **Metadata** - Document properties like UUID, version, and custom fields
* **Tags** - Annotations on content nodes for extraction workflows
* **Data objects** - Structured extracted data with attributes
* **Native files** - Embedded binary files (PDFs, images, etc.)
* **Audit trail** - Full revision history of data changes

## Reading & Analysis

Commands for understanding document content without modifying anything.

<CardGroup cols={2}>
  <Card title="Info" icon="circle-info" href="/guides/kdx-cli/document/info">
    Document summary with metadata and statistics
  </Card>

  <Card title="Stats" icon="chart-bar" href="/guides/kdx-cli/document/stats">
    Detailed statistics and node type breakdown
  </Card>

  <Card title="Text" icon="file-lines" href="/guides/kdx-cli/document/text">
    Extract readable text with page markers
  </Card>

  <Card title="Grep & Lines" icon="magnifying-glass" href="/guides/kdx-cli/document/query">
    Search content with regex and retrieve lines
  </Card>

  <Card title="Find" icon="filter" href="/guides/kdx-cli/document/find">
    Multi-criteria search (text, type, page, region)
  </Card>

  <Card title="Locate" icon="location-dot" href="/guides/kdx-cli/document/locate">
    Find nodes with match positions for tagging
  </Card>

  <Card title="Node" icon="circle-nodes" href="/guides/kdx-cli/document/node">
    Inspect a single node by ID
  </Card>
</CardGroup>

## Structure & Metadata

Commands for inspecting document structure, annotations, and spatial layout.

<CardGroup cols={2}>
  <Card title="Print & Select" icon="tree" href="/guides/kdx-cli/document/structure">
    Tree view and selector queries
  </Card>

  <Card title="Tags" icon="tags" href="/guides/kdx-cli/document/tags">
    List all tags with counts
  </Card>

  <Card title="Audit" icon="clock-rotate-left" href="/guides/kdx-cli/document/audit">
    Revision history and change tracking
  </Card>

  <Card title="Delta" icon="code-compare" href="/guides/kdx-cli/document/delta">
    Inspect delta binary files to see what changed
  </Card>

  <Card title="Spatial" icon="vector-square" href="/guides/kdx-cli/document/spatial">
    Bounding box queries and region search
  </Card>

  <Card title="Native Files" icon="file-pdf" href="/guides/kdx-cli/document/native-files">
    List and extract embedded files
  </Card>

  <Card title="External Data" icon="database" href="/guides/kdx-cli/document/external-data">
    Manage external data key-value store
  </Card>

  <Card title="Metadata" icon="sliders" href="/guides/kdx-cli/document/metadata">
    View and modify document metadata
  </Card>
</CardGroup>

## Data & Tagging

Commands that modify the document by adding tags, creating data objects, and setting attributes.

<CardGroup cols={2}>
  <Card title="Data" icon="database" href="/guides/kdx-cli/document/data">
    Create and inspect data objects and attributes
  </Card>

  <Card title="Tag" icon="tag" href="/guides/kdx-cli/document/tag-cmd">
    Annotate content nodes with tags
  </Card>
</CardGroup>

## Agentic Workflows

<Card title="Agentic CLI Use" icon="robot" href="/guides/kdx-cli/document/agentic-use">
  How AI agents use `kdx document` commands to analyze and annotate documents programmatically. Includes end-to-end workflow examples and best practices.
</Card>

## Quick Start

### Explore a Document

```bash theme={null}
# Get overview
kdx document info invoice.kddb

# Check structure
kdx document print invoice.kddb --depth 3

# Read page content
kdx document text invoice.kddb --pages 1:3
```

### Search and Annotate

```bash theme={null}
# Find content
kdx document locate invoice.kddb --pattern "\$[\d,]+\.\d{2}" --type word

# Tag a node
kdx document tag invoice.kddb --node-id 245 --name "invoice/amount"

# Create structured data
kdx document data create invoice.kddb --path "INVOICE"
kdx document data set-attribute invoice.kddb \
  --object-id 1 --tag "total" --value "1234.56" --type CURRENCY
```

### Scripting with JSON

```bash theme={null}
# JSON Lines output pipes well with jq
kdx document grep "revenue" report.kddb | jq -r '.content'

# Get stats for scripting
PAGE_COUNT=$(kdx document info report.kddb -o json | jq '.statistics.pageCount')
```

## Output Formats

All document commands support the global `-o` flag:

```bash theme={null}
kdx document info doc.kddb -o json    # JSON output
kdx document info doc.kddb -o yaml    # YAML output
kdx document info doc.kddb -o table   # Table output (default)
```

Search commands (`grep`, `find`, `locate`) output JSON Lines (JSONL) by default for streaming. Use `--pretty` for readable output.
