Metadata-Version: 2.4
Name: irides-enrichment
Version: 0.2.0
Summary: Metadata and Markdown/OKF enrichment package for Irides: base preformatters, PK/FK wikilinks, database.md catalog linking, and optional AI inference.
Author-email: Gian Andrea Sechi <me@gianandreasechi.com>
License: Apache-2.0
Project-URL: Source Code, https://github.com/GianAndreaSechi/irides/tree/main/packages/enrichment
Project-URL: Homepage, https://www.gianandreasechi.com
Keywords: database,enrichment,wikilinks,okf,markdown,irides,catalog,lineage
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Documentation
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: irides-core>=0.2.0
Requires-Dist: PyYAML>=6.0
Provides-Extra: ai
Requires-Dist: irides-core[ai]; extra == "ai"
Provides-Extra: all
Requires-Dist: irides-core[ai]; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"

# Irides Enrichment (`irides-enrichment`)

Satellite package for **Irides** that enriches database table metadata (`database/*`) and `database.md` overview files with base preformatters, bidirectional path-qualified wikilinks (`[[path|alias]]`), PK/FK linking, and optional AI inference & TL;DRs.

## Features

- **Base preformatter & wikilinks**: Ensures standalone Markdown files include normalized YAML frontmatter and base instance/schema wikilinks without overwriting manual governance/notes.
- **Same-instance PK/FK graph linking**: Connects explicit foreign keys and heuristic implicit foreign keys (`customer_id -> customers.id`) within each `(config, instance)` scope.
- **Opt-in AI relationship & TL;DR discovery (`--use-ai`)**: Discovers missed implicit FKs, deduces missed `database.md` ↔ catalog links, and writes concise TL;DR summaries (strictly validated against real catalog tables).
- **`database.md` catalog correlation**: Links repository `database.md` files (both Prism catalog records and standalone manifests/Markdown) to DB catalog tables and adds reverse `used_by` backlinks on those tables.
- **Dual-mode persistence**:
  - For catalog records: saves into canonical JSON (`FileMetadataStore.save_table_enrichment` / `save_prism_enrichment`) and regenerates Markdown + OKF v0.2 via `FileArtifactStore`.
  - For standalone `.md` files: inserts/updates frontmatter and idempotent `<!-- irides:enrichment:start -->` sections in-place.

## Installation

```bash
pip install irides-enrichment
# With AI support (LiteLLM):
pip install "irides-enrichment[ai]"
# Or together with Irides CLI (`irides enrich`):
pip install "irides-cli[enrichment]"
```

## Usage

```bash
# Enrich the entire Irides catalog (STORAGE_METADATA_DIR + STORAGE_EXPORT_DIR)
irides-enrichment
# or via the unified CLI:
irides enrich

# Also include standalone Markdown / database.md files
irides enrich ./examples/sqlite_demo ./services/checkout/database.md

# Enable AI implicit FK discovery + TL;DR
irides enrich --use-ai

# Dry-run preview
irides enrich --dry-run
```

## CLI Options Reference (`irides-enrichment` / `irides enrich`)

| Flag / Argument | Description |
|---|---|
| `paths` *(positional)* | Optional standalone Markdown files or directories (including `database.md` files) |
| `--metadata-dir` | Override `STORAGE_METADATA_DIR` for canonical Irides JSON catalog |
| `--export-dir` | Override `STORAGE_EXPORT_DIR` for Markdown/OKF catalog exports |
| `--config`, `--target` | Filter catalog DB tables by target config name |
| `--instance` | Filter catalog DB tables by instance name |
| `--no-database` | Skip enriching catalog/standalone DB table docs |
| `--no-database-md` | Skip enriching Prism/standalone `database.md` docs |
| `--use-ai` | Enable opt-in LLM inference for implicit PK/FKs, missed links, and TL;DR |
| `--ai-model` | Override `LITELLM_MODEL` for enrichment AI pass |
| `--dry-run` | Compute enrichment and wikilinks without modifying files |
| `--no-export-markdown` | Disable derived Markdown export updates |
| `--no-export-okf` | Disable derived OKF v0.2 export updates |
| `--no-preformat` | Export full DB table metadata instead of essential deterministic records |

## End-to-End Cycle (`describe` → `prism` → `enrich`)

```bash
export STORAGE_METADATA_DIR=/tmp/irides_demo/metadata
export STORAGE_EXPORT_DIR=/tmp/irides_demo/exports

python3 examples/sqlite_demo/setup_demo.py
irides -c examples/sqlite_demo/irides.yaml describe --target demo_sqlite
irides prism examples/sqlite_demo --output-dir /tmp/irides_demo/prism
irides enrich --dry-run
irides enrich
```

## Python Plugin & Library Usage

```python
from irides_core import load_plugin
from irides_enrichment import EnrichmentOptions, run_enrichment

# Direct import
report = run_enrichment(EnrichmentOptions(use_ai=False))

# Or via irides-core plugin registry (`irides.plugins`)
plugin = load_plugin("enrichment")
report = plugin.run({"use_ai": False})
```

## Async Platform Integration

For asynchronous enrichment runs triggered via REST API (`POST /api/v1/enrichment/run`) or MCP (`enqueue_enrichment`), see [services/worker_enrichment/README.md](https://github.com/GianAndreaSechi/irides/blob/main/services/worker_enrichment/README.md), [services/api/README.md](https://github.com/GianAndreaSechi/irides/blob/main/services/api/README.md), and [infra/README.md](https://github.com/GianAndreaSechi/irides/blob/main/infra/README.md).
