# Knowledge system for chat-to-data

A structured knowledge base that sits between a company’s database and an AI assistant, so a question in plain English becomes correct SQL.

Kind of work: Design and method. Built with: Postgres sample, Templates for Snowflake and BigQuery, Markdown and YAML, Column-level graph.

Status: Knowledge base and sample complete. The query skill is the next phase.

## The pain

AI writes confident queries that are wrong for a specific business, because it does not know what the company’s data means.

AI models write plausible SQL that is wrong for a specific business: the wrong join, the wrong definition of revenue, a column that looks right and is not.

The fix is giving the model the business’s own context in a form it can read reliably.

## What was built

**One layout per client and database.** A new client is added without changing the global structure. Each declares its SQL dialect.

**An article per table.** Purpose, columns, and the caveats a long-time analyst would know.

**Metric definitions.** Kept as a human-readable page and a machine-readable twin, with a script that checks the two agree.

**A graph an agent can walk.** Tables, columns, foreign keys, and which metrics use which columns, so an agent can plan a query.

**A worked sample.** A healthcare-claims database with four documented tables, two metrics and their lineage. Query logs are designed as one file per day, for audit.

## Results

There is no accuracy benchmark for this project yet. The same idea ran in production in my work at a real-estate software company.

## How it was built

- Human-readable and machine-readable definitions are checked against each other by script.
- Guidance for the model and a separate guide for the people who use it.
- Query logging designed for audit, secured at the storage layer.

## What it means for a business

“Ask your data a question” only works when the AI knows your definitions. This is the method for capturing them once and keeping them correct as the business changes.

[Work with me](https://lichucki.ai/contact)
