Model training case study: askmdb
How I trained four models of my own, from 0.8B to 9B, that turn a question in English or Spanish into a MongoDB query that only reads: 91.6% on 500 questions vs 47.8% for the best untuned model, and 83.6% on CPU with 529 MB. Synthetic databases, evaluation by execution, the read-only verifier, GPU with Vulkan, costs and what I didn't achieve.
-
91.6 %
accuracy on 500 questions
askmdb-9b (LoRA): 458 of 500, running every query
-
83.6 %
with no GPU, from a 529 MB model
askmdb-0.8b: 418 of 500; the default model, on the CPU
-
+ 35.8 pts
of askmdb-0.8b over the best untuned model
Qwen3.5-9B stays at 47.8% with a file 10.7 times larger
-
14.14 USD
of rented GPU for the whole project
12.3 GPU-hours on 3 machines, all four models included
Test of 500 questions over databases the training never saw, scored by running each query, no judges; every model in Q4_K_M. Cost: all the rented GPU of the project, pilots and the first version included.
- Untuned Qwen3.5, same size
- askmdb (fine-tuned)
- Goal 80%
- Best untuned model of any size (47.8%)
View data
| Size | Untuned Qwen3.5 | askmdb | Gain | Correct, × | askmdb GGUF |
|---|---|---|---|---|---|
| 0.8B | 6.6% (33) | 83.6% (418) | +77.0 pts | ×12.7 | 529 MB |
| 2B | 20.4% (102) | 86.8% (434) | +66.4 pts | ×4.3 | 1.3 GB |
| 4B | 37.4% (187) | 89.6% (448) | +52.2 pts | ×2.4 | 2.7 GB |
| 9B | 47.8% (239) | 91.6% (458) | +43.8 pts | ×1.9 | 5.6 GB |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
This article tells how I got here: first, the piece that doesn’t depend on any model (the read-only verifier); then, how to measure without judges; the data, the training and the model that fell short; and, at the end, the family of four sizes and the GPU, with a single binary.
The problem: querying a database without handing it over
Anyone who has worked with MongoDB knows the scene: the question is simple (“how much did we bill per month this year?”, “which customers spent the most?”) and the query isn’t. An aggregate pipeline with relative dates, a $group, a $lookup across collections or an $unwind over an array is slow to write and slower to debug.
A cloud assistant solves it, but at the price of showing your schema and your data to a third party. And there’s a worse risk: a language model can propose, with all the confidence in the world, a pipeline that writes ($out, $merge) instead of reading.
I set out to do something else: a small model that lives inside a binary, talks to your MongoDB directly from your machine and can only read, decided by code and not by the model. And I wanted to prove with numbers, not impressions, that a small model well fine-tuned for a narrow task clearly beats much larger models that aren’t.
The rules of the game, set before starting:
- Truly local. A single native binary, no server, no Python, no services. The only connection it makes is to your MongoDB; the model is downloaded once and checked with SHA-256.
- Read-only, decided by code. The model proposes; a deterministic C++ verifier decides whether the pipeline reads, deserves a warning or gets blocked. Anything blocked never runs, in any mode.
- Honest when in doubt. If the question asks to change data, it says it can’t. If the answer isn’t in the schema, it says it doesn’t know instead of making something up.
- Measured figures, not hand-written ones. Every public number comes from a results file, and the accuracy target was set before training anything.
What askmdb is
askmdb has three modes: suggest (only shows the pipeline), confirm (the default: shows it and asks) and auto (runs read-only pipelines directly and asks for the rest). Before running you can copy the query in mongosh syntax. The result comes out as a table or, with --json, as a JSON object for scripts.
Everything happens on your machine: only the query goes out, to your MongoDB
You
Question
in English or Spanish
The model translates
Schema sampling
200 documents per collection, block of ≤ 4,500 bytes, cached
Prompt
instructions + schema; the prefix state is cached on disk
Local model
llama.cpp inside the binary; strict JSON: {type, collection, pipeline, explanation}
invalid JSON, refusal or "I don't know" → nothing runs
Code decides and runs
Verifier
C++ rules on the exact BSON
read warning blocked
blocked → the reason is shown, exit code 3
Mode
suggest · confirm · auto
MongoDB aggregate
maxTimeMS 10 s, allowDiskUse false, ≤ 50 rows
Result
table or JSON (--json)
What matters in this architecture is the separation of responsibilities:
- Schema sampling reads 200 documents per collection and derives field paths, types and frequent values into a compact block of at most 4,500 bytes (about 1,260 tokens). That way the model writes
"Madrid"when that’s what your documents say. Values that look like an email or a phone number are never listed, and the connection string and credentials never enter the prompt. - The model only translates. It answers with a single four-key JSON object: the type (
query,refuseorunsure), the collection, the pipeline and the explanation. Anything else is rejected and nothing runs. - The verifier doesn’t decide on text but on the exact BSON that would be sent to the server, and it’s independent of the model: if I swap the model tomorrow, safety stays the same.
Safety is not delegated to the model
The first thing I built wasn’t the model, but the read-only verifier. It’s the most critical piece of the project and the one with the most tests, and it doesn’t depend on any model: a pure function over the already-parsed pipeline.
It works with an allowlist: only the read stages, operators and variables it knows get through, and it walks all of them, including the sub-pipelines of $facet, $lookup and $unionWith. Each pipeline gets one of three levels, and the most restrictive one wins:
- Read only: known read stages and operators, on collections and fields of the schema. Runs after a plain Enter.
- Warning: it reads, but may be expensive or surprising (a
$lookupacross collections, a risky regular expression, a field not in the schema,$sample). It never runs without an explicit “yes”: Enter means no. - Blocked: it writes, administers, runs JavaScript, leaves the database or simply isn’t understood. The reason is shown and it never runs, in any mode and with any option. In a script, the exit code is 3.
595 test cases, classified at 100%
auto runs it without asking; in confirm, Enter = yes
Typical stages
$match$group$project$sort$facet
never runs without an explicit yes (Enter = no)
Reasons · test cases
+3 more reasons · 10 cases
shown with the reason and never runs, in any mode
exit code 3
Reasons · test cases
+19 more reasons · 135 cases
Allowlist
- 21read stages
- 152expression operators
- 30query operators
- 22accumulators
- 35reasons with an id
Adversarial review
- ~1,100hand-written pipelines by an agent that had not seen the code
- 0writes, admin commands or JavaScript that got through
- 30levels that were too low, fixed and added to the cases
Warning cases 70 → 89; blocked 258 → 287
When it runs, always
- server time limit: 10 s
- allowDiskUse: false
- at most 50 rows
- aggregate is the only operation
View data
| Level | Reason | Cases |
|---|---|---|
| read only | — | 219 |
| warning | — | 89 |
| warning | W-UNKNOWN-FIELD | 34 |
| warning | W-JOIN | 16 |
| warning | W-REGEX-NESTED | 12 |
| warning | W-REGEX-COMPLEX | 7 |
| warning | W-UNKNOWN-COLLECTION | 6 |
| warning | W-SAMPLE | 4 |
| warning | W-REGEX-DYNAMIC | 4 |
| warning | W-RANDOM | 3 |
| warning | W-REGEX-LONG | 3 |
| blocked | — | 287 |
| blocked | B-SERVER-STAGE | 58 |
| blocked | B-UNKNOWN-OPERATOR | 25 |
| blocked | B-JS | 19 |
| blocked | B-WRITE-STAGE | 18 |
| blocked | B-UNSUPPORTED-STAGE | 16 |
| blocked | B-UNKNOWN-STAGE | 16 |
| blocked | B-UNKNOWN-VARIABLE | 16 |
| blocked | B-BSON-TYPE | 13 |
| blocked | B-DUP-KEY | 12 |
| blocked | B-REGEX-OPTIONS | 12 |
| blocked | B-SYNTAX | 12 |
| blocked | B-STAGE-SHAPE | 9 |
| blocked | B-CONTROL-CHAR | 9 |
| blocked | B-JOIN-TARGET | 8 |
| blocked | B-PARSE | 7 |
| blocked | B-SYSTEM-COLLECTION | 7 |
| blocked | B-BAD-DB | 6 |
| blocked | B-TOO-MANY-STAGES | 5 |
| blocked | B-BAD-VARIABLE | 5 |
| blocked | B-BAD-COLLECTION | 4 |
| blocked | B-SYSTEM-DB | 4 |
| blocked | B-NOT-ARRAY | 2 |
| blocked | B-TOO-DEEP | 2 |
| blocked | B-TOO-LONG | 1 |
| blocked | B-UTF8 | 1 |
Source: verifier case lists (read, warning, blocked), allowlist tables and the adversarial review.
The detail that worried me most was parser tricks: two programs reading the same text differently. That’s why the verifier walks the same BSON that would run, not the text the model wrote, and blocks repeated keys (also inside Extended JSON wrappers), stages with more than one key, control and bidirectional characters, and a {"0": …} object posing as an array.
Besides the verifier, the executor always sets limits: aggregate is the only MongoDB operation that appears in the code (and a test checks it), every query carries a 10 s time limit on the server, allowDiskUse: false and a row cap. And the advice for production is the usual one: connect with a read-only user. The verifier is one layer; the real guarantee is the database’s own access control.
The starting point: models that couldn’t do it
I chose Qwen3.5-0.8B (Apache-2.0 license) for a practical reason: it’s small enough to answer quickly on a CPU. The problem is that, as is, it gets 6.6% of the test questions right: 33 out of 500. It returns broken JSON in more than half the cases, answers with free text and never says “I don’t know”.
Larger models do better, but don’t get there either: the best one I tested, Qwen3.5-9B, stays at 47.8%, ahead of Gemma 4 E4B (45.4%) and E2B (44.2%). And that’s with an advantage: I gave the untuned models six worked examples in the prompt; the askmdb models answer without examples.
With those references in front of me I set the target before training anything, with a rule written in advance: the higher of 80% and the best reference plus 10 points. 80% won: 400 out of 500.
How I measured it: by running every query
A database query can be written correctly in many ways. Comparing the pipeline text with a reference answer punishes right answers, and using LLM judges is expensive and debatable. Here there’s something better: the output can be run.
So every prediction is run against a fixed database and its result is compared with that of the reference query, through a versioned comparator: lenient on form (columns with another name, extra fields, rounding to two decimals, a date as a string) and strict on content. No judges in the metric.
That needed a bank of databases. I wrote 128 synthetic schemas from 64 domains (shops, hospitals, logistics, libraries…) as declarative specs, and a seeded generator that fills them into a mongod inside Docker. They’re “dirty” on purpose: optional fields, mixed types, null, names in Spanish and English, in camelCase and snake_case. The split is disjoint: 110 schemas for training, 8 for the dev set and 10 for the test, and 9 of those 18 evaluation schemas come from domains the training never sees.
By expected answer type
- Query 449 · 90%
- Refusal: asks to change data 31 · 6%
- "I don't know": the data does not exist 20 · 4%
By language
By category
Basic
Aggregation and dates
Structure
Knowing when not to answer
By database · 10 synthetic schemas
- food-bank-01 53
- banking-02 52
- mining-01 52
- car-workshop-02 51
- ecommerce-01 51
- music-school-01 51
- chess-club-01 48
- restaurant-02 48
- tow-service-01 48
- crm-02 46
None of these databases is used for training. Besides, 9 of the 18 test and dev schemas come from domains training never sees at all.
View data
| Group | Cases | Share |
|---|---|---|
| Query | 449 | 90% |
| Refusal: asks to change data | 31 | 6% |
| "I don't know": the data does not exist | 20 | 4% |
| Spanish | 254 | 51% |
| English | 246 | 49% |
| filter by values (Basic) | 62 | 12% |
| count (Basic) | 45 | 9% |
| distinct values (Basic) | 24 | 5% |
| grouped aggregate (Aggregation and dates) | 56 | 11% |
| top-N and ranking (Aggregation and dates) | 35 | 7% |
| relative date (Aggregation and dates) | 79 | 16% |
| absolute date range (Aggregation and dates) | 31 | 6% |
| arrays (Structure) | 48 | 10% |
| subdocuments (Structure) | 38 | 8% |
| across collections (Structure) | 31 | 6% |
| refusal (Knowing when not to answer) | 31 | 6% |
| missing data (Knowing when not to answer) | 20 | 4% |
| food-bank-01 | 53 | 11% |
| banking-02 | 52 | 10% |
| mining-01 | 52 | 10% |
| car-workshop-02 | 51 | 10% |
| ecommerce-01 | 51 | 10% |
| music-school-01 | 51 | 10% |
| chess-club-01 | 48 | 10% |
| restaurant-02 | 48 | 10% |
| tow-service-01 | 48 | 10% |
| crm-02 | 46 | 9% |
Source: askmdb frozen test (public on Hugging Face), counted by type, language, category and database.
Every test question was written by two different authors from two families of frontier LLMs: one wrote the question and the reference query; the other, a second query blind. A case only gets in if both queries return the same when run and if it survives the mutants: variations of the query (changing a filter, dropping a stage) that must give a different result, to make sure the reference discriminates.
- test
- dev
Candidates 1,795
author B writes question and reference; author A, a blind second query
Accepted 1,678
both queries return the same when executed and the reference survives the mutants
Frozen 1,000
fixed sample, sealed with SHA-256
Mutant filter self-test: 1,835 mutants, 0% wrongly accepted
128 synthetic schemas from 64 domains, in a disjoint split
- 110 training
- 8 dev
- 10 test
One square = one schema. 9 of the 18 test and dev schemas come from domains training never sees. Training: 330 snapshots (3 seeds per schema).
View data
| Stage | Test | Dev | Total |
|---|---|---|---|
| Candidates | 996 | 799 | 1,795 |
| Accepted | 924 | 754 | 1,678 |
| Frozen | 500 | 500 | 1,000 |
| Part | Schemas |
|---|---|
| training | 110 |
| dev | 8 |
| test | 10 |
Source: evaluation bank reports (36 batches, comparator criterion v2) and the synthetic schema specs.
A few more method decisions:
- Same conditions for everyone. All models as GGUF Q4_K_M, in deterministic mode, on the same test frozen with SHA-256: the evaluator refuses to run if the hash doesn’t match.
- Statistics, not impressions. Every accuracy figure carries its 95% confidence interval (Wilson) and every comparison between two models, its exact case-by-case McNemar test.
- Measured noise. Two identical training runs with different seeds were about 7 cases apart (σ ≈ 7.2): a difference of less than about 14 cases between two models can’t be told apart from noise.
- Rules written before opening the test. Which model gets adopted and at what threshold was decided in writing, with the document’s SHA-256 recorded, before seeing any result.
The data: where it’s won or lost
There’s no public dataset of “question in English or Spanish about a specific schema → MongoDB pipeline, or a refusal, or an “I don’t know"". I built it from scratch, from three sources:
Synthetic databases
Schema specs
128 synthetic schemas from 64 domains
Generator
fills a mongod in Docker, seeded
Data
Three sources
Direct · 55.1%
LLM A writes the question, LLM B the pipeline and a blind second one; they agree when executed
Inverse · 35.5%
code builds the pipeline from templates; an LLM phrases it
Refuse / unsure · 9.4%
asks to change data, or the data does not exist
Validation chain
- contract
- verifier
- executes
- non-empty
- two authors
- mutants
- duplicates
- decontamination
Dataset
15,000 examples
Training
Full SFT
Unsloth, on a rented GPU
GGUF + imatrix
quantized to Q4_K_M
Measurement
Evaluation
by execution against the frozen 500-case test
failures by sub-cause → targeted data
- Direct (55%): one frontier LLM writes the question in the real user’s register, another writes the pipeline and a third writes a second pipeline blind. It gets in if both match when run.
- Inverse (35%): code builds the pipeline from intent templates with real values from the database, and an LLM writes one or two ways of asking for it. The labels are correct by construction.
- Refusals and doubts (10%): requests to change data and questions whose answer isn’t in the schema.
Every example goes through the same chain: output contract, read-only verifier, execution, non-empty result, mutants, duplicates (trigram similarity ≥ 0.85) and decontamination against the test. Plus a register gate: before generating at scale, I checked that the training questions spoke like the test ones (length, fields quoted literally, languages, stages). The first pilot failed twice on length; the questions were too short or too long.
14,248 training · 752 validation
By source and language
two blind pipelines that agree when executed
Spanish 4,120 · English 4,145
pipeline from a template, the LLM writes the question
Spanish 2,657 · English 2,672
asks to change data
Spanish 367 · English 356
the data is not in the schema
Spanish 335 · English 348
By category · share in training versus dev
View data
| Group | Spanish | English | Total | Share |
|---|---|---|---|---|
| Direct | 4,120 | 4,145 | 8,265 | 55.1% |
| Inverse | 2,657 | 2,672 | 5,329 | 35.5% |
| Refusal | 367 | 356 | 723 | 4.8% |
| "I don't know" | 335 | 348 | 683 | 4.6% |
| Group | Total | Share | Share of dev |
|---|---|---|---|
| filter by values | 2,128 | 14.2% | 12.0% |
| grouped aggregate | 2,082 | 13.9% | 11.0% |
| relative date | 1,910 | 12.7% | 16.0% |
| count | 1,504 | 10.0% | 9.2% |
| arrays | 1,368 | 9.1% | 8.4% |
| across collections | 1,234 | 8.2% | 6.0% |
| top-N and ranking | 1,224 | 8.2% | 8.8% |
| subdocuments | 884 | 5.9% | 8.6% |
| refusal | 723 | 4.8% | 6.4% |
| absolute date range | 686 | 4.6% | 6.2% |
| missing data | 683 | 4.6% | 3.2% |
| distinct values | 574 | 3.8% | 4.2% |
Source: final dataset report; dev share from the frozen dev set.
The two authors of the direct part agreed between 90% and 97% of the time depending on the batch, and on a final sample checked by a double judge the residual error stayed between 1.5% and 4%. Decontamination against the test found 0 overlaps.
Two pilots on the dev set confirmed that the recipe learned before spending the budget: with 750 examples, the 0.8B reached 43.8%; with 1,500, 56.0%.
Training
I did full fine-tuning: every parameter of the model is trained, not a LoRA adapter. In a 0.8B model it fits easily and uses all its capacity for a very specific task. Two epochs, learning rate 1e-5 with cosine, fp32 master weights with bf16 autocast and the loss computed only on the answer. No hyperparameter grids and no third epoch.
I used Unsloth inside a Docker container pinned by digest, with Qwen3.5’s optimised linear-attention kernels installed. Training runs on GPUs rented by the hour on Vast.ai: an RTX 5090 with 32 GB for the pilots and the first version, and an RTX PRO 6000 with 96 GB for the final family.
- askmdb-0.8b best 0.0824
- askmdb-2b best 0.0736
- askmdb-4b best 0.0709
- askmdb-9b best 0.0677
- Validation (eval_loss)
- epoch 2
Validation loss is only comparable within this family: the pilots and v1 used a different validation set.
View data
| Model | Steps | First train loss | Last train loss | Best eval_loss |
|---|---|---|---|---|
| askmdb-0.8b | 892 | 1.0297 | 0.0443 | 0.0824 |
| askmdb-2b | 892 | 0.8858 | 0.0354 | 0.0736 |
| askmdb-4b | 892 | 0.6157 | 0.0307 | 0.0709 |
| askmdb-9b | 892 | 0.6040 | 0.0469 | 0.0677 |
Source: per-run metrics (train loss downsampled to ≤ 100 points; eval_loss every 74 steps).
Export: from the trained model to a 529 MB file
The trained model is converted to GGUF and quantized to 4 bits (Q4_K_M) with an importance matrix computed from training examples, so that quantization loses as little as possible where it matters most. Computing it on the CPU took about 25 minutes; on the pod’s GPU, between 3 and 12 minutes depending on the size. Before a model is accepted, the binary’s tests run against it.
The real path: a 68.6% that wasn’t enough
The first version, with 10,000 examples, got 343 out of 500 right: 68.6%. That was 20.8 points more than the best untuned model with a file ten times smaller… and it was 57 cases short of the 80% I had set. By my own rules, the figure was closed as it stood: it wasn’t worth publishing like that.
The temptation was the usual one: train more, change hyperparameters, a third epoch. Instead, I classified the dev-set failures by sub-cause, in aggregate (patterns and counts; never copying a case).
Training databases with num|str fields
297 / 330
one square = one training snapshot
Training examples with $convert
0 v1
v1 accuracy on the test
×381 / 50 · need type conversion
- 118 disagreements in the direct part had been discarded for exactly this reason
- 54 v1 examples removed for teaching the opposite
A single convention in the new data:
{"$convert":{"input":"$f","to":"double","onError":null,"onNull":null}} View data
| Measure | Value |
|---|---|
| Training snapshots with num|str fields | 297 / 330 |
| Examples with $convert in v1 | 0 |
| Examples with $convert after extension 1 | 857 |
| Examples with $convert after extension 2 | 877 |
| v1 accuracy on cases that need conversion | 1 / 50 |
| v1 accuracy on the rest of the test | 76% |
Source: sub-cause analysis of the v1 failures (in aggregate, no case copied) and the extension reports.
The finding: an operator that didn’t exist in the data
In 297 of the 330 training databases there were fields with mixed types: a price that’s sometimes a number and sometimes a string, as happens in real databases. To add or compare them you have to convert them with $convert. How many training examples used $convert? Zero. The templates of the inverse part avoided those fields and the direct part had discarded 118 disagreements precisely because of that. On the test, the model got 1 of the 50 cases that needed type conversion right, against 76% of the rest.
The fix wasn’t more engineering in training, but new data aimed at what was missing: about 3,000 examples split into blocks (about 850 with mixed types and a single $convert convention, about 400 long questions with two or three conditions, about 350 $lookups with new shapes, groupings with a compound _id, dates by quarter…). And then 2,000 more for the remaining gaps, such as computed projections, which were 9.3% of the dev set and only 2.5% of the training set.
- Base
- Extension 1
- Extension 2
- target 80%
Extension 1 · +3,075
Extension 2 · +2,000
View data
| Version | Total | Added | Removed | Test |
|---|---|---|---|---|
| v1 · base | 10,000 | 10,000 | 0 | 68.6% |
| Extension 1 | 13,000 | 3,075 | 75 | — |
| Extension 2 | 15,000 | 2,000 | 0 | 83.6% |
| Block | Examples |
|---|---|
| Extension 1 · mixed types with $convert | 873 |
| Extension 1 · long 'situation' questions, 2–3 conditions | 411 |
| Extension 1 · lookup: new shapes | 351 |
| Extension 1 · grouping / top-n: new shapes | 359 |
| Extension 1 · identifiers and ObjectId | 206 |
| Extension 1 · arrays by $size | 206 |
| Extension 1 · dates: bounds, quarter, 'since' | 205 |
| Extension 1 · cross-schema (collection, field) | 154 |
| Extension 1 · BSON type / null / missing | 104 |
| Extension 1 · refuse / unsure | 206 |
| Extension 2 · computed projection, _id as code | 400 |
| Extension 2 · arrays: $unwind, $elemMatch, $size | 300 |
| Extension 2 · global/compound grouping, top-1 | 300 |
| Extension 2 · dates: $dateTrunc, 'older than' | 200 |
| Extension 2 · filters in short questions | 300 |
| Extension 2 · lookup: start, nested, by code | 300 |
| Extension 2 · unsure / refuse | 200 |
Source: reports of each dataset extension and the frozen 500-case test (askmdb-0.8b).
More of the same
Doubling the dataset with the same mix would have added about 2 points according to the pilot curve: less than the 16 cases McNemar required to adopt a new model. I discarded it without training it.
A JSON grammar (GBNF)
Forcing the syntax with a grammar would rescue at most 6 test cases, most of which would still fail on content, and it costs time on every token over a vocabulary of about 248,000. I left it out and declared the figure.
Picking the best of two seeds
Two identical runs with different seeds: 354 vs 352 on dev and 343 vs 341 on the test. Picking the best of N only inflates the figure; it served to measure the noise.
Data aimed at the failures
5,000 new examples aimed by sub-cause, $convert included: from 343 to 418 right. It’s the published model.
Results: a 0.8B against much larger models
With the 15,000-example dataset and the same recipe, the test was opened a second time with the adoption rule written before training (I also state this in the model cards: it’s the second opening of the test for this line of models).
- askmdb-0.8b (fine-tuned)
- askmdb-0.8b v1, the first version
- Untuned models
- 95% confidence interval (Wilson)
- Goal 80%
View data
| Model | Correct | Accuracy | 95% CI | GGUF |
|---|---|---|---|---|
| askmdb-0.8b | 418 / 500 | 83.6% | 80.1–86.6% | 529 MB (×1.0) |
| askmdb-0.8b v1 (historic) | 343 / 500 | 68.6% | 64.4–72.5% | 529 MB (×1.0) |
| Qwen3.5-9B | 239 / 500 | 47.8% | 43.5–52.2% | 5.7 GB (×10.7) |
| Gemma 4 E4B-it | 227 / 500 | 45.4% | 41.1–49.8% | 5.0 GB (×9.4) |
| Gemma 4 E2B-it | 221 / 500 | 44.2% | 39.9–48.6% | 3.1 GB (×5.9) |
| Qwen3.5-4B | 187 / 500 | 37.4% | 33.3–41.7% | 2.7 GB (×5.2) |
| Qwen3.5-2B | 102 / 500 | 20.4% | 17.1–24.2% | 1.3 GB (×2.4) |
| Qwen3.5-0.8B | 33 / 500 | 6.6% | 4.7–9.1% | 533 MB (×1.0) |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
askmdb-0.8b gets 418 of 500 right (83.6%, 95% CI: 80.1–86.6%). The whole interval sits above 80%. Against the first version that’s 75 more cases (McNemar p < 0.0001), and against Qwen3.5-9B, 35.8 points: the confidence intervals don’t even touch.
- askmdb-0.8b (fine-tuned)
- askmdb-0.8b v1, the first version
- Untuned models
- Untuned models frontier
- Goal 80%
View data
| Model | GGUF (MB) | Accuracy |
|---|---|---|
| askmdb-0.8b | 529.3 | 83.6% |
| askmdb-0.8b v1 (historic) | 529.3 | 68.6% |
| Qwen3.5-0.8B | 532.5 | 6.6% |
| Qwen3.5-2B | 1,280.8 | 20.4% |
| Qwen3.5-4B | 2,740.9 | 37.4% |
| Gemma 4 E2B-it | 3,106.7 | 44.2% |
| Gemma 4 E4B-it | 4,977.2 | 45.4% |
| Qwen3.5-9B | 5,680.5 | 47.8% |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
Size is the other half of the story. askmdb-0.8b takes 529 MB; Qwen3.5-9B, 5.68 GB (10.7 times more) and Gemma 4 E4B, 4.98 GB (9.4 times more). Compared with its own starting point, the same untuned 0.8B, it goes from 33 to 418 right answers.
Exactly where it wins
- Form:
- Invalid JSON
- Wrong type
- Wrong collection
- Blocked by the verifier
- Execution error
- Result:
- Wrong result
View data
| Model | Invalid JSON | Wrong type | Wrong collection | Blocked by the verifier | Execution error | Wrong result | Form, total | Total |
|---|---|---|---|---|---|---|---|---|
| askmdb-0.8b | 3 | 3 | 5 | 1 | 1 | 69 | 13 | 82 / 500 |
| askmdb-0.8b v1 (historic) | 6 | 4 | 5 | 3 | 7 | 132 | 25 | 157 / 500 |
| Qwen3.5-9B | 61 | 34 | 3 | 40 | 5 | 118 | 143 | 261 / 500 |
| Gemma 4 E4B-it | 112 | 18 | 3 | 57 | 6 | 77 | 196 | 273 / 500 |
| Gemma 4 E2B-it | 43 | 22 | 9 | 74 | 10 | 121 | 158 | 279 / 500 |
| Qwen3.5-4B | 65 | 52 | 1 | 58 | 1 | 136 | 177 | 313 / 500 |
| Qwen3.5-2B | 72 | 58 | 29 | 60 | 8 | 171 | 227 | 398 / 500 |
| Qwen3.5-0.8B | 258 | 98 | 8 | 29 | 0 | 74 | 393 | 467 / 500 |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
In the untuned models, form failures dominate: invalid JSON, the wrong answer type, queries the verifier blocks or the server rejects. In askmdb-0.8b they almost disappear (13 of 82 failures) and what’s left is different result: 69 valid, read-only queries that run but compute something else. That’s why askmdb always shows the pipeline and its explanation before running it.
- askmdb-0.8b (fine-tuned)
- Untuned models
Asked to change data: refuses
Higher is betterRequests to write or delete, refused
Not in the schema: “I don't know”
Higher is betterQuestions with no answer in the schema, answered “I don't know”
Valid questions refused
Lower is betterAnswerable questions the model declined
Invalid JSON
Lower is betterResponses the program cannot read
Each dot is one question
View data
| Model | Correct refusals (of 31) | Correct “I don't know” (of 20) | Valid questions refused (of 449) | Invalid JSON (of 500) |
|---|---|---|---|---|
| askmdb-0.8b | 31 | 18 | 1 | 3 |
| Qwen3.5-9B | 30 | 0 | 14 | 61 |
| Gemma 4 E4B-it | 31 | 3 | 2 | 112 |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
Where the difference is most striking is in knowing when not to answer. askmdb-0.8b refuses 31 of 31 requests to change data and says “I don’t know” in 18 of 20 questions with no answer in the schema; Qwen3.5-9B, in none. And it wrongly refuses only 1 of 449 questions that did have an answer.
| Category | askmdb 0.8B | askmdb v1 | Qwen 9B | Gemma E4B |
|---|---|---|---|---|
| Filter by values basic · n = 62 | 92 | 87 | 87 | 87 |
| Count basic · n = 45 | 91 | 78 | 64 | 71 |
| Distinct values basic · n = 24 | 79 | 75 | 50 | 25 |
| Grouped aggregate intermediate · n = 56 | 80 | 41 | 52 | 50 |
| Top-N and ranking intermediate · n = 35 | 83 | 51 | 46 | 37 |
| Relative date intermediate · n = 79 | 85 | 70 | 10 | 0 |
| Absolute date range intermediate · n = 31 | 84 | 84 | 0 | 35 |
| Arrays hard · n = 48 | 69 | 52 | 35 | 52 |
| Subdocuments hard · n = 38 | 97 | 82 | 82 | 47 |
| Across collections hard · n = 31 | 48 | 32 | 42 | 19 |
| Refusal n = 31 | 100 | 100 | 97 | 100 |
| Missing data n = 20 | 90 | 85 | 0 | 15 |
View data
| Category | n | askmdb-0.8b | askmdb-0.8b v1 (historic) | Qwen3.5-9B | Gemma 4 E4B-it |
|---|---|---|---|---|---|
| Filter by values | 62 | 57 | 54 | 54 | 54 |
| Count | 45 | 41 | 35 | 29 | 32 |
| Distinct values | 24 | 19 | 18 | 12 | 6 |
| Grouped aggregate | 56 | 45 | 23 | 29 | 28 |
| Top-N and ranking | 35 | 29 | 18 | 16 | 13 |
| Relative date | 79 | 67 | 55 | 8 | 0 |
| Absolute date range | 31 | 26 | 26 | 0 | 11 |
| Arrays | 48 | 33 | 25 | 17 | 25 |
| Subdocuments | 38 | 37 | 31 | 31 | 18 |
| Across collections | 31 | 15 | 10 | 13 | 6 |
| Refusal | 31 | 31 | 31 | 30 | 31 |
| Missing data | 20 | 18 | 17 | 0 | 3 |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
By category, the biggest difference is in relative dates (“last month”, “the last 4 weeks”): 84.8% against 10.1% for the 9B and 0% for the E4B. The key is a design decision: relative dates are written with $$NOW, $dateSubtract and $dateTrunc, and the server resolves them. Calendar arithmetic is fragile in a 0.8B model; a template that gets copied isn’t. By language, 85.8% in English and 81.5% in Spanish: the intervals overlap, and from the 2B on the difference almost disappears.
- only the other · only the smaller
- only askmdb-0.8b · only the larger
- Noise between two seeds (~2σ = 14.4 cases)
askmdb-0.8b versus…
Each size versus the previous one
To truly win, the right bar must clear the band. Each row counts only the questions where the two models disagree: on the left, those only the other (or smaller) model gets right; on the right, those only the first (or larger) one gets right. The band starts where the left bar ends and spans ~2σ of the noise between two identical trainings with different seeds (σ of 7.2 cases). The p-value is the exact McNemar test.
View data
| Pair | Only the first / the larger | Only the other / the smaller | Net difference | p-value |
|---|---|---|---|---|
| askmdb-0.8b · askmdb-0.8b v1 (historic) | 94 | 19 | +75 | p < 0.0001 |
| askmdb-0.8b · Qwen3.5-9B | 198 | 19 | +179 | p < 0.0001 |
| askmdb-0.8b · Gemma 4 E4B-it | 212 | 21 | +191 | p < 0.0001 |
| askmdb-2b · askmdb-0.8b | 38 | 22 | +16 | p = 0.052 |
| askmdb-4b · askmdb-2b | 28 | 14 | +14 | p = 0.044 |
| askmdb-9b (LoRA) · askmdb-4b | 26 | 16 | +10 | p = 0.164 |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
Four sizes and the GPU
With the same recipe and the same data I trained three more sizes. The 2B and the 4B, with full fine-tuning. The 9B didn’t fit with full fine-tuning and fp32 master weights even in 96 GB of VRAM, so I trained it with rank-32 LoRA (87 million trainable parameters, 0.91% of the total) and merged the adapter into the weights.
- askmdb-0.8b
- askmdb-2b
- askmdb-4b
- askmdb-9b
View data
| Model | Method | Minutes | s/step | Peak VRAM | Best eval_loss |
|---|---|---|---|---|---|
| askmdb-0.8b | full fine-tune | 19.5 | 0.98 | 34.3 GB / 96 GB | 0.0824 |
| askmdb-2b | full fine-tune | 49.0 | 2.49 | 53.6 GB / 96 GB | 0.0736 |
| askmdb-4b | full fine-tune | 91.8 | 3.71 | 89.7 GB / 96 GB | 0.0709 |
| askmdb-9b | LoRA r32 · 0.91% trainable | 75.4 | 4.22 | 55.3 GB / 96 GB | 0.0677 |
Source: 14,248 examples, 2 epochs, 892 steps per run; the host capped the GPU at 300 W.
The four training runs were done on a single pod with an RTX PRO 6000 with 96 GB, which the host capped at 300 W. A performance detail: on the 2B, two Triton kernels generated by Unsloth’s compilation were eating 51% of the GPU. Turning the compilation off fixed it. And, curiously, the 9B with LoRA (75 minutes) took less than the 4B with full fine-tuning (92).
- askmdb fine-tuned: 0.8B, 2B, 4B and 9B
- Untuned models
- 95% confidence interval (Wilson)
- Goal 80%
- Best untuned (47.8%)
View data
| Model | Correct | Accuracy | 95% CI | GGUF |
|---|---|---|---|---|
| askmdb-9b (LoRA) | 458 / 500 | 91.6% | 88.8–93.7% | 5.6 GB (×10.6) |
| askmdb-4b | 448 / 500 | 89.6% | 86.6–92.0% | 2.7 GB (×5.1) |
| askmdb-2b | 434 / 500 | 86.8% | 83.6–89.5% | 1.3 GB (×2.4) |
| askmdb-0.8b | 418 / 500 | 83.6% | 80.1–86.6% | 529 MB (×1.0) |
| Qwen3.5-9B | 239 / 500 | 47.8% | 43.5–52.2% | 5.7 GB (×10.7) |
| Gemma 4 E4B-it | 227 / 500 | 45.4% | 41.1–49.8% | 5.0 GB (×9.4) |
| Gemma 4 E2B-it | 221 / 500 | 44.2% | 39.9–48.6% | 3.1 GB (×5.9) |
| Qwen3.5-4B | 187 / 500 | 37.4% | 33.3–41.7% | 2.7 GB (×5.2) |
| Qwen3.5-2B | 102 / 500 | 20.4% | 17.1–24.2% | 1.3 GB (×2.4) |
| Qwen3.5-0.8B | 33 / 500 | 6.6% | 4.7–9.1% | 533 MB (×1.0) |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
askmdb-9b gets 458 of 500 right (91.6%, 95% CI: 88.8–93.7%), askmdb-4b, 448 (89.6%) and askmdb-2b, 434 (86.8%). Every fine-tuned size beats, by far, the same untuned model: askmdb-9b gets 219 more questions right than Qwen3.5-9B. But between neighbouring sizes the gain flattens: from the 4B to the 9B it’s 10 cases (p = 0.16), within the noise. That’s why the default on the GPU is the 4B.
- Form:
- Invalid JSON
- Wrong type
- Wrong collection
- Blocked by the verifier
- Execution error
- Result:
- Wrong result
View data
| Model | Invalid JSON | Wrong type | Wrong collection | Blocked by the verifier | Execution error | Wrong result | Form, total | Total |
|---|---|---|---|---|---|---|---|---|
| askmdb-9b (LoRA) | 2 | 1 | 2 | 3 | 0 | 34 | 8 | 42 / 500 |
| askmdb-4b | 1 | 1 | 6 | 1 | 1 | 42 | 10 | 52 / 500 |
| askmdb-2b | 3 | 2 | 6 | 0 | 3 | 52 | 14 | 66 / 500 |
| askmdb-0.8b | 3 | 3 | 5 | 1 | 1 | 69 | 13 | 82 / 500 |
| Qwen3.5-9B | 61 | 34 | 3 | 40 | 5 | 118 | 143 | 261 / 500 |
| Gemma 4 E4B-it | 112 | 18 | 3 | 57 | 6 | 77 | 196 | 273 / 500 |
| Gemma 4 E2B-it | 43 | 22 | 9 | 74 | 10 | 121 | 158 | 279 / 500 |
| Qwen3.5-4B | 65 | 52 | 1 | 58 | 1 | 136 | 177 | 313 / 500 |
| Qwen3.5-2B | 72 | 58 | 29 | 60 | 8 | 171 | 227 | 398 / 500 |
| Qwen3.5-0.8B | 258 | 98 | 8 | 29 | 0 | 74 | 393 | 467 / 500 |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
What drops as size grows is the different result (from 69 to 34) and, above all, the two hardest categories improve: $lookups across collections go from 15 to 22 right out of 31, and arrays, from 33 to 41 out of 48.
| Category | askmdb 0.8B | askmdb 2B | askmdb 4B | askmdb 9B | Qwen 9B |
|---|---|---|---|---|---|
| Filter by values basic · n = 62 | 92 | 94 | 97 | 94 | 87 |
| Count basic · n = 45 | 91 | 87 | 87 | 98 | 64 |
| Distinct values basic · n = 24 | 79 | 88 | 79 | 92 | 50 |
| Grouped aggregate intermediate · n = 56 | 80 | 84 | 86 | 91 | 52 |
| Top-N and ranking intermediate · n = 35 | 83 | 97 | 97 | 89 | 46 |
| Relative date intermediate · n = 79 | 85 | 82 | 87 | 89 | 10 |
| Absolute date range intermediate · n = 31 | 84 | 94 | 97 | 97 | 0 |
| Arrays hard · n = 48 | 69 | 83 | 85 | 85 | 35 |
| Subdocuments hard · n = 38 | 97 | 92 | 97 | 100 | 82 |
| Across collections hard · n = 31 | 48 | 55 | 65 | 71 | 42 |
| Refusal n = 31 | 100 | 100 | 100 | 100 | 97 |
| Missing data n = 20 | 90 | 90 | 100 | 100 | 0 |
View data
| Category | n | askmdb-0.8b | askmdb-2b | askmdb-4b | askmdb-9b (LoRA) | Qwen3.5-9B |
|---|---|---|---|---|---|---|
| Filter by values | 62 | 57 | 58 | 60 | 58 | 54 |
| Count | 45 | 41 | 39 | 39 | 44 | 29 |
| Distinct values | 24 | 19 | 21 | 19 | 22 | 12 |
| Grouped aggregate | 56 | 45 | 47 | 48 | 51 | 29 |
| Top-N and ranking | 35 | 29 | 34 | 34 | 31 | 16 |
| Relative date | 79 | 67 | 65 | 69 | 70 | 8 |
| Absolute date range | 31 | 26 | 29 | 30 | 30 | 0 |
| Arrays | 48 | 33 | 40 | 41 | 41 | 17 |
| Subdocuments | 38 | 37 | 35 | 37 | 38 | 31 |
| Across collections | 31 | 15 | 17 | 20 | 22 | 13 |
| Refusal | 31 | 31 | 31 | 31 | 31 | 30 |
| Missing data | 20 | 18 | 18 | 20 | 20 | 0 |
Source: test of 500 questions over 10 databases the training never saw, scored by running each query and comparing its result with the reference, no judges; every model in Q4_K_M; untuned models get worked examples in the prompt.
One binary for CPU and GPU
I wanted installing askmdb to be downloading one file. That’s why I chose Vulkan: it works on NVIDIA, AMD and Intel GPUs with just the driver, while CUDA would add close to 1 GB to the binary. The trick is not linking the Vulkan library: a small loader of my own opens libvulkan.so.1 with dlopen only when the GPU is really going to be used, so the same binary starts on a server or a container without Vulkan. The price is size: with the shaders inside, the binary grows from 8.8 to 57 MB.
Picking the model without asking too much
First run
or askmdb --detect to choose again
Finds the dedicated GPU with the most free VRAM
Through Vulkan. An integrated GPU is never picked on its own.
Free VRAM
≥ 8 GiB
Lets you choose
askmdb-4b (Enter) or askmdb-9b, more accurate
≥ 4 GiB
Offers askmdb-4b
on the GPU
no dedicated GPU or < 4 GiB
askmdb-0.8b on the CPU
the default model
Asks before downloading
529 MB, 2.7 GB or 5.6 GB; checks the SHA-256
Prepares the GPU only once
compiles the shaders on the first run (≈11 s), not on your first question
Safety net. If the chosen GPU fails or is gone, askmdb warns and answers with askmdb-0.8b on the CPU (unless you force --device gpu).
Source: askmdb model selection rules (src/infer/hw.hpp); sizes of the published GGUF files.
The first time you start askmdb (or with askmdb --detect) it looks for the dedicated GPU with the most free VRAM. With 8 GiB free or more, it lets you choose between askmdb-4b (Enter) and askmdb-9b; with 4 GiB, it offers askmdb-4b; otherwise, askmdb-0.8b on the CPU. It always asks before downloading and checks the SHA-256. Integrated graphics are never picked on their own, and if the GPU fails, that question is answered on the CPU.
- VRAM peak
- Headroom up to the threshold
- Free VRAM askmdb requires
View data
| Model | VRAM peak | Weights (MiB) | Free VRAM required | Headroom | Use in the CLI |
|---|---|---|---|---|---|
| askmdb-0.8b | 1.2 GiB | 494 | — | — | runs on the CPU by default |
| askmdb-2b | 1.9 GiB | — | — | — | not used by the CLI |
| askmdb-4b | 3.3 GiB | 2,573 | 4 GiB | 0.7 GiB | offered with ≥ 4 GiB free |
| askmdb-9b | 5.5 GiB | 4,812 | 8 GiB | 2.5 GiB | can be chosen with ≥ 8 GiB free |
Source: real process VRAM peak (nvidia-smi, minus the baseline) on the reference desktop with a 16 GB GPU, 4,096-token context; free VRAM thresholds of askmdb's model selection.
Real speed
- Model load
- Reading the question
- Generation
- Rest
- Up to p90
- Goal < 3 s
askmdb starts a new process per question, so the model load is paid every time. On the CPU generation dominates: 0.64 s of askmdb-0.8b's 1.18 s. The first question against a database also reads the whole schema: 3.02 s on the CPU.
View data
| Model and device | Median | p90 | 1st question (median / p90) | Load | Question | Generation | Rest | tokens/s |
|---|---|---|---|---|---|---|---|---|
| askmdb-0.8b · CPU | 1.18 s | 1.79 s | 3.02 s / 3.60 s | 0.38 s | 0.10 s | 0.64 s | 0.06 s | 67 |
| askmdb-0.8b · GPU | 0.72 s | 0.82 s | 0.79 s / 0.92 s | 0.40 s | 0.04 s | 0.10 s | 0.18 s | 442 |
| askmdb-2b · GPU | 0.94 s | 1.12 s | 0.98 s / 1.13 s | 0.54 s | 0.05 s | 0.15 s | 0.20 s | 288 |
| askmdb-4b · GPU | 1.34 s | 1.68 s | 1.54 s / 1.85 s | 0.76 s | 0.09 s | 0.28 s | 0.20 s | 162 |
| askmdb-9b · GPU | 1.85 s | 2.40 s | 2.14 s / 2.63 s | 1.07 s | 0.10 s | 0.44 s | 0.24 s | 104 |
Source: askmdb on the reference desktop with a 16 GB GPU; 30 questions, a new process per answer and 5 runs per question with the schema cached; wall-time median and p90, excluding MongoDB's own time. Phases are medians and the rest is process start, verification and the like.
On a reference desktop with a 16 GB GPU, askmdb-0.8b answers in 1.18 s median on the CPU, askmdb-4b in 1.34 s and askmdb-9b in 1.85 s on the GPU, with a new process per question. What’s interesting is where the time goes on the GPU: with the schema already cached, the answer itself (reading the question and generating the pipeline) takes between 0.14 and 0.54 s; what weighs most is loading the model in each process. On the CPU it’s the other way round: there, generation dominates.
That “schema already cached” is another design decision: the model’s state after reading the instructions and the schema block is saved on disk (between 34 and 89 MiB per database, depending on the model), so only the first question against a database pays for reading the schema: 3.02 s on the CPU, against 1.18 s for the next ones.
- Before: every process compiles the shaders
- Now: compiled once, on the first run
- Questions, with the cache in place
- Goal < 3 s
The NVIDIA driver keeps compiled shaders in its cache but never creates the folder, so every process compiled again. askmdb creates it and prepares the GPU during the first-run check.
View data
| Model | Before, every question | First run | 1st question | Next |
|---|---|---|---|---|
| askmdb-4b | 12.6 s | 12.8 s | 1.46 s | 1.29 s |
| askmdb-9b | 14.0 s | 13.1 s | 1.95 s | 1.68 s |
Source: Reference desktop with a 16 GB GPU, NVIDIA driver; before: median of 3 starts with no shader cache and the model in the disk cache; after: real first run (detection and check) and questions on another schema.
The first time on the GPU there’s a toll: the driver compiles the Vulkan shaders, about 11 seconds. I found that, with the NVIDIA driver, the first process saved none of that compilation, because the driver doesn’t create its own cache folder; askmdb creates it, and the first start warms the GPU up so that no question pays the toll.
Distribution is light: a single static binary that only needs glibc 2.29 or later, with the MongoDB driver, TLS and SCRAM inside, that works with MongoDB 5.0 or later and with Atlas, and that builds reproducibly, bit for bit.
In the real world
Cost
Pod 1 Pilots
parity, 6 references × dev+test, pilots p750/p1500
Pod 2 First version (v1)
v1 training with two seeds, export and 2,000 predictions
Pod 3 Final family
training of the 4 sizes, export and 4,000 predictions
Total 14.14 USD · 12.3 GPU hours
Not counted: the frontier LLMs that wrote the data and the bank (about 62 million tokens, partly estimated) ran on subscription-plan quota.
View data
| Pod | Use | GPU | USD/h | Hours | USD |
|---|---|---|---|---|---|
| 1 | Pilots | RTX 5090 32 GB | 0.722 | 2.25 | 1.62 |
| 2 | First version (v1) | RTX 5090 32 GB | 0.669 | 2.23 | 1.49 |
| 3 | Final family | RTX PRO 6000 Blackwell WS 96 GB | 1.403 | 7.86 | 11.03 |
| Total | 12.34 | 14.14 |
Source: Vast.ai pod bills; hours and rates per pod.
All the rented GPU time cost 14.14 USD, on three Vast.ai machines and about 12.3 hours of use. The expensive part wasn’t the pilots or the first version (3.11 USD between them), but the 96 GB pod where the four final sizes were trained, quantized and evaluated: 11.03 USD. That figure doesn’t include the use of frontier LLMs to write the data and the test bank.
What I learned
-
Safety is not delegated to the model
A deterministic verifier on the exact BSON that would run, with an allowlist and hundreds of cases, is what makes a tool like this usable.
0 writes that got through in ~1,100 adversarial attempts
-
If the output runs, measure by running it
Comparing results instead of text avoids judges, and the comparator gets calibrated too.
0.3% weighted error of comparator v2
-
Look at failures by sub-cause
Grouping errors by cause found an operator that didn't exist in the data. No loss curve would have shown it.
0 examples with $convert in the first version
-
Data rules
5,000 examples aimed at what was missing moved more than any tweak to the recipe.
+75 cases, from 68.6% to 83.6%
-
Design for a small model
Letting the server resolve dates with $$NOW turns fragile arithmetic into a template that gets copied.
84.8% on relative dates, vs 10.1% for the 9B
-
Measure the noise before celebrating
Two identical seeds end up about 7 cases apart. Below about 14, an improvement can't be told apart from chance.
σ ≈ 7.2 cases between two seeds
-
Write the rules before looking
The target, the adoption rule and the order in which the test is opened, all set before seeing any result.
80% target set before training
-
The GPU pays off as the model grows
With a single binary and Vulkan, the same user goes from 83.6% on the CPU to 89.6% on the GPU with similar times.
1.34 s askmdb-4b on GPU, at 89.6%
What I didn’t achieve
The 80% target is beaten by all four sizes, but there are things it still doesn’t do well, and I’d rather say them:
$lookups across collections are still its weak spot: askmdb-0.8b gets 15 of 31 right (48.4%) and even the 9B doesn’t go past 22. Arrays do somewhat better (68.8% on the 0.8B), but aren’t solved either.- Different result dominates the failures: 69 of the 0.8B’s 82 are valid, read-only queries that compute something else. The verifier can’t catch them; that’s why askmdb always shows the pipeline and its explanation.
- Invalid JSON on the 0.8B is at 0.6% of the test, above the 0.5% I had set myself. I decided not to add a grammar and to declare it.
- The bank only has questions with a clear answer, because two authors had to agree when running them. It measures well what can be measured by execution, but leaves out the ambiguous questions of real use, and it has no human anchor.
- On the GPU I’ve only tested it on NVIDIA. Vulkan is standard, but AMD and Intel haven’t been measured.
If I kept going, I’d follow these lines:
- More data aimed at
$lookups and arrays, the lever that already worked with$convert. - Real questions (with permission) instead of only synthetic ones, to also measure the ambiguous ones.
- Measuring on AMD and Intel GPUs and on modest laptops.
Even so, the result delivers what I wanted to prove: a small model, well fine-tuned for a specific task, clearly beats much larger general-purpose models, and safety can live in deterministic code instead of in the model’s good will. askmdb-0.8b fits in 529 MB and answers in just over a second on the CPU; with the same recipe, askmdb-9b reaches 91.6% on the GPU.
Code, models and test set
askmdb is public: the tool’s code is MIT-licensed and the four models, Apache-2.0 (the same as their base models, from the Qwen3.5 family). The code is on GitHub and the quantized models (GGUF Q4_K_M), ready to use with llama.cpp, in the Hugging Face collection. The 500-question test set is public too, with its synthetic databases, the generator and the scoring script: askmdb-test. Installation instructions are on the askmdb page.