ai-trainer Guide
Builds, scores, versions and exports the command-embedding database, and downloads the optional ONNX and GGUF model files. This guide explains which models ship, which databases are created and when, where training data comes from, the exact training file format, and every step from the terminal or the Lite dashboard.
ai-trainer at a glance
ai-trainer builds the command-embedding database from a JSON file of command metadata, scores it against a test file, versions it as snapshots, exports it, and downloads the optional model files. It is the training workshop of the AI suite; ai-cmd does the querying.
Reference and verification
This is a scenario-first guide: operational workflows, real run order, and troubleshooting. For the full autogenerated command and flag catalog, use the ai-trainer CLI Reference, or read the raw signer JSON.
SHA256 (v9.8.4): 323087352162952478afdc6110033596ff5f9a4f626064c66cbb8299ca0c344c
What ai-trainer Does
ai-trainer is the model workshop of the Kodachi AI suite. It builds a command-embedding database from a JSON file of command metadata, scores that database against a test file, versions it as snapshots, exports it, and downloads the optional model files (the ONNX sentence-embedding model and the GGUF models for the local LLM tier). It does not run queries itself: ai-cmd does that.
Key Capabilities
| Feature | Command | What it does |
|---|---|---|
| Full training | train |
Builds data/embeddings.db from scratch out of a training JSON file (TF-IDF vectors, one per command) |
| Incremental training | incremental |
Folds a second JSON file of new commands into an existing database without rebuilding it |
| Validation | validate |
Scores the database against a test file of query to command pairs and reports accuracy, precision, recall and F1 |
| Snapshots | snapshot, list-snapshots |
Saves a versioned copy of the database and lists the saved versions |
| Export | export |
Writes the database to JSON in full, compact or stats form |
| Status | status |
Reports whether a trained database exists and how many embeddings it holds |
| Model download | download-model |
Fetches the all-MiniLM-L6-v2 ONNX model and tokenizer, or a GGUF model for the local LLM tier |
Models and Databases: What Ships, What You Create
Three different things get called "the model", and only one of them is something you train. This table is the whole picture for a Kodachi 9 or 10 install.
| Item | File | Ships with Kodachi? | Created by |
|---|---|---|---|
| Intent classifier | models/kodachi-intent-classifier.onnx, intent-labels.json, intent-classifier-tokenizer.json |
Yes, pre-trained | The Kodachi team, offline. It classifies a sentence into one of 32 categories. It is never retrained on your machine and using the AI does not change it. |
| Sentence-embedding model | models/all-MiniLM-L6-v2.onnx, tokenizer.json |
Yes | Upstream model. ai-trainer download-model fetches it again if it is missing or damaged. |
| Local LLM (GGUF) | models/*.gguf |
No | ai-trainer download-model --llm, on request, because the files are 1 GB to 5.6 GB. |
| Command-embedding database | data/embeddings.db |
No | ai-trainer train, the first time you run it. The table is created on the spot (SQLite). |
| Learning database and feedback log | data/learning.db, feedback/feedback.json |
No | ai-cmd, on its first query or first ai-cmd feedback. |
| Learner database | data/kaics.db |
No | ai-learner learn, on its first run. See the ai-learner guide. |
| Admin and scheduler database | data/kodachi-ai.db |
No | ai-scheduler add creates it with the first scheduled task. ai-admin db commands report "Database not found" until it exists. |
So, is the database generated somewhere?
Yes, at runtime, by the tool that owns it, on first use. Nothing ships pre-built and no installer step creates it. A fresh install has the two ONNX models and no databases at all, and ai-trainer status, validate and export say "Database not found" until you have trained once. That is expected, not a broken install.
Where the files live
- Command line: the
data/,models/,feedback/anddb/folders of the AI runtime directory. On a standard Kodachi 9 install that is the hooks folder itself, so the database lands at/opt/kodachi/dashboard/hooks/data/embeddings.db. Run the commands from that folder, as every example on this page does. - Dashboard: the dashboard runs the AI binaries with their own per-user runtime directory,
~/.local/share/kodachi/ai/(override with theKODACHI_AI_RUNTIME_DIRenvironment variable), so the system install stays read-only. A database trained from the dashboard therefore lives under your home directory, not under/opt. - Not sure which one a build uses?
ai-learner status --jsonprintsdatabase_path, and a failingai-trainer statusnames the path it looked for.
Where Training Data Comes From
You write it, or you download the starter files below. Training data is not collected from your usage and it is not shipped inside the binary pack. Here is how the three layers fit together:
- The intent classifier is trained by the Kodachi team from the command registry, the built-in intent patterns and the workflow profiles (about ten thousand example sentences across 32 categories). You receive the finished ONNX file. There is nothing for you to train here.
- The command-embedding database is built by
ai-trainer trainfrom a JSON file of command metadata that you supply. The two starter files below are the same command metadata the Kodachi tooling uses, and they are the fastest way to get a first trained database. - Feedback is collected as you go: every executed query is recorded by ai-cmd, and
ai-cmd feedback "<query>" --correct-intent <id>records a correction. On Kodachi 10 ai-cmd consults those corrections when it ranks matches; on Kodachi 9 they are stored only. Feedback never rewrites the classifier and never edits your training JSON, so it is a separate channel from training, not a source of training data.
Starter files
| File | Contents | Use with |
|---|---|---|
| training-data.json | 111 Kodachi commands with descriptions, keywords and example phrasings, ready to train | ai-trainer train --data |
| test-cases.json | 12 query to command pairs drawn from the same file, for a first validation run | ai-trainer validate --test-data |
# Put the starter files where the binaries expect them (Kodachi 9 standard install)
cd /opt/kodachi/dashboard/hooks
sudo mkdir -p data
sudo curl -fsSL -o data/training-data.json https://kodachi.cloud/docs/ai/samples/training-data.json
sudo curl -fsSL -o data/test-cases.json https://kodachi.cloud/docs/ai/samples/test-cases.json
jq .command_count data/training-data.json # prints 111
Training Data Format (exact)
This is the structure the binary parses. It is the same in Kodachi 9 and 10. A file in any other shape, including one with a wrapper object around these fields, is rejected with Failed to parse training data JSON.
{
"version": "9.0.1",
"generated_at": "2026-02-09T00:00:00Z",
"command_count": 2,
"commands": [
{
"command_id": "health-control-net-check",
"service": "health-control",
"command": "net-check",
"description": "Check network connectivity and internet accessibility",
"category": "network",
"examples": ["health-control net-check", "check network", "am i online"],
"keywords": ["health-control", "net-check", "network"],
"typical_queries": ["check network", "test internet", "network status"]
},
{
"command_id": "tor-switch-status",
"service": "tor-switch",
"command": "status",
"description": "Show the current Tor connection status",
"category": "tor",
"examples": ["tor-switch status", "is tor running", "tor status"],
"keywords": ["tor", "status", "anonymity"],
"typical_queries": ["check tor status", "is tor working", "show tor state"]
}
]
}
Rules the parser enforces
| Field | Required | Rule |
|---|---|---|
version |
yes | Any string. Use the Kodachi version you are on. |
generated_at |
yes | Any string, by convention an ISO 8601 timestamp. |
command_count |
yes | Must equal the number of entries in commands. A mismatch is rejected as an inconsistent file, so update it when you add or remove entries. |
commands |
yes | Non-empty array. At most 100,000 entries. |
command_id |
yes | Unique per entry. It is the primary key of the database: training the same id again overwrites the earlier vector. Use <service>-<command>. |
service, command |
yes | The binary name and its subcommand, for example tor-switch and status. |
description |
yes | One sentence. It is part of the text the vector is built from. |
category |
no | Lowercase, one of network, security, system, privacy, tor, dns, vpn, monitoring, authentication, other. Anything else, or a missing field, becomes other without an error. |
examples, keywords, typical_queries |
no | Arrays of strings, empty if omitted. These are the training signal: use the wording people actually type. |
| Any string field | At most 8,192 bytes. |
What the trainer does with an entry. It joins service, command, description, every keyword, every example and every typical query into one text document, computes a TF-IDF vector over all documents, and stores one vector per command_id. Validation then vectorises each test query and picks the closest command. So two commands whose phrasings overlap will confuse each other, and a command with four to six distinct phrasings scores much better than one with a bare description.
Test file format
Used by validate --test-data. The key is test_cases; min_score is optional and defaults to 0.5.
{
"version": "9.0.1",
"test_cases": [
{ "query": "check my internet connection", "expected_command_id": "health-control-net-check", "min_score": 0.5 },
{ "query": "is tor working", "expected_command_id": "tor-switch-status" }
]
}
A test case passes when the top match is expected_command_id and its similarity is at least min_score. The run as a whole passes when the share of passing cases reaches --threshold (default 0.85).
Writing good training data
- Give every command four to six phrasings in
examplesortypical_queries, written the way a person would type them ("am i online", not "verify connectivity status"). - Do not reuse a phrasing across two commands; it makes them indistinguishable.
- Keep
command_idstable once you have validated against it, because the test file references it. - Balance the categories. A hundred network entries and five DNS entries will pull ambiguous queries toward network.
- After every edit, check the file parses (
jq . data/training-data.json) and thatcommand_countstill matches (jq '.commands | length').
Step by Step: Command Line
Run from the hooks folder. train, incremental, export, snapshot and download-model run with sudo; train, incremental and export also check for a signed-in online-auth session and stop with "Authentication required" without one. validate, status and list-snapshots need neither.
# 0. Go where the binaries are
cd /opt/kodachi/dashboard/hooks
# 1. Before training: no database yet, this is expected
ai-trainer status
# 2. Get the starter files (or write your own in the format above)
sudo mkdir -p data
sudo curl -fsSL -o data/training-data.json https://kodachi.cloud/docs/ai/samples/training-data.json
sudo curl -fsSL -o data/test-cases.json https://kodachi.cloud/docs/ai/samples/test-cases.json
# 3. Build the database (creates data/embeddings.db)
sudo ai-trainer train --data data/training-data.json
sudo ai-trainer train --data data/training-data.json --json # same, machine readable
# 4. Score it
ai-trainer validate --test-data data/test-cases.json
ai-trainer validate --test-data data/test-cases.json --threshold 0.90 --json
# 5. Keep a rollback point
sudo ai-trainer snapshot --snapshot-version 1.0.0
ai-trainer list-snapshots
# 6. Export for backup or inspection (the path must stay inside the runtime directory)
sudo ai-trainer export --output data/model_export.json --format compact
sudo ai-trainer export --output data/model_stats.json --format stats --json
# 7. Add commands later without rebuilding: a second file in the same format
sudo ai-trainer incremental --new-data data/my-new-commands.json
ai-trainer validate --test-data data/test-cases.json
# 8. Try a training run without touching the real database
sudo ai-trainer train --data data/training-data.json --database data/embeddings-test.db
ai-trainer validate --test-data data/test-cases.json --database data/embeddings-test.db --json
train versus incremental. train clears the database and rebuilds every vector from the file you give it; it is the command to use for a clean rebuild or after editing existing entries. incremental keeps what is there and adds the entries of the new file; it requires an existing database and is the command to use when you only have new commands to add.
Starting over. Delete data/embeddings.db (or train into a different --database) and run train again. Snapshots are separate copies under data/models/ (one .db plus one .json of metadata per snapshot) and survive that.
Downloading model files
download-model is the only command on this page that touches the network. Without flags it fetches the all-MiniLM-L6-v2 ONNX model and tokenizer into models/. With --llm it fetches a GGUF model for the local LLM tier (Mistral.rs); pick the size that fits the machine:
| Tier | Model | On disk | RAM (32K context) | Use when |
|---|---|---|---|---|
small |
Qwen3-1.7B Q4_K_S | ~1.0 GB | ~1.8 GB | Under 4 GB free RAM, fastest load |
default |
Qwen3-1.7B Q4_K_M | ~1.1 GB | ~2.0 GB | Recommended. Balanced on 4 GB systems |
large |
Phi-3.5-mini Q4_K_M | ~2.3 GB | ~3.5 GB | 128K context, better reasoning chains |
xlarge |
Qwen3-8B Q4_K_M | ~4.8 GB | ~6.5 GB | 8B class tuned for speed, needs 8 GB or more |
xlarge-hq |
Qwen3-8B Q5_K_M | ~5.6 GB | ~7.5 GB | 8B class tuned for quality, needs 16 GB or more, about 15 percent slower than xlarge |
sudo ai-trainer download-model # ONNX embedding model and tokenizer
sudo ai-trainer download-model --llm # default GGUF (Qwen3-1.7B Q4_K_M)
sudo ai-trainer download-model --llm xlarge-hq # quality-tuned 8B
sudo ai-trainer download-model --all # ONNX plus the default GGUF
sudo ai-trainer download-model --show-models # what is installed, what is available, sizes
sudo ai-trainer download-model --force # re-download and overwrite
sudo ai-trainer download-model --output-dir models/custom
There is no RAM guard before a local model is loaded. Loading xlarge-hq on a 4 GB machine ends in an out-of-memory kill under inference, so match the tier to the host before selecting it.
Step by Step: Lite Dashboard
Everything above is also available without a terminal. The Lite dashboard has two panels for it, both running the same ai-trainer binary. Because the dashboard launches the AI tools in your per-user runtime directory (~/.local/share/kodachi/ai/), there is no sudo prompt and a database trained here is separate from one trained on the command line under /opt.
AI Commander, "Model Trainer (advanced)"
Open Essentials, then the AI Commander tab, then its Commander sub-tab. Below the "Ask for what you want" query box is a collapsed card named Model Trainer (advanced). Expand it and work down the panels in this order:
| Panel | Controls | Runs |
|---|---|---|
| Training Data Management | File picker for the training JSON, optional database path (leave as "Default database"), Train from File | ai-trainer train --data <file> |
| Incremental Training | File picker for the new-commands JSON, Incremental Train | ai-trainer incremental --new-data <file> |
| Validation Enhancement | File picker for the test JSON, accuracy threshold slider in percent, Validate with File. Results appear in a Validation Results panel: accuracy, precision, recall, F1 and passed tests out of total | ai-trainer validate --test-data <file> --threshold |
| Model Export | Format (Full, Compact, Statistics Only), output path, Export Model | ai-trainer export --output --format |
| Snapshot Management | Version label, Create Snapshot, List Snapshots (shows version, date, size and accuracy per snapshot) | ai-trainer snapshot, ai-trainer list-snapshots |
| Model Download | Output directory, Download ONNX Model (always fetches the latest ONNX assets) | ai-trainer download-model |
| Advanced Options | JSON output format, verbose mode, timeout in seconds (30 to 600), retry count (0 to 10). They apply to the training and validation actions above | adds --json and verbose logging, bounds the run |
The training and test files are picked from anywhere on disk with the folder button; the starter files above work as they are. Each button's tooltip shows the exact command line it runs, and the output lands in the dashboard's output log.
Kodachi AI command builder, "Training" tab
When you want every flag rather than guided defaults, open the Command Builders group and choose Kodachi AI. Its Training tab exposes ai-trainer one command per card, with a field per flag and the resulting command line shown before you run it:
- Train Model: Data File (required), Database.
- Incremental Training: New Data File (required), Database.
- Validate Model: Test Data File (required), Accuracy Threshold (default 0.85), Database.
- Export Model: Output File (required), Export Format (Full, Compact, Stats Only).
- Create Snapshot: Version (required). List Snapshots: no options.
- Download Model: Output Directory, LLM Model Size (small, default, large, xlarge, xlarge-hq), Download All, Force Download, Show Available Models.
The same page has Learning (ai-learner), Admin (ai-admin database backup, restore, integrity check, migrate, info), Scheduler and Discovery tabs, so the whole train, validate, snapshot, back up cycle can be done from one screen. Output format (plain, JSON, JSON pretty) is a global switch at the top of the page.
AI Chat is a different thing
The "AI Assistant" button on the shared rail opens AI Chat, a conversation window that drafts and explains commands. It uses the shipped classifier and, if you enable them, local or cloud language models. It has no training controls and does not read the embedding database; use AI Commander or the command builder for that.
What Training Changes, and What It Does Not
data/embeddings.dbis ai-trainer's own model store.validatescores it,exportdumps it,snapshotversions it,statuscounts it. Building a good one is how you evaluate and ship a command catalogue for your own set of commands.- ai-cmd resolves your sentence against the command catalogue compiled into it, the shipped intent classifier and, on Kodachi 10, the corrections you have submitted with
ai-cmd feedback. Retraining with ai-trainer does not replace the shipped classifier and cannot break ai-cmd; if a training run goes wrong, delete the database or restore a snapshot and nothing else is affected. - Nothing on this page sends data anywhere. Training, validation, snapshots and export are local file operations. Only
download-modelreaches the network, and only when you run it.
Questions People Ask
Do I have to train before I can use ai-cmd? No. ai-cmd works out of the box with the shipped classifier and its built-in catalogue. Training is for people who want to build, score and version their own command catalogue.
Is the database created by the installer? No. It is created the first time you run ai-trainer train. Until then status, validate and export report "Database not found".
Where do I get training data? Download the starter files above, or write your own in the format above. It is never generated from your usage.
Does the AI learn from what I type? ai-cmd records executed queries and the corrections you submit with ai-cmd feedback. On Kodachi 10 those corrections influence ranking; on Kodachi 9 they are stored only. See the ai-learner guide for the learning side.
Which threshold should I use for validate? Start with the default 0.85. Use a lower value (for example 0.2) to see whether the plumbing works on a tiny test file, and 0.90 or higher as a release gate for a catalogue you maintain.
Can I keep several catalogues? Yes, with --database on train, incremental and validate. Only the default data/embeddings.db is what status, export and snapshot look at.
Why does export refuse my output path? The path is confined to the runtime directory. Use a relative path such as data/model_export.json.
Why does incremental fail on a fresh install? It adds to an existing database and does not create one. Run train once first.
Why does the dashboard not see the database I trained in the terminal? The dashboard uses ~/.local/share/kodachi/ai/, the terminal uses the hooks folder. Train in the place you will use, or point both at one path with KODACHI_AI_RUNTIME_DIR.
Related Workflows
- ai-learner, feedback, learning cycles, analysis and reports
- ai-cmd, querying, preview and feedback
- ai-discovery, binary detection and command metadata extraction
- ai-admin, database backup, restore and integrity
- AI suite overview, all eight binaries and how they connect
- Full CLI Reference: ai-trainer commands
Troubleshooting
| Problem | Cause | Solution |
|---|---|---|
| "Database not found" from status, validate or export | No training run yet | Run sudo ai-trainer train --data data/training-data.json once |
| "Failed to parse training data JSON" | Wrong shape: a wrapper object, a missing version, generated_at or command_count, or invalid JSON |
Match the format above exactly; check with jq . |
| "Training data is inconsistent: command_count field declares N" | command_count does not equal the number of entries |
Set it to jq '.commands | length' |
| "Training data contains no commands" | Empty commands array |
Add at least one entry |
| "Authentication required" | train, incremental or export without a signed-in session | Sign in with online-auth, then retry with sudo |
| Validation shows 0 percent | Test file uses ids that are not in the training file, or the wrong key (test_queries instead of test_cases) |
Use the test file format above and ids that exist in the trained data |
| Low accuracy after training | Too few or overlapping phrasings | Four to six distinct phrasings per command, no phrasing reused across commands |
| incremental update lowers accuracy | New entries overlap existing ones | Restore the last snapshot, review the overlapping examples, retrain with train |
| Model download fails | No network, or not enough disk space | Check connectivity; ONNX needs about 200 MB free, GGUF tiers 1 GB to 6 GB |