dataintelligence

module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: Apache-2.0

README

DataIntelligence

CI Go Reference Go Report Card

A governed semantic layer + MCP gateway that makes your data warehouse safe for AI agents.

Point an LLM agent at a raw warehouse and it will, sooner or later, invent a join, pick the wrong grain, multiply a total through a fan-out, choose one of three "revenue" definitions at random, and return a confident wrong number that runs clean. A crash is a gift; a silent wrong answer is the real problem.

DataIntelligence puts a layer between the agent and the warehouse that resolves meaning, compiles fan-out/chasm-safe SQL, enforces governance on every hop, and exposes only governed tools over MCP. Agents ask for a metric by dimensions — never raw SQL.

It is domain-neutral: the engine knows nothing about your business. Your model, sources, and policies are config. examples/meridian/ is one example integration.


What it prevents

The five failure modes of naive text-to-SQL, blocked structurally — not by prompting:

  1. Wrong join — relationships are declared once in a join graph; the compiler only traverses them.
  2. Wrong grain — every measure is pinned to its grain.
  3. Fan-out / chasm — each measure aggregates in its own CTE, then joins. Inflation is impossible by construction.
  4. Ambiguous metric — one metric, one definition; synonyms route to it; RBAC gates who can resolve it.
  5. Silent wrong answer — every metric reconciles to a control query in CI, and answers are graded against a labeled set.

Quickstart (5 minutes)

Try it — seeded warehouse + service, one command
cd deploy/platform
docker compose up --build          # Postgres (seeded) + the service
curl localhost:41900/v1/healthz    # {"status":"ok"}

# a governed query, sliced by region
curl -s -X POST localhost:41900/v1/query -H 'X-DI-Role: finance' \
  -d '{"metrics":["total_revenue"],"group_by":["store_region"]}'
Use it on YOUR warehouse
go install github.com/liliang-cn/dataintelligence/cmd/di@latest

# 1. generate a semantic-model draft from your live schema (heuristic; add LLM_* env to refine)
di model gen -dsn "postgres://user:pass@host:5432/db?sslmode=disable" -out model.yaml
#   -- introspected 9 table(s)
#   -- mode: heuristic · 7 entities, 6 joins, 18 dimensions, 11 metrics · 0 lint note(s)

di model lint -model model.yaml    # review it, then serve

# 2. serve it (REST /v1 + MCP)
DI_DSN="postgres://user:pass@host:5432/db?sslmode=disable" di serve -model model.yaml

# 3. ask in natural language, governed end to end
curl -s -X POST localhost:41900/v1/ask -H 'X-DI-Role: finance' \
  -d '{"question":"total revenue by region"}'
Connect an agent (MCP)

The MCP server exposes list_metrics, get_dimensions, query_metric — and deliberately no run_sql. Point any MCP client at it. For Claude Desktop:

{
  "mcpServers": {
    "dataintelligence": {
      "command": "di",
      "args": ["mcp"],
      "env": { "DI_DSN": "postgres://user:pass@host:5432/db?sslmode=disable" }
    }
  }
}

Architecture

  Agent / app / CLI
        │  natural language
        ▼
  GROUNDING        NL → retrieve metrics (BM25 ⊕ dense ⊕ cross-encoder rerank),
                   few-shot, disambiguate → a typed semantic query (never raw SQL)
        ▼
  SEMANTIC LAYER   entities · dimensions · metrics · join graph
   (semantic-go)   COMPILER: aggregate-to-grain-in-CTE → join → dialect SQL
        ▼                    (Postgres · Snowflake · Databricks)
  WAREHOUSE        database/sql + cost ceiling + row cap + timeout
        ▼
     your warehouse

  GOVERNANCE on every hop:  RBAC · row-level security · column masking ·
                            k-anonymity · per-user identity (OIDC + RFC 8693 OBO)
  OBSERVABILITY:            OpenTelemetry span tree + cost, eval gates, audit
  EXPOSED VIA:              REST /v1  and  MCP (governed tools only)

Build order is load-bearing: meaning first, transport last.

What's in the box

Area Capability Command
Onboarding introspect a warehouse → generate a model draft di model gen
Query governed semantic query → fan-out-safe SQL di query, POST /v1/query
NL ground a question, optionally answer di ask, POST /v1/ground /v1/ask
Dialects same model → Postgres / Snowflake / Databricks SQL di explain -dialect
Governance RBAC, masking, RLS, k-anon, threat-model-as-code di threats
Identity real OIDC/JWT + on-behalf-of to the warehouse di obo, di pentest
Evaluation accuracy gate vs control SQL + LLM judge di nleval
Write-back NL → typed proposal → approve → commit → rollback di propose/approve/revert
Rollout model version registry, canary, auto-rollback di rollout
Service config-driven daemon, REST /v1 + MCP di serve

See docs/DESIGN.md for the full design and deploy/ for Docker / Compose / Helm.

Status

The semantic + grounding + governance + MCP spine is production-grade and measured: the NL eval gate runs a labeled set against hand-written control queries with a per-category accuracy floor, and every metric reconciles in CI. Built on three reusable libraries: semantic-go (the layer + compiler), cortexdb (retrieval), and agent-go / eval-go.

Support & consulting

DataIntelligence is free and open source (Apache-2.0) — use it, fork it, ship it.

If you want help standing it up against your warehouse, modeling contested metrics, wiring it into your agent stack, or hardening governance for production, that's what I do for a living. Open an issue, or reach out: ll_faw@hotmail.com.

License

Apache-2.0.

Directories

Path Synopsis
Package agenttools is the single source of truth for the platform's agent-callable capabilities.
Package agenttools is the single source of truth for the platform's agent-callable capabilities.
Package cache is a result cache keyed by (caller, semantic query).
Package cache is a result cache keyed by (caller, semantic query).
cmd
di command
Command di drives the DataIntelligence platform.
Command di drives the DataIntelligence platform.
Package config is the single boot contract for the DataIntelligence service: one YAML file declares the semantic model, sources, warehouse, governance, and auth, and the daemon starts entirely from it.
Package config is the single boot contract for the DataIntelligence service: one YAML file declares the semantic model, sources, warehouse, governance, and auth, and the daemon starts entirely from it.
Package connectors reads data from sources (and, later, writes to sinks).
Package connectors reads data from sources (and, later, writes to sinks).
Package convo adds conversation memory and multi-metric chaining on top of the grounding + governance + critic stack.
Package convo adds conversation memory and multi-metric chaining on top of the grounding + governance + critic stack.
Package copilot wraps an agent-go agent that drives the platform: given a goal, the LLM autonomously calls governed platform tools (describe / list_metrics / get_dimensions / query_metric / health_check) and synthesizes an answer plus a governed recommendation.
Package copilot wraps an agent-go agent that drives the platform: given a goal, the LLM autonomously calls governed platform tools (describe / list_metrics / get_dimensions / query_metric / health_check) and synthesizes an answer plus a governed recommendation.
Package critic is the formal verification step of the agentic loop: after a question is grounded and executed, a critic judges the result along four fixed dimensions — grain, coverage, sanity, and metric-identity — and returns a verdict: pass | revise | ask_user.
Package critic is the formal verification step of the agentic loop: after a question is grounded and executed, a critic judges the result along four fixed dimensions — grain, coverage, sanity, and metric-identity — and returns a verdict: pass | revise | ask_user.
Package destinations is the right edge of the data plane: Sinks deliver query or pipeline output somewhere.
Package destinations is the right edge of the data plane: Sinks deliver query or pipeline output somewhere.
Package engine is the query spine: it ties the semantic model + compiler (semantic-go) to a real warehouse.
Package engine is the query spine: it ties the semantic model + compiler (semantic-go) to a real warehouse.
Package flow is the platform's Run plane: a workflow engine that runs steps in order, pauses at Human nodes for approval, and supports saga-style rollback (each step's Compensate is run in reverse on rollback/reject).
Package flow is the platform's Run plane: a workflow engine that runs steps in order, pauses at Human nodes for approval, and supports saga-style rollback (each step's Compensate is run in reverse on rollback/reject).
Package governance enforces policy at the query boundary: metric RBAC (you can't even name a metric you're not authorized for), column masking on the result, and an append-only audit trail.
Package governance enforces policy at the query boundary: metric RBAC (you can't even name a metric you're not authorized for), column masking on the result, and an append-only audit trail.
Package grounding is the context-engineering core: it indexes metric metadata in cortexdb, retrieves the top-K relevant metrics for a question (so the LLM sees only those, not the whole catalog), then asks the agent-go LLM to emit a semantic query — or a clarification when ambiguous.
Package grounding is the context-engineering core: it indexes metric metadata in cortexdb, retrieves the top-K relevant metrics for a question (so the LLM sees only those, not the whole catalog), then asks the agent-go LLM to emit a semantic query — or a clarification when ambiguous.
Package ingest maps a source into the warehouse: infer a mapping (source field → model field), run key/data checks, surface a structure diff, and land the rows.
Package ingest maps a source into the warehouse: infer a mapping (source field → model field), run key/data checks, surface a structure diff, and land the rows.
Package mcp exposes the platform's foundational tools as a standalone MCP server (official github.com/modelcontextprotocol/go-sdk).
Package mcp exposes the platform's foundational tools as a standalone MCP server (official github.com/modelcontextprotocol/go-sdk).
Package modelgen turns a live warehouse into a semantic-model draft: introspect the schema (tables, columns, keys, foreign keys), then generate entities / joins / dimensions / metrics — heuristically, optionally refined by an LLM.
Package modelgen turns a live warehouse into a semantic-model draft: introspect the schema (tables, columns, keys, foreign keys), then generate entities / joins / dimensions / metrics — heuristically, optionally refined by an LLM.
Package nleval is the natural-language evaluation closed-loop: a labeled question set, three-axis scoring (semantic / execution / result), governance probes, a CI gate, and a persisted accuracy dashboard.
Package nleval is the natural-language evaluation closed-loop: a labeled question set, three-axis scoring (semantic / execution / result), governance probes, a CI gate, and a persisted accuracy dashboard.
Package nodes is the field-level rule engine (whiteboard "Data Node"): when the same entity arrives from multiple sources, field rules decide the surviving value (conflict resolution, source-based or value-based), enforce required fields, and raise field-level alerts.
Package nodes is the field-level rule engine (whiteboard "Data Node"): when the same entity arrives from multiple sources, field rules decide the surviving value (conflict resolution, source-based or value-based), enforce required fields, and raise field-level alerts.
Package obs is lightweight, OTel-shaped observability: a trace is a set of spans (name + duration + attributes) sharing one trace_id, persisted to the warehouse so a wrong answer can be traced back.
Package obs is lightweight, OTel-shaped observability: a trace is a set of spans (name + duration + attributes) sharing one trace_id, persisted to the warehouse so a wrong answer can be traced back.
Package reconcile finds cross-source data conflicts and (optionally) has an LLM triage them.
Package reconcile finds cross-source data conflicts and (optionally) has an LLM triage them.
Package rollout is the production change-management plane (M21): a persisted model-version registry, deterministic canary traffic-splitting, and lineage-driven cache invalidation.
Package rollout is the production change-management plane (M21): a persisted model-version registry, deterministic canary traffic-splitting, and lineage-driven cache invalidation.
Package runtime is the control plane over HTTP: the execution dashboard (flow runs + approve/reject/rollback), governed query, data explorer, and lineage (chain-of-change).
Package runtime is the control plane over HTTP: the execution dashboard (flow runs + approve/reject/rollback), governed query, data explorer, and lineage (chain-of-change).
ui
Package ui is the embedded web console: server-rendered Go templates + htmx + Alpine + GSAP + Tailwind, all go:embed'd into the di binary and served by `di serve` at /ui.
Package ui is the embedded web console: server-rendered Go templates + htmx + Alpine + GSAP + Tailwind, all go:embed'd into the di binary and served by `di serve` at /ui.
Package spiderbench runs the Spider text-to-SQL benchmark through the governed semantic layer and reports it HONESTLY: DataIntelligence only answers metric×dimension analytical queries, so most Spider questions (row-level lookups, rankings, sub-queries, set operations) are out of scope by design.
Package spiderbench runs the Spider text-to-SQL benchmark through the governed semantic layer and reports it HONESTLY: DataIntelligence only answers metric×dimension analytical queries, so most Spider questions (row-level lookups, rankings, sub-queries, set operations) are out of scope by design.
Package warehouse executes compiled SQL against a real warehouse with cost guardrails (timeout + row cap) at the boundary.
Package warehouse executes compiled SQL against a real warehouse with cost guardrails (timeout + row cap) at the boundary.
Package writeback is the production write-path: the AI agent turns a natural language request into a TYPED, validated change proposal (never raw SQL), confined to a declared allowlist of writable tables/columns/operations.
Package writeback is the production write-path: the AI agent turns a natural language request into a TYPED, validated change proposal (never raw SQL), confined to a declared allowlist of writable tables/columns/operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL