Details
Sage turns a large document corpus into knowledge an LLM agent can use, with every statement traced back to the page it came from.
In large organisations, the rationale behind past decisions is scattered across documents and people's memory, so teams rebuild it from scratch. Sage reads the documents once and pre-digests them into a persistent graph of synthesized, cited prose. At query time it retrieves this digested knowledge instead of re-reading raw documents. Good answers are filed back as derived knowledge, so the store grows with use.
Knowledge climbs a three-step ladder: Note (one source's evidence) → Claim (a scored proposition across sources) → Page (a cited article about one entity). Four evidence edges link them:
supports,contradicts,supersedes,derived_from.
Use Sage to:
- Turn a document corpus into one cited prose page per entity, which an agent reads instead of raw chunks.
- Record what changed: when a newer source supersedes or contradicts an older one, the engine stores the edge, lowers the older claim's confidence, and the page flags contested claims.
- Trace any statement back to the document and page it came from.
- Fit the graph vocabulary (entity types, genres, source authority) from the corpus and have an expert ratify it, rather than hand-writing a schema.
- Add documents over time: every stage resumes from the store, and
lintrecomputes only the knowledge a changed source touches.
Details
- Prose, not a schema: knowledge is cited markdown; the database only indexes and links it, so the same engine works in any domain.
- Provenance to the page: every note records its source document and page; every claim and page cites the notes behind it.
- Two knowledge tiers: primary knowledge (source evidence) is permanent; derived knowledge (claims, pages, answers) can be recomputed, and the engine invalidates it when a source changes.
- Controlled vocabularies:
resolvemaps entity mentions onto registries (e.g. MONDO, HGNC, ChEMBL, ROR) and a growing alias DB, not hardcoded term lists. - Experts in the loop: a human ratifies the domain profile;
harmonizeauto-applies only high-confidence entity merges, and a deterministic guard vetoes risky ones (sign flips, subtype vs parent, distinct ontology ids). The rest go to a review queue. - Built for scale: stages run in parallel (
--workers) and resume from the store, so a large corpus can be built in parts.
Details
The engine has three paths, each scoped to one project. 🟦 uses an LLM, 🟩 rule-based, 🟧 expert gate (the build waits for it; every stage's optional reviews are in its doc's Manual steps section).
| Stage | What it does | |
|---|---|---|
| Setup path | Once per domain: turn the corpus into text and fix the graph vocabulary. | |
decode |
Converts every document to text once (PDF, PPTX, DOCX, XLSX, images, text). Cached by content hash, so each build re-runs it only for new or changed files. | 🟩 |
profile |
Fits and ratifies a versioned domain profile: entity types, genres, source authority, resolvers. | 🟦🟩🟧 |
| Build path | On every corpus update: turn text into cited knowledge. | |
ingest |
Classifies each document's genre and extracts source-grounded prose notes. | 🟦🟩 |
resolve |
Canonicalizes entity mentions against controlled vocabularies. | 🟦🟩 |
harmonize |
Merges duplicate entities that surface matching misses (abbreviations, OCR twins, legal-name variants). | 🟦🟩 |
claims |
Clusters notes into scored claims joined by evidence edges. | 🟦🟩 |
generate |
Writes one cited prose page per entity. | 🟦 |
lint |
Detects stale knowledge and dangling links, recomputes only what changed, and fills missing vectors. | 🟦🟩 |
Read path, on demand: query answers questions over the built prose and evidence graph, with citations, and export writes one markdown page per entity (Obsidian-ready).
Helpers: check lists what a run needs and whether it is in place, vocab fetches the built-in vocabularies, rebind keeps a moved file's identity, redate dates a built store again without re-extracting, links sets each document's link back to its origin, purge removes documents with the knowledge only they supported, report writes one HTML page showing what is inside the knowledge base, and inventory writes one showing what is under a source folder before anything reads it.
Details
Five steps from a fresh clone to a first answer from your own documents. Each links to the part of the runbook,
running.md, that holds the details.
1. Install Python ≥ 3.12.2, uv and the claude CLI, then the engine (§1):
git clone https://github.com/AstraZeneca/sagekg.git && cd sagekg
uv sync2. Configure. Copy .env_example to .env and fill it in: where your provider's credentials are, which model ids to use, and one block per project naming its corpus and its domain profile (§2, §7). A profile describes your domain; use the shipped one (drug_regulatory_review, the paper's) or measure your own with sagekg profile (profile.md).
3. Check that everything the run needs is in place, before anything is spent (check.md):
uv run sagekg check --project smoke4. Build (§3). run goes from decode to generate and ends by writing report.html, a page showing what was built. --limit 50 reads only the first 50 documents of your corpus, a quick check of the setup; drop it for the whole corpus:
uv run sagekg run --project smoke --limit 505. Ask a question (query.md):
uv run sagekg query --project smoke "What is the TRIAL-1 hazard ratio?"Then review what the stages left for an expert, and grow the run to the whole corpus (§4, §5).
Details
Each project gets one directory: $EKG_DATA_DIR/<project>/, or EKG_PROJECT_<NAME>_DATA when set. The corpus is only read, never copied.
$EKG_DATA_DIR/<project>/ (default ./data/kb/<project>/)
├── store.sqlite # the knowledge and its index, in one file
│ ├── sources # one row per document: path, content hash, date, authority
│ ├── nodes # notes (primary) · claims, pages, answers (derived) — all prose
│ ├── edges # supports · contradicts · supersedes · derived_from
│ ├── entities, aliases # canonical entities and the growing alias DB
│ ├── nodes_fts # the keyword index, updated on every write
│ ├── node_vectors # the semantic index (when EKG_EMBED_MODEL is set), written with each node
│ └── journal, runs, llm_usage # per-document and per-entity outcomes, run history, model cost
├── decoded_text/md/<doc_id>.md # decode: one text file per document (`--to-txt`: txt/<doc_id>.txt)
├── vocab_cache/<name>.json # resolve: parsed vocabularies, reused while newer than the source
└── profile/ # profile: only when you measure one from the corpus
├── measurables.json # what the corpus showed
├── rulings.json # the expert's decisions
├── handoff.json # the two joined
└── <name>@<version>.json # the profile you bind in .env (+ .evidence/.manifest .json)
<export --out DIR>/
└── page_<entity_id>.md # export: one markdown page per entity, plus answer_<id>.md per filed answer
The pages are also in store.sqlite (nodes, type page), so query and lint read them without an export.
Details
| Doc | Covers |
|---|---|
| Start here | |
architecture | Core concepts: the ladder, the typed spine, the store. |
running | Configure a project, run, resume, models, review queues. |
code map | Interactive map of the engine: each part, what it saves and reads, every store table and its columns. Download the file and open it in a browser. |
| Setup path | once per domain |
decode | Files → text, the cache key, the quality-check review queue. |
profile | Measuring and ratifying a domain profile. |
| Build path | in sagekg run order |
ingest | Genre classification, note extraction, quarantine reasons. |
resolve | Mentions → canonical entities, vocabularies, the alias DB. |
harmonize | Duplicate-entity merges, the guard, the review queue. |
claims | Claims, evidence edges, supersession, confidence. |
generate | One cited prose page per entity. |
lint | Staleness and dangling-link sweep, targeted recompute, vector fill. |
| Read path | reads the built store |
query | Cited answers behind five guardrails; --file-back. |
export | Pages → markdown with frontmatter, for Obsidian. |
| Helpers | run on demand |
rebind | Keeps a moved file's identity; the review queue. |
redate | Dates a built store again, as ingest does, without re-extracting; a dry run and a diff first. |
purge | Removes documents, with the knowledge only they supported. |
links | Each document's link back to where it came from, from the corpus's link manifest. |
report | One HTML page showing what is inside the knowledge base, stage by stage. |
inventory | One HTML page showing what is under a source folder: files, sizes, types, dates per folder. |
check | What a run needs, checked before it spends anything. |
vocab | The built-in vocabularies: list and fetch them. |

