Database schema
Generated from the table definitions in knowtation_api.db; don't edit it by hand. After
changing a table, add a migration and run uv run python -m knowtation_api.docgen. Tests fail if
this page is out of date or if the migrations and db.py differ. How to back up, restore
and grant access: Database.
confidence_policies
A stored confidence-policy version (immutable).
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
name |
varchar(200) | no | Name, e.g. core or default. |
|
version |
varchar(50) | no | Version, e.g. 1.1.3. |
|
content_hash |
varchar(64) | no | SHA-256 of the content; recorded with each run that uses it. | |
content |
jsonb | no | The rule set or policy as stored. | |
public |
boolean | no | Usable and copyable by everyone, and picked up by runs automatically (packs). Set for all versions of a name at once; true for built-ins. | |
created_at |
timestamp with time zone | no | When the row was created. | |
owner_id |
varchar(32) | yes | → users.id |
The author; empty for built-ins. |
Unique together: name, version.
dataset_members
A co-owner or reviewer of a dataset (the owner is datasets.owner_id).
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
dataset_id |
varchar(32) | no | → datasets.id |
The dataset. |
user_id |
varchar(32) | no | → users.id, indexed |
The member. |
role |
varchar(16) | no | co_owner or reviewer. | |
added_at |
timestamp with time zone | no | When they accepted. |
datasets
A dataset: its source, its profile when read, and the proposals made while reading.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id; also the upload folder. |
name |
varchar(200) | no | Display name. | |
source |
jsonb | no | Where the data came from: uploaded file names, or the URL and its settings. | |
profile |
jsonb | no | The dataset as read (data model Dataset): resources, elements, statistics. |
|
proposals |
jsonb | no | Proposals made while reading (data model Proposal). |
|
warnings |
jsonb | no | Problems met while reading, as sentences. | |
dataset_hash |
varchar(64) | no | SHA-256 of the resources (ids, file hashes or locations, row counts); recorded with each run for reproducibility. | |
owner_id |
varchar(32) | yes | → users.id, indexed |
The owner. Empty only between upgrading and the first start, which gives such datasets to the admin. |
status |
varchar(16) | no | ready, or reading (a URL source in the background), or failed. | |
progress |
jsonb | yes | While reading: stage (downloading, reading), bytes, total. | |
error |
varchar | yes | Why reading the source failed, for people. | |
default_version |
integer | yes | The dictionary version to show and export; empty means the latest. | |
public |
boolean | no | Visible to every signed-in user. | |
created_at |
timestamp with time zone | no | When the row was created. |
dictionary_versions
An immutable dictionary version: its content, its proposals and a review's changes.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
dataset_id |
varchar(32) | no | → datasets.id, indexed |
The dataset described. |
number |
integer | no | 1, 2, 3… within the dataset. | |
parent |
integer | yes | The version this one started from; empty for the first. | |
author |
varchar(200) | no | knowtation for a run's version, otherwise the reviewer. |
|
note |
varchar | yes | run <id> for a run, or the reviewer's note. |
|
run_id |
varchar(32) | yes | The run that made this version, or for a review the run of the version reviewed. Not a foreign key; runs and versions are both deleted with their dataset. | |
content |
jsonb | no | The whole description with the chosen values (data model Dataset). |
|
proposals |
jsonb | no | Every proposal behind the content, with its review status. | |
changes |
jsonb | yes | A review's changes (action, element, property, value, before, after); empty for runs and for reviews saved before migration 0002. | |
created_at |
timestamp with time zone | no | When the row was created. |
Unique together: dataset_id, number.
llm_answer_uses
A dataset that asked for or reused a stored answer.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
key |
varchar(64) | no | → llm_answers.key |
The answer. |
dataset_id |
varchar(32) | no | → datasets.id, indexed |
The dataset that used it. |
llm_answers
A stored LLM answer, keyed by everything that was sent.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
key |
varchar(64) | no | primary | SHA-256 of model, prompt version, settings and context. |
model |
varchar(200) | no | The model asked, provider:name. | |
output |
jsonb | no | The validated answer (LLMOutput). | |
input_tokens |
integer | no | Input tokens of the original call. | |
output_tokens |
integer | no | Output tokens of the original call. | |
hits |
integer | no | How often it was reused. | |
created_at |
timestamp with time zone | no | When it was first asked. | |
last_used_at |
timestamp with time zone | no | When it was last asked or reused. |
llm_keys
A person's own key for one LLM provider, encrypted.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
user_id |
varchar(32) | no | → users.id |
Whose key it is. |
provider |
varchar(16) | no | anthropic, google or openai. | |
secret |
text | no | The key, encrypted with KNOWTATION_SECRET_KEY. | |
hint |
varchar(4) | no | The key's last four characters. | |
created_at |
timestamp with time zone | no | When it was added. | |
last_checked_at |
timestamp with time zone | yes | When the provider last listed its models. | |
last_error |
text | yes | Why the last check failed (never contains the key). |
Unique together: user_id, provider.
llm_model_lists
The models one key can use, as its provider last listed them.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
owner |
varchar(32) | no | primary | 'server', or the id of the user whose key it is. |
provider |
varchar(16) | no | primary | anthropic, google, openai or ollama. |
models |
jsonb | no | [{id, label}], ids written provider:name. | |
fetched_at |
timestamp with time zone | yes | When the provider last listed them. | |
checked_at |
timestamp with time zone | no | When we last asked (successfully or not). | |
error |
text | yes | Why the last listing failed (never contains the key). |
llm_model_settings
The admin's settings for one LLM model: hidden from the server's list, or a set price.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
model |
varchar(200) | no | primary | provider:name. |
hidden |
boolean | no | Left out of the server's models (own keys are never filtered). | |
usd_per_mtok_in |
float | yes | US dollars per million input tokens, set by the admin; beats genai-prices. | |
usd_per_mtok_out |
float | yes | US dollars per million output tokens, set by the admin. | |
updated_at |
timestamp with time zone | no | Last change. |
llm_spend
What one run or trial spent on LLM calls; kept when its dataset or user is deleted.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
created_at |
timestamp with time zone | no | indexed | When it finished. |
kind |
varchar(16) | no | run or trial. | |
job_id |
varchar(32) | no | The run's or trial's id (not a link). | |
dataset_id |
varchar(32) | no | The dataset's id (not a link). | |
dataset_name |
varchar(200) | no | The dataset's name then. | |
username |
varchar(40) | no | Who started it. | |
model |
varchar(200) | no | The model, provider:name. | |
key_source |
varchar(8) | no | Who paid: server or own key. | |
calls |
integer | no | Calls sent to the provider. | |
cached_calls |
integer | no | Batches answered from the cache. | |
input_tokens |
integer | no | Input tokens billed. | |
output_tokens |
integer | no | Output tokens billed. | |
cost_usd |
float | yes | Estimated US dollars; empty when the model's price is unknown. |
requests
An invitation to review or co-own a dataset, or an ownership transfer, until answered.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
kind |
varchar(16) | no | review, co_owner or transfer. | |
dataset_id |
varchar(32) | no | → datasets.id, indexed |
The dataset. |
from_user |
varchar(32) | no | → users.id |
Who asked. |
to_user |
varchar(32) | no | → users.id, indexed |
Who is asked. |
status |
varchar(16) | no | pending, accepted, declined or cancelled. | |
created_at |
timestamp with time zone | no | When the row was created. | |
decided_at |
timestamp with time zone | yes | When it was answered or cancelled. |
rule_draft_decisions
One decision on a dataset's draft rules (drafts themselves are computed, not stored). Keyed by the draft's content hash, so the same draft stays decided across later runs.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
dataset_id |
varchar(32) | no | → datasets.id, indexed |
The dataset. |
version |
integer | no | The dictionary version it was decided on. | |
draft_hash |
varchar(64) | no | SHA-256 of the draft's rules; the same draft has the same hash. | |
status |
varchar(16) | no | approved or discarded. | |
username |
varchar(40) | no | Who decided. | |
rule_set |
varchar(200) | yes | The rule set an approved draft was saved as. | |
decided_at |
timestamp with time zone | no | When. |
rule_sets
A stored rule-set version (immutable).
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
name |
varchar(200) | no | Name, e.g. core or default. |
|
version |
varchar(50) | no | Version, e.g. 1.1.3. |
|
content_hash |
varchar(64) | no | SHA-256 of the content; recorded with each run that uses it. | |
content |
jsonb | no | The rule set or policy as stored. | |
public |
boolean | no | Usable and copyable by everyone, and picked up by runs automatically (packs). Set for all versions of a name at once; true for built-ins. | |
created_at |
timestamp with time zone | no | When the row was created. | |
owner_id |
varchar(32) | yes | → users.id |
The author; empty for built-ins. |
Unique together: name, version.
runs
An identification run: what was asked for, its status and its reproducibility record.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
dataset_id |
varchar(32) | no | → datasets.id, indexed |
The dataset the run reads. |
status |
varchar(16) | no | pending, running, done or failed. | |
request |
jsonb | no | What was asked for: rule sets, policy, LLM, start fresh. | |
record |
jsonb | yes | When done, the reproducibility record (data model Run): versions, hashes, settings, warnings. |
|
error |
varchar | yes | Why the run failed, for people. | |
progress |
jsonb | yes | LLM batches so far: done, from the cache, total. | |
started_by |
varchar(40) | yes | Username of whoever started the run. | |
archived_at |
timestamp with time zone | yes | When the run was archived (hidden by default). | |
archived_by |
varchar(40) | yes | Username of whoever archived the run. | |
created_at |
timestamp with time zone | no | When the row was created. | |
finished_at |
timestamp with time zone | yes | When the run ended, done or failed. |
sessions
A signed-in browser session; the cookie holds the id, the table only its hash.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id_hash |
varchar(64) | no | primary | SHA-256 of the id. |
user_id |
varchar(32) | no | → users.id, indexed |
Who is signed in. |
created_at |
timestamp with time zone | no | When the row was created. | |
last_seen_at |
timestamp with time zone | no | Last use; 14 days unused ends the session. |
trials
A trial: what rule sets, a policy and an LLM would produce; kept a day, never a version.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
dataset_id |
varchar(32) | no | → datasets.id, indexed |
The dataset tried. |
status |
varchar(16) | no | pending, running, done or failed. | |
request |
jsonb | no | What was asked for: rule sets, policy, LLM. | |
result |
jsonb | yes | When done, the analysis and proposals (API TrialOut). |
|
error |
varchar | yes | Why the trial failed, for people. | |
progress |
jsonb | yes | LLM batches so far: done, from the cache, total. | |
started_by |
varchar(40) | no | Username of whoever started the trial; only they can read it. | |
created_at |
timestamp with time zone | no | When the row was created. | |
finished_at |
timestamp with time zone | yes | When the trial ended, done or failed. |
users
A person who signs in: their password hash, admin flag, status and API token hash.
| Column | Type | Empty allowed | Key | Description |
|---|---|---|---|---|
id |
varchar(32) | no | primary | Random hex id. |
username |
varchar(40) | no | Sign-in name: 3–40 of a-z 0-9 . _ -; never changes. | |
display_name |
varchar(200) | no | Name shown to other people. | |
password_hash |
varchar(200) | no | Argon2id hash (pwdlib). | |
is_admin |
boolean | no | The one admin. | |
status |
varchar(16) | no | active or disabled (sign-in refused). | |
may_use_server_llm |
boolean | no | May run LLMs on the server's keys (the admin always may). | |
llm_max_usd_per_run |
float | yes | Cap per run on the server's keys, set by the admin; empty: the server's. | |
own_llm_max_usd_per_run |
float | yes | Cap per run on their own keys, set by the person; empty: the server's. | |
must_change_password |
boolean | no | Set when the admin chose the password; cleared when the user changes it. | |
failed_logins |
integer | no | Wrong passwords in a row; 5 lock the account for 5 minutes. | |
locked_until |
timestamp with time zone | yes | Sign-in refused until then. | |
token_hash |
varchar(64) | yes | SHA-256 of the user's one API token. | |
token_created_at |
timestamp with time zone | yes | When the API token was generated. | |
created_at |
timestamp with time zone | no | When the row was created. | |
last_login_at |
timestamp with time zone | yes | Last successful sign-in. |
Unique together: token_hash; username.
Links between tables
| Column | Refers to | When the referred row is deleted |
|---|---|---|
confidence_policies.owner_id |
users.id |
restrict |
dataset_members.dataset_id |
datasets.id |
cascade |
dataset_members.user_id |
users.id |
cascade |
datasets.owner_id |
users.id |
restrict |
dictionary_versions.dataset_id |
datasets.id |
cascade |
llm_answer_uses.dataset_id |
datasets.id |
cascade |
llm_answer_uses.key |
llm_answers.key |
cascade |
llm_keys.user_id |
users.id |
cascade |
requests.dataset_id |
datasets.id |
cascade |
requests.from_user |
users.id |
cascade |
requests.to_user |
users.id |
cascade |
rule_draft_decisions.dataset_id |
datasets.id |
cascade |
rule_sets.owner_id |
users.id |
restrict |
runs.dataset_id |
datasets.id |
cascade |
sessions.user_id |
users.id |
cascade |
trials.dataset_id |
datasets.id |
cascade |