Skip to main content

LEAI โ€” Oracle Database Intelligence & Documentation Engine

LEAI is a reverse engineering, impact analysis, and documentation engine for Oracle Database, specifically designed to power Retrieval-Augmented Generation (RAG), LLMs, and software engineers maintaining complex enterprise database ecosystems.


๐Ÿ“Œ What Is It?

Enterprise Oracle databases accumulate years of business rules scattered across hundreds of tables, views, triggers, and massive PL/SQL packages (3,000 to 10,000+ lines of code).

Enabling developers or AI assistants to reliably understand such environments is challenging due to three main issues:

  1. Token Inefficiency & Hallucinations: Sending entire monolithic packages into an LLM context is expensive, slow, and triggers attention degradation ("Lost in the Middle").
  2. Hidden Dependencies: Altering a single column can silently break triggers, views, and procedures across multiple schemas.
  3. Synonyms and Aliases: Stored procedures frequently access tables via private or public synonyms (PUBLIC SYNONYM), creating the false impression that referenced objects do not exist or belong elsewhere.

LEAI solves this by extracting the Oracle data dictionary, constructing a cross-schema dependency graph, and formatting the technical context specifically for humans and LLMs.


โš™๏ธ How It Works

LEAI operates via a 3-stage decoupled pipeline:

 [Oracle Database]
       โ”‚
       โ–ผ (leai extract)
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ 1. RAW JSON โ”‚ โ”€โ”€> Pure technical dictionary snapshot (DDL, columns, types, PKs, FKs, Synonyms).
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚
       โ–ผ (leai annotate / leai enrich)
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ 2. YAML     โ”‚ โ”€โ”€> Editable business annotations (descriptions, rules, tags). Preserves human
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     documentation and allows AI to fill missing stubs without overwriting.
       โ”‚
       โ–ผ (leai compile / leai trace)
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚ 3. DOCS     โ”‚ โ”€โ”€> Markdown with YAML Frontmatter + Mermaid.js lineage diagrams + structured
 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     chunks for Vector DBs (pgvector, Chroma, Qdrant).

Core Technologies & Internal Mechanics:

  • Multi-Level Lineage Tracing (trace): Identifies upstream dependencies and downstream consumers with configurable depth (--depth N), automatically computing change risk levels (LOW, MEDIUM, HIGH, CRITICAL).
  • Transparent Synonym & Dblink Resolution: Resolves ALL_SYNONYMS and PUBLIC SYNONYMS directly to their underlying physical target objects, including remote database links (@dblink).
  • PL/SQL Semantic Compression: When querying a specific procedure (TEST_PROC) inside a 10,000-line package, LEAI surgically extracts only the requested subprogram body and produces a lightweight signature skeleton of the rest of the package, reducing token consumption by up to 95%.
  • Dynamic Contextual RAG (ask & chat): Automatically detects database entities mentioned in user prompts, executes on-the-fly dependency tracing, and delivers a surgical, noise-free context payload to the LLM.
  • Native Multi-Provider AI Support: Direct HTTPS REST integration with OpenAI (ChatGPT), Google Gemini, Anthropic Claude, DeepSeek, Qwen, Kimi, and Ollama (local & free) without heavy external dependencies.

๐Ÿš€ Quickstart: Using LEAI in Any Project

You don't need to clone the repository. You can use LEAI as a standalone CLI tool in any folder in 3 simple steps:

Step 1: Install LEAI via pip or uv

# Using standard pip
pip install leai

# Or using uv tool (isolated global CLI)
uv tool install leai

Step 2: Initialize your project directory

Create a working directory for your database documentation and enter it:

mkdir my-database-docs
cd my-database-docs

Create a leai.yml file in that folder:

# Oracle connection string (supports environment variables ${VAR})
dsn: "oracle://${DB_USER}:${DB_PASS}@${DB_HOST}:1521/${DB_SERVICE}"

# Schemas integrated into your ecosystem graph
schemas:
  - HR
  - FINANCE
  - CORE

# Output directories
rawPath: "./raw"                  # Raw JSON technical snapshots
annotationsPath: "./annotations"  # Business annotations in YAML
docPath: "./docs"                  # Final Markdown docs for RAG

# AI Provider Configuration (Optional - for enrich, ask, and chat)
ai:
  default_provider: "openai"      # openai, gemini, anthropic, deepseek, qwen, kimi, ollama
  temperature: 0.2
  providers:
    openai:
      api_key: "${OPENAI_API_KEY}"
      model: "gpt-4o-mini"
    gemini:
      api_key: "${GEMINI_API_KEY}"
      model: "gemini-1.5-flash"
    anthropic:
      api_key: "${ANTHROPIC_API_KEY}"
      model: "claude-3-5-sonnet-20241022"
    ollama:
      base_url: "http://localhost:11434/v1"
      model: "llama3.1"

Step 3: Run and Explore!

That's it! You can now run LEAI commands directly in your folder:

# 1. Extract technical metadata from Oracle into raw/
leai extract

# 2. Start an interactive AI Copilot chat session about your database
leai chat

# 3. Analyze impact and trace a specific table with Mermaid diagrams
leai trace EMPLOYEES --depth 2

# 4. Auto-enrich business rules using AI without overwriting manual notes
leai enrich

# 5. Compile everything into clean Markdown files in docs/
leai compile

๐Ÿ“– CLI Command Reference

1. leai (or leai generate)

Executes the full pipeline: extracts technical snapshots from Oracle, synchronizes business annotation stubs, and compiles final Markdown docs.

Parameter / Flag Type Description
-c, --config PATH Option Path to the configuration file (Default: leai.yml).
-t, --object-type TEXT Option Filter specific object types (e.g., -t tables -t views -t packages).
leai
leai generate -t tables -t packages --config prod.yml

2. leai extract

Connects to Oracle and extracts raw JSON technical snapshots into the raw/ directory.

Parameter / Flag Type Description
-s, --schema TEXT Option Extract only a specific schema.
-t, --object-type TEXT Option Filter object types to extract.
-c, --config PATH Option Path to leai.yml.
leai extract
leai extract -s HR -t tables -t views

3. leai annotate

Reads JSON snapshots from raw/ and generates/synchronizes YAML stubs in annotations/, preserving existing manual documentation (Offline Mode).

Parameter / Flag Type Description
-t, --object-type TEXT Option Synchronize only specific object types.
-c, --config PATH Option Path to leai.yml.
leai annotate
leai annotate -t tables

4. leai compile

Recompiles the entire Markdown documentation in docs/ by merging raw/ and annotations/ without connecting to the database.

Parameter / Flag Type Description
-t, --object-type TEXT Option Compile only specific object types.
-c, --config PATH Option Path to leai.yml.
leai compile
leai compile -t views

5. leai trace <OBJECT>

Generates deep impact analysis, terminal hierarchical trees, change risk calculations, and Mermaid.js lineage dossiers.

Parameter / Flag Type Description
OBJECT Required Argument Name of the table, view, procedure, or synonym to trace (e.g., EMPLOYEES).
-d, --depth INT Option Max graph traversal depth (Default: 1 for direct, 2+ for multi-level).
--rag-json, --rag Flag Also exports structured JSON chunks for Vector DB ingestion.
--offline Flag Resolves dependencies locally from raw/ snapshots without connecting to Oracle.
-s, --schema TEXT Option Schema of target object (searches all configured schemas if omitted).
-o, --output PATH Option Custom file path for the generated Markdown dossier.
-c, --config PATH Option Path to leai.yml.
# Multi-level lineage trace (Depth 2)
leai trace EMPLOYEES --depth 2

# Offline mode with RAG JSON chunk export
leai trace EMPLOYEES --offline --depth 2 --rag-json

6. leai enrich

Uses AI (LLMs) to analyze DDLs and PL/SQL code, automatically generating business rules and column descriptions in annotations/ with real-time progress bars.

Parameter / Flag Type Description
-o, --object-name TEXT Option Specific object name to enrich (e.g., -o EMPLOYEES).
-p, --provider TEXT Option AI provider (openai, gemini, anthropic, deepseek, qwen, kimi, ollama).
-m, --model TEXT Option Model identifier (e.g., gpt-4o-mini, gemini-1.5-flash, claude-3-5-sonnet-20241022).
--overwrite Flag Forces regeneration of existing descriptions and comments.
-t, --object-type TEXT Option Filter object types to enrich (e.g., -t tables -t packages).
-c, --config PATH Option Path to leai.yml.
# Enrich using default provider
leai enrich

# Enrich using Google Gemini or Anthropic Claude
leai enrich --provider gemini --model gemini-1.5-flash
leai enrich --provider anthropic --model claude-3-5-sonnet-20241022

# Enrich a single table with forced overwrite
leai enrich -o EMPLOYEES --overwrite

7. leai ask <QUESTION>

Asks one-off natural language questions answered with dynamic RAG context directly in your terminal.

Parameter / Flag Type Description
QUESTION Required Argument The question regarding database structure, dependencies, or business rules.
-p, --provider TEXT Option AI provider to use.
-m, --model TEXT Option Model identifier to use.
-c, --config PATH Option Path to leai.yml.
leai ask "Which views or stored procedures query the EMPLOYEES table?"
leai ask "How does the payroll calculation workflow operate?" --provider gemini

8. leai chat

Launches an interactive multi-turn terminal chat session with persistent conversation memory and cumulative graph context.

Parameter / Flag Type Description
-p, --provider TEXT Option AI provider to use.
-m, --model TEXT Option Model identifier to use.
-c, --config PATH Option Path to leai.yml.
leai chat
leai chat --provider anthropic --model claude-3-5-sonnet-20241022
leai chat --provider ollama --model llama3.1

๐ŸŽฎ Interactive In-Session Commands:

  • /clear: Clears conversation history and active entity memory.
  • /save [file.md]: Exports the complete transcript and generated scripts into a Markdown file.
  • /help: Displays available commands.
  • /exit or /quit: Closes the chat session.

9. leai changes

Audits and lists recently created or modified database objects (via Oracle's LAST_DDL_TIME).

Parameter / Flag Type Description
-d, --days INT Option Number of trailing days to audit (Default: 7).
-u, --user TEXT Option Filter by modifying user / schema (e.g., -u HR).
-s, --schema TEXT Option Target schema.
-t, --object-type TEXT Option Filter object types.
-c, --config PATH Option Path to leai.yml.
# Objects altered in the last 15 days
leai changes -d 15

# Filter by schema
leai changes -d 30 -u HR

๐Ÿ“ Directory Structure

my_project/
โ”œโ”€โ”€ leai.yml
โ”œโ”€โ”€ raw/                      <-- Raw JSON snapshots extracted from Oracle
โ”‚   โ””โ”€โ”€ HR/
โ”‚       โ”œโ”€โ”€ tables/
โ”‚       โ”œโ”€โ”€ views/
โ”‚       โ”œโ”€โ”€ synonyms/
โ”‚       โ””โ”€โ”€ code_objects/
โ”œโ”€โ”€ annotations/              <-- YAML business rules & annotations (editable)
โ”‚   โ””โ”€โ”€ HR/
โ”‚       โ”œโ”€โ”€ tables/
โ”‚       โ””โ”€โ”€ code_objects/
โ””โ”€โ”€ docs/                     <-- Final compiled Markdown for LLMs, RAG, and humans
    โ””โ”€โ”€ HR/
        โ”œโ”€โ”€ tables/
        โ”œโ”€โ”€ dossiers/         <-- Impact dossiers generated by leai trace
        โ””โ”€โ”€ code_objects/

๐Ÿงช Automated Testing

To run the complete automated test suite:

python -m unittest discover tests

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leai-0.1.1.tar.gz (57.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leai-0.1.1-py3-none-any.whl (51.8 kB view details)

Uploaded Python 3

File details

Details for the file leai-0.1.1.tar.gz.

File metadata

  • Download URL: leai-0.1.1.tar.gz
  • Upload date:
  • Size: 57.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for leai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6de1b4604045e89ad42711634242b4b931b1816de8e56ac52923366f16a998f9
MD5 32d13867b30c3ff608a189575fecf3e1
BLAKE2b-256 9251c43e52f9d7b02554cec5cc40c821c51ff250b0c8660fe21aa96b0beaa93e

See more details on using hashes here.

File details

Details for the file leai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: leai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 51.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for leai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97db915f9b2caa43d4ae17322d483c8a56726c2c91c71fea6759d4d0d54cc888
MD5 76c074a5f7283113611b3e7c58eba24b
BLAKE2b-256 1bb591ae219533dab3416b44fb8a650aa615e0b81fb040a34cef6fd37c2d6c9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page