Skip to main content
Glama
README.md
# Leonida Knowledge Base

[![CI](https://github.com/MertTomak/leonida-knowledge-base/actions/workflows/ci.yml/badge.svg)](https://github.com/MertTomak/leonida-knowledge-base/actions/workflows/ci.yml)

A small, source-grounded RAG knowledge base about GTA 6, built as the memory of a multi-agent content pipeline ([leonida-shorts-factory](https://github.com/MertTomak/leonida-shorts-factory)).

The biggest risk for a game guide written by agents is a confident wrong answer. This knowledge base answers that problem in three ways:

1. **Every fact is a claim with sources.** Each claim is a single sentence in our own words. It links to the pages it came from, with their publication dates.
2. **Verdicts are computed, not chosen.** Rules in [`src/verdict.ts`](src/verdict.ts) decide whether a claim is CONFIRMED, PLAYER REPORT, RUMOR or SPECULATION, based on its sources. An agent can't label a claim more confidently than its sources allow.
3. **It says "I don't know".** When nothing in the base is close enough to a question, search returns `noMatch` instead of the nearest loosely related fact.

> Not affiliated with Rockstar Games or Take-Two Interactive. No game assets and no copied article text: claims are paraphrased facts with links.

## Verdict rules

| Claim kind | Verdict |
|---|---|
| **official** (patches, frame rate, prices, languages, dates, sales) | CONFIRMED only after a human (the owner) has seen it on Rockstar's, Take-Two's or the console store's own page (`ownerChecked` on the source). Otherwise RUMOR, however many news sites repeat it. |
| **gameplay** (controls, locations, missions, mechanics) | CONFIRMED with at least two independent publishers (two pages from one site count once), PLAYER REPORT with one. A claim whose sources conflict is capped at PLAYER REPORT and carries a `conflict` note. |
| **inference** | SPECULATION |

`npm run check` fails if any stored verdict differs from what the rules compute.

## How it works

```
data/sources.json ─┐                       ┌─► CLI (search, check, stats)
                   ├─► SQLite index ───────┤
data/claims.jsonl ─┘   FTS5 (BM25)         └─► MCP server ─► Claude Code agents
                       + local embeddings      search_knowledge · get_claim
                         (bge-small, ONNX)     check_claim · add_source · add_claim
```

- **Hybrid retrieval.** BM25 keyword search (SQLite FTS5) and semantic search (`BAAI/bge-small-en-v1.5`, quantized, run locally with transformers.js) are fused with Reciprocal Rank Fusion.
- **Abstention.** If the best semantic similarity is below a threshold, the answer is `noMatch`. The threshold is tuned on a dev split and reported on a held-out test split.
- **News mode.** `as_of` + `max_age_days` keep only claims with a source from the last N days (the pipeline's 3-day rule for news).
- **Incremental index.** Only claims whose text changed are re-embedded. The index lives in `.cache/kb.sqlite` and rebuilds itself when the data files change.
- **Everything is local.** Node's built-in `node:sqlite`, a 33 MB embedding model and no API keys. Nothing costs money to run.

## Results

From [`eval/results.md`](eval/results.md): 63 claims, 36 sources, 73 questions (55 answerable, 18 the base can't answer), split into dev and test.

| Retrieval (answerable questions) | hit@1 | recall@5 | MRR |
|---|---|---|---|
| BM25 only | 78.2% | 92.7% | 0.842 |
| Vector only | 81.8% | 100.0% | 0.895 |
| **Hybrid** | **85.5%** | **100.0%** | **0.907** |

| Abstention, test split (threshold 0.65 tuned on dev) | |
|---|---|
| Answerable questions answered | 77.8% |
| Unanswerable questions refused | 88.9% |
| Balanced accuracy | 83.3% |

The tuning split scores higher (94.6%) than the test split (83.3%). That gap is the honest cost of a single similarity threshold. Refusing is the safer failure for this use: the agent then researches the topic instead of repeating a wrong fact.

## Using it

Requirements: Node 24 or newer.

```bash
npm install
npm run build                                   # downloads the model once, builds the index
npm run search -- "how do I fight the devil"
npm run check                                   # verdict rules
npm test                                        # unit tests for the verdict rules
npm run eval                                    # rewrites eval/results.md, fails below eval/baseline.json
```

### CI and the eval gate

Every push and pull request runs type checking, the verdict-rule unit tests, the verdict check over all claims and the full evaluation ([`.github/workflows/ci.yml`](.github/workflows/ci.yml)). `npm run eval` exits with an error if hybrid retrieval or abstention drops below the minimums in [`eval/baseline.json`](eval/baseline.json), or if any claim breaks the verdict rules. A change to the data, the search or the model that makes answers worse fails CI, and with branch protection it can't be merged. The results table is posted to the run's summary. The numbers in this README come from a Mac. The quantized model gives slightly different similarities on Linux: in CI, hybrid recall@5 is 98.2% and test balanced accuracy is about 82%. That's why the baseline minimums leave a small margin.

As an MCP server for Claude Code:

```bash
claude mcp add leonida-kb -- node /absolute/path/to/leonida-knowledge-base/src/mcp.ts
```

| Tool | What it does |
|---|---|
| `search_knowledge` | Hybrid search with verdicts, sources, dates and conflicts. Optional topic, verdict and news-age filters. |
| `get_claim` | One claim by id (the Scriptwriter cites these ids, the Reviewer checks them). |
| `check_claim` | Dry run: the verdict a claim would get and any similar existing claims. |
| `add_source` | Registers a page. Agents can't mark it as owner-checked. |
| `add_claim` | Adds a fact. The verdict is computed, and near-duplicates (similarity ≥ 0.92) are rejected. |

## Data

The initial claims come from the pipeline's own research notes (30 November - 4 December 2026), translated and rewritten as single facts. They cover controls and settings, performance and patches, PC and pricing rumors, missable content, hidden cars, two easter eggs, and the map's counties.

The 11 RUMOR claims are official-type facts that haven't been checked by the owner on an official page yet. That's the rule working as intended, not missing data.

## License

MIT, see [LICENSE](LICENSE). The embedding model (BAAI bge-small-en-v1.5) is MIT licensed as well.