| Title: | Open Knowledge Format (OKF) Ingestion |
|---|---|
| Description: | Read, validate, and load Open Knowledge Format (OKF) bundles (a directory of markdown files with YAML frontmatter) into a portable DuckDB catalog, build the concept graph, render to HTML, and optionally embed concept bodies for semantic search. Deterministic and agent-free: the same bundle always yields the same catalog, graph, and render, with no LLM calls in the core. Implements the OKF v0.3 specification; bundles that declare an earlier version are read with the fallbacks the specification allows. |
| Authors: | Travis Jakel [aut, cre] |
| Maintainer: | Travis Jakel <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.14.2 |
| Built: | 2026-11-30 22:07:46 UTC |
| Source: | https://github.com/travisjakel/okf-ingest |
Concepts that link to a given concept ("linked from" / backlinks).
okf_backlinks(con, path)okf_backlinks(con, path)
con |
An open DuckDB connection to an okf catalog. |
path |
Bundle-relative concept path. |
Character vector of source concept paths (resolved inbound links).
The agent supplies *values* for the declared 'parameters' and MUST NOT author or edit the computation (SPEC 10.3). Binding the computation with those values into the executable artifact is the consumer's job, and the attester independently re-derives the same binding to compare against what actually ran. Shipping that derivation here – in the deterministic layer, with no execution – is what lets an attester be three lines: bind, canonicalise, compare.
okf_bind(contract, params = list())okf_bind(contract, params = list())
contract |
One row of [okf_computations()]. |
params |
Named list of parameter values. |
Substitution is textual and runtime-agnostic: every occurrence of '@name', '$name' or '{{name}}' becomes the supplied value. An undeclared parameter name and a missing required parameter are both errors, because a silent partial binding is exactly the failure attestation exists to catch.
A list with 'artifact' (the bound text), 'canonical', and 'hash' (sha1 of the canonical form).
Collapses runs of whitespace, trims each line and drops blank lines, so a re-derived binding and a receipt's recorded artifact compare equal despite formatting. Deliberately conservative: it does NOT touch case, comments or token order, because a consumer that normalises too much stops detecting the rewrite it exists to detect.
okf_canonicalize(txt)okf_canonicalize(txt)
txt |
Computation text. |
The canonical form.
Split a concept body into chunks on paragraph boundaries.
okf_chunk_body(body, target_chars = 600L)okf_chunk_body(body, target_chars = 600L)
body |
Concept body text. |
target_chars |
Approximate maximum chunk size in characters. |
Character vector of chunks.
Operates on the undirected resolved-link graph. Each node starts in its own community; nodes iteratively adopt the most common label among neighbours, ties broken by the lexicographically smallest label (so the result is fully reproducible – no randomness). Isolated nodes keep their own label.
okf_clusters(con, max_iter = 50L, include_reserved = FALSE)okf_clusters(con, max_iter = 50L, include_reserved = FALSE)
con |
An open DuckDB connection to an okf catalog. |
max_iter |
Maximum propagation sweeps. |
include_reserved |
Include reserved concepts ('index.md'/'log.md') as nodes – useful for graph visualization, where 'index.md' is the hub. |
A data.frame with 'path' and integer 'cluster' (1-based, stable order).
Reads and binds only – nothing here executes or attests anything. The computation is either an inline fenced block under a '# Computation' heading (SPEC 10.3) or a file named by the 'computation' path field; declaring both, or neither, is a defect [okf_doctor()] reports.
okf_computations(rd, now = NULL)okf_computations(rd, now = NULL)
rd |
A bundle as returned by [okf_read()]. |
now |
Reference time passed through to [okf_trust()]. |
A data.frame with 'path', 'title', 'runtime', 'computation_path', 'computation' (the text, from whichever form is present), 'form' ('inline'/'file'/'none'/'both'), 'n_parameters', 'parameters' (JSON), 'executor', 'receipt' (JSON), 'attester', plus 'status', 'stale_after', 'is_stale' and 'trust_tier' from [okf_trust()], and 'attestable': SPEC 10.2 and 10.3 say a value MUST NOT be shown as attested without a 'runtime' and an attester, and that a computation which cannot be found makes the concept not attestable.
This is the OKF / "LLM wiki" consume primitive (Karpathy): hand the agent 'index.md' plus the relevant concept(s) and their link-neighborhood to read directly. It uses the concept graph – **no embeddings, no vector search**. With 'start', it walks the (undirected) link graph from that concept to 'depth'; without 'start', it packs all concepts. Output is capped to roughly 'max_tokens' (estimated at ~4 chars/token).
okf_context( con, start = NULL, depth = 1L, max_tokens = 8000L, include_index = TRUE, rank = c("bfs", "ppr"), query = NULL, now = NULL, current_only = FALSE )okf_context( con, start = NULL, depth = 1L, max_tokens = 8000L, include_index = TRUE, rank = c("bfs", "ppr"), query = NULL, now = NULL, current_only = FALSE )
con |
An open DuckDB connection to an okf catalog. |
start |
Optional concept path to center the neighborhood on. |
depth |
Link-graph radius around 'start' (ignored when 'start' is NULL or when 'rank = "ppr"'). |
max_tokens |
Approximate output budget. |
include_index |
Prepend 'index.md' (the map) when present. |
rank |
Neighborhood selection: '"bfs"' (default; everything within 'depth', in discovery order) or '"ppr"' (rank the whole graph by Personalized PageRank from 'start' via [okf_rank()] and budget-fill by relevance – hubs no longer drown out the pages that matter). |
query |
Free-text query as an alternative to 'start': seed concepts are chosen lexically via [okf_seeds()], then the graph is ranked by multi-seed PPR (weights proportional to lexical scores) and the budget fills by relevance. Deterministic hybrid retrieval – no embeddings. |
now |
Optional ISO-8601 reference time. Supplied, each included concept whose SPEC 5.5 'stale_after' has passed carries a staleness note. Lifecycle state is annotated, never used to demote or drop a concept: SPEC 11 asks a consumer to surface it, and a deprecated concept is still a real link target. |
current_only |
Apply the SPEC 5.4 filter to current knowledge: a concept that is deprecated, or whose 'status' is outside the vocabulary, is left out, and a deprecated concept that names a replacement with 'superseded_by' is swapped for it in place. Off by default: a deprecated concept is still a real link target, and a bundle whose producer writes its own status vocabulary would otherwise lose every page. The result then lists what was 'replaced' and 'excluded', so the filter is never silent. |
A list with 'text' (the markdown blob), 'included'/'omitted' concept paths, 'est_tokens', (for 'query') the 'seeds' used, and (for 'current_only') 'replaced' and 'excluded'.
Compares two bundle states and reports what changed as knowledge structure rather than text hunks: concepts added / removed / changed (by 'content_hash' of the body), frontmatter 'type' and 'title' changes, and concept-graph deltas (resolved edges added/removed, links newly broken or fixed). Fully deterministic: pure hash and set comparison, all output sorted by path, no wall clock.
okf_diff( a, b, bundle_id_a = NULL, bundle_id_b = NULL, untyped = c("skip", "keep") )okf_diff( a, b, bundle_id_a = NULL, bundle_id_b = NULL, untyped = c("skip", "keep") )
a |
The "before" side. |
b |
The "after" side. |
bundle_id_a, bundle_id_b
|
Optional bundle id when a side is a catalog holding more than one bundle. |
untyped |
Passed to [okf_read()] for a side given as a directory: '"skip"' (OKF, the default) or '"keep"' (read a file with no 'type' as a concept anyway, which is what a directory of plain notes needs). |
Each side can be a bundle directory, a bundle from [okf_read()], a path to a '.duckdb' catalog, or an open DBI connection to one. Diffing a catalog against its source directory answers "what drifted since the last ingest"; diffing two directories compares two snapshots.
A list with 'identical' (logical), 'added'/'removed'/'changed' (character path vectors), 'type_changed'/'retitled' (data.frames of 'path'/'from'/'to'), 'links_added'/'links_removed' (data.frames of 'src_path'/'dst_path'), 'broken_added'/'broken_fixed' (data.frames of 'src_path'/'dst_raw'), and 'summary' (named counts, including 'unchanged').
Combines the validation findings already stored in the catalog (conformance errors, files that are not concepts, broken links, orphans, ...) with maintenance checks: duplicate titles; duplicate identity (the same normalized id/alias claimed by more than one concept – breaks by-name/wikilink resolution); hub concentration (info severity: pages whose outbound links mostly point at high in-degree hubs); and, when 'now' is supplied, future/stale timestamps. Health 'score' = the percentage of non-reserved concepts with zero error/warn findings – 'info' findings never affect it. Fully deterministic.
okf_doctor(con, now = NULL, stale_days = NULL)okf_doctor(con, now = NULL, stale_days = NULL)
con |
An open DuckDB connection to an okf catalog. |
now |
Optional ISO-8601 "current time" enabling stale/future-timestamp checks (kept explicit so the function stays deterministic; the CLI passes the wall clock). |
stale_days |
Optional integer; with 'now', flag timestamps older than this many days. |
A list with 'score', 'n_concepts', 'n_healthy', 'n_error', 'n_warn', 'n_info', 'by_rule' (named counts), and 'issues' (a data.frame of path/severity/rule/message; severity is 'error', 'warn', or 'info').
Two mechanical, deterministic repairs (never invents content):
**timestamps** – a parseable non-ISO 'timestamp:' is rewritten to ISO-8601.
**moved links** – a broken link whose basename matches *exactly one* concept is re-pointed to that concept (relative to the linking file).
Edits files in place. Anything ambiguous is left for [okf_doctor()] to report. Pages carrying 'reviewed: true' in frontmatter are human-validated and are never modified (protected pages).
okf_doctor_fix(root)okf_doctor_fix(root)
root |
A bundle directory path. |
A data.frame of changes ('path', 'kind', 'before', 'after'); zero rows if nothing was safely fixable.
Populates 'okf_chunk' with one row per chunk plus its embedding vector and the concept's 'content_hash'. By default replaces all chunks. With 'incremental = TRUE', only concepts whose 'content_hash' differs from what was last embedded are re-embedded (and removed concepts' chunks are dropped) – the expensive embedder calls are skipped for unchanged concepts.
okf_embed(con, embedder = NULL, target_chars = 600L, incremental = FALSE)okf_embed(con, embedder = NULL, target_chars = 600L, incremental = FALSE)
con |
An open DuckDB connection to an okf catalog. |
embedder |
An embedder function; defaults to [okf_ollama_embedder()]. |
target_chars |
Approximate chunk size in characters. |
incremental |
Re-embed only concepts whose content changed. |
The number of chunks (re)written this call (invisibly usable as an integer).
Fenced code is masked first. Inline '[text](target)' links come first, in document order, then reference-style links in definition order. A reference-style link is counted once per *definition* that the body uses, not once per use: '[text][label]', '[label][]' and '[label]' all point at the one '[label]: target' line. A definition is used when '[label]' occurs anywhere outside the definition lines, labels compared case-insensitively (ASCII) with whitespace collapsed. The first definition of a label wins. A label that starts with '^' is a footnote, not a link.
okf_extract_links(body)okf_extract_links(body)
body |
Concept body text. |
Character vector of raw link targets (as written).
Supports '[[target]]' and '[[target|display]]'; strips the display text and any '#anchor', returning the reference as written. These are resolved by name (id / alias / title / filename-stem) rather than by path – see [okf_links()] – so they work with Obsidian/Logseq/Foam-style vaults and stay valid across file renames.
okf_extract_wikilinks(body)okf_extract_wikilinks(body)
body |
Concept body text. |
Character vector of raw wikilink references (as written).
Local directories are used in place. Git URLs (github/gitlab/bitbucket, '.git', or 'git@') are shallow-cloned. Tar/zip archives (local path or 'http(s)' URL) are downloaded if remote and extracted. The caller MUST invoke the returned 'cleanup()' when done to remove any temporary files.
okf_fetch(source, subdir = NULL, branch = NULL)okf_fetch(source, subdir = NULL, branch = NULL)
source |
A directory path, git URL, or tar/zip path/URL. |
subdir |
Optional bundle path within the cloned/extracted tree. |
branch |
Optional git branch or tag (git sources only). |
A list with 'dir' (the resolved bundle directory), 'source_kind' ('"dir"'/'"git"'/'"tar"'/'"zip"'), and 'cleanup' (a function).
A force-directed graph drawn on a '<canvas>' with hand-rolled vanilla JS (no CDN, no framework) – pan, zoom, drag, type-to-search, nodes coloured by community ([okf_clusters()]). Clicking a node navigates to its rendered '.html' (relative), so dropping 'graph.html' into an [okf_html()] site root makes the graph a live map of the site. Fully offline; embeds the node/edge model as JSON.
okf_graph_html(con, out, site_title = NULL)okf_graph_html(con, out, site_title = NULL)
con |
An open DuckDB connection to an okf catalog. |
out |
Output '.html' file path. |
site_title |
Optional page title; defaults to the bundle directory name. |
The output path (invisibly).
Returns a JSON object with 'nodes' and 'edges'. Nodes carry 'id' (path), 'type', 'title', 'tags', 'cluster' (from [okf_clusters()]), and 'href' (the rendered '.html' path). Edges are resolved links with 'source' and 'target' fields. Feeds any external graph visualizer – the same "core is a contract" idea as the DuckDB catalog.
okf_graph_json(con, pretty = TRUE)okf_graph_json(con, pretty = TRUE)
con |
An open DuckDB connection to an okf catalog. |
pretty |
Pretty-print the JSON. |
A JSON string (invisibly also suitable for writing to a file).
A text diagram for embedding directly in markdown (READMEs, docs, GitHub renders it natively) – the lightweight complement to the interactive [okf_graph_html()]. Node ids are sanitized; labels are the concept titles.
okf_graph_mermaid(con)okf_graph_mermaid(con)
con |
An open DuckDB connection to an okf catalog. |
A Mermaid diagram as a single string (a ““ “'mermaid ““ block).
Two modes. As a navigable **site** ('single = FALSE', the default), writes one self-contained ‘.html' per concept under 'out/' (mirroring the bundle’s directory tree) plus an 'index.html' landing page; internal '.md' links are rewritten to '.html'. As a **single file** ('single = TRUE'), writes one self-contained '.html' at path 'out', with each concept an anchored '<section>' and intra-bundle links rewritten to in-page anchors. No JavaScript; CSS is inlined so output is portable. Reserved concepts ('index.md', 'log.md') are rendered too. Bodies are rendered with the commonmark package; broken/orphan links are surfaced in a per-page footer badge from the validation findings.
okf_html(con, out, single = FALSE, site_title = NULL)okf_html(con, out, single = FALSE, site_title = NULL)
con |
An open DuckDB connection to an okf catalog (from [okf_ingest()]). |
out |
Output directory (site mode) or output '.html' file path (single). |
single |
Emit one self-contained file instead of a per-concept site. |
site_title |
Optional title for the landing page / single-file header; defaults to the bundle directory name. |
A list with 'files' (paths written), 'n_concepts', and 'mode' (invisibly).
Reports what the ignore file is doing, so an over-broad pattern cannot quietly shrink a bundle: an ignored file produces no findings at all, which is indistinguishable from a clean one unless something counts it.
okf_ignored(root)okf_ignored(root)
root |
Path to the bundle directory. |
Character vector of bundle-relative paths, possibly empty.
Reports direct 'outbound' (concepts it links to), direct 'inbound' (concepts linking to it, i.e. backlinks), and 'transitive' – every concept that can reach it by following resolved links (what a change here could ripple to).
okf_impact(con, path)okf_impact(con, path)
con |
An open DuckDB connection to an okf catalog. |
path |
Bundle-relative concept path. |
A list with 'path', 'outbound', 'inbound', 'transitive' (all sorted character vectors).
Reads, validates, and loads the bundle into the 'okf_bundle', 'okf_concept', 'okf_link', and 'okf_validation' tables of a (file or in-memory) DuckDB database.
okf_ingest( root, db_path = ":memory:", ingested_at = NULL, bundle_id = NULL, source_kind = "dir", subdir = NULL, branch = NULL, incremental = FALSE, untyped = c("skip", "keep") )okf_ingest( root, db_path = ":memory:", ingested_at = NULL, bundle_id = NULL, source_kind = "dir", subdir = NULL, branch = NULL, incremental = FALSE, untyped = c("skip", "keep") )
root |
A bundle directory path, a git URL, a tar/zip path or URL, or a bundle list from [okf_read()]. Non-directory sources are fetched via [okf_fetch()] and cleaned up afterwards. |
db_path |
DuckDB path; defaults to in-memory '":memory:"'. |
ingested_at |
Optional ISO-8601 timestamp; defaults to the current time. |
bundle_id |
Optional stable bundle id. |
source_kind |
How the bundle was obtained (e.g. '"dir"'); auto-set for fetched sources. |
subdir |
Optional bundle path within a cloned/extracted source. |
branch |
Optional git branch or tag (git sources only). |
incremental |
Only rewrite concepts whose 'content_hash' changed since a prior ingest of the same bundle into 'db_path' (added/removed handled too); links and validation are always recomputed (they are graph-global). Falls back to a full load if the bundle is not already present. The 'summary' then includes 'changed'/'added'/'removed'/'cached' counts. |
untyped |
Passed to [okf_read()]: '"skip"' (OKF, the default) or '"keep"' (read a file with no 'type' as a concept anyway). |
A list with the open 'con', the 'bundle_id', and a 'summary' (counts, conformance, link totals). The caller owns/closes 'con'.
Three edge sources, in this order: markdown links, inline and reference-style (resolved by path), '[[wikilink]]' references (resolved by name: id / alias / title / stem), and the path fields of SPEC 6.2 – 'resource', 'computation', 'executor.resource', 'attester.resource', 'sources[].resource' and 'superseded_by'. That last group carries the derivation, execution and replacement edges, which appear nowhere in the body. Wikilinks are an okf extension – SPEC 6.1 says they "are not links in OKF" – and carry 'kind = "wikilink"' so a consumer can leave them out.
okf_links(rd)okf_links(rd)
rd |
A bundle as returned by [okf_read()]. |
'target' says what the reference points at: '"concept"' (the only case that forms a graph edge), '"file"' (a real non-concept file in the bundle, such as an attester '.py' – present, so not broken), '"dir"' (a directory of the bundle, which an index entry links to on purpose), '"scope"' (a SPEC 5.1 scope descriptor, not a path at all), or '"missing"'. A bare '#fragment' and a target that leaves the bundle root produce no row.
A data.frame with 'src_path', 'dst_raw', 'dst_path', 'resolved', 'kind' ('body'/'wikilink'/'resource'/'computation'/'executor'/'attester'/ 'source'/'superseded_by') and 'target'.
An embedder is a function of 'texts' returning a list of numeric vectors. Swap in any such function (e.g. an OpenAI client) for [okf_embed()] / [okf_rag()].
okf_ollama_embedder( model = "nomic-embed-text", url = NULL, embed_texts = getOption("okf.embed_texts") )okf_ollama_embedder( model = "nomic-embed-text", url = NULL, embed_texts = getOption("okf.embed_texts") )
model |
Embedding model name. |
url |
Optional base URL of an Ollama host. An explicit value still means "that Ollama box"; leave it 'NULL' to resolve from the environment. |
embed_texts |
Optional '(texts, model, url) -> matrix' backend. Defaults to 'getOption("okf.embed_texts")', and to the built-in client when unset. |
The endpoint is resolved, never hard-coded: llama-server / llama-swap speak the OpenAI ‘/v1/embeddings' shape and do NOT serve Ollama’s '/api/embeddings'. Resolution order is 'url', then 'LLM_EMBED_URL', then 'LLM_LOCAL_BACKEND=llamaswap' (via 'LLAMASWAP_URL'), then 'OLLAMA_URL'. The request/response shape follows from the resolved path, so a host that names 'OLLAMA_URL' keeps working untouched. Mirrors 'okf.rag._embed_endpoint'.
A host project may instead supply its own backend with 'embed_texts': a function '(texts, model, url) -> matrix' with one row per text, settable once per session via 'options(okf.embed_texts = <fn>)'.
A function 'texts -> list(numeric)'. Requires the httr2 package.
Parse the YAML frontmatter and body of a single OKF concept file.
okf_parse_file(path)okf_parse_file(path)
path |
Path to a markdown file. |
A list with 'meta' (parsed frontmatter, or 'NULL'), 'body', and 'err' ('NA' on success, else '"no_frontmatter"', '"unclosed_frontmatter"', '"duplicate_key"' or '"yaml_parse_error"').
Query helpers over an ingested OKF catalog.
okf_concepts(con) okf_graph_df(con) okf_findings(con) okf_search(con, term, current_only = FALSE)okf_concepts(con) okf_graph_df(con) okf_findings(con) okf_search(con, term, current_only = FALSE)
con |
An open DuckDB connection to an okf catalog. |
term |
Search term for [okf_search()] (matched against concept bodies). |
current_only |
For [okf_search()]: apply the SPEC 5.4 filter to current knowledge, leaving out deprecated concepts and concepts whose 'status' is outside the vocabulary. |
A data.frame: concepts ([okf_concepts]), link edges ([okf_graph_df]), validation findings ([okf_findings]), or body matches ([okf_search]).
Embeds ‘query' and returns the top-k most cosine-similar chunks (via DuckDB’s native 'list_cosine_similarity'). Run [okf_embed()] first.
okf_rag(con, query, embedder = NULL, k = 5L)okf_rag(con, query, embedder = NULL, k = 5L)
con |
An open DuckDB connection to an embedded okf catalog. |
query |
Query string. |
embedder |
An embedder function; defaults to [okf_ollama_embedder()]. |
k |
Number of results to return. |
A data.frame with 'path', 'title', 'chunk_id', 'score', 'text'.
Exact power-iteration PPR seeded at 'start', over the undirected resolved-link graph. Deterministic: no sampling, fixed lexicographic node order, scores rounded to 10 decimals. Reserved pages (index.md / log.md) participate in the walk (they carry real link structure) but can be filtered by the caller.
okf_rank( con, start, damping = 0.85, tol = 1e-12, max_iter = 200L, k = 20L, weights = NULL )okf_rank( con, start, damping = 0.85, tol = 1e-12, max_iter = 200L, k = 20L, weights = NULL )
con |
An open DuckDB connection to an okf catalog. |
start |
Concept path(s) to personalize on. A vector spreads the teleport across several seeds (see 'weights') – this is how [okf_context()] serves free-text queries via [okf_seeds()]. |
damping |
Continue-walk probability (teleport = 1 - damping). |
tol |
L1 convergence tolerance. |
max_iter |
Iteration cap. |
k |
Return the top k concepts (Inf for all with score > 0). |
weights |
Optional non-negative weights for multiple 'start' seeds (normalized internally; default equal). |
A data.frame of 'path', 'score', 'title', 'reserved', sorted by score descending (ties broken by path).
A '.md' file is a concept when it is not reserved ('index.md', 'log.md'), is not excluded by '.okfignore', and has frontmatter with a non-empty 'type' (SPEC 3.2). A file with no frontmatter or no 'type' is skipped: it stays in the file set, so a link to it still resolves, and it is reported as 'not_a_concept', never as an error.
okf_read( root, bundle_id = NULL, source_kind = "dir", untyped = c("skip", "keep") )okf_read( root, bundle_id = NULL, source_kind = "dir", untyped = c("skip", "keep") )
root |
Path to the bundle directory. |
bundle_id |
Optional stable id; defaults to a hash of the root path. |
source_kind |
How the bundle was obtained (e.g. '"dir"'). |
untyped |
What to do with a '.md' file that has no frontmatter or no non-empty 'type'. '"skip"' (the default) is OKF: the file is not a concept. '"keep"' reads it as a concept anyway, with no type – an okf extension for a notes vault or any directory of markdown that was never written as OKF, where '"skip"' would leave nothing to read. Each kept file is reported as 'untyped_concept'. |
A list with 'bundle_id', 'root', 'okf_version', 'source_kind', 'concepts' (parsed per-file records), 'known' (all concept paths), 'files' (every file in the tree), 'dirs', 'ignored', 'not_concepts', the SPEC 8.1 bundle metadata 'title' / 'description' / 'license', and 'root_fallback' (whether the declared version still allows the v0.2 path fallback).
Resolve a markdown link target to a bundle-relative concept path.
okf_resolve_link(raw, src_rel, known)okf_resolve_link(raw, src_rel, known)
raw |
Raw link target. |
src_rel |
Bundle-relative path of the linking concept. |
known |
Character vector of all known concept paths in the bundle. |
The resolved bundle-relative path, or 'NA' if it does not resolve.
SPEC 6 first: a leading '/' is from the bundle root, anything else from the directory of the concept's own file. If that names nothing and 'fallback' is set, the value is tried from the bundle root.
okf_resolve_path(raw, src_rel, targets, fallback = TRUE, dirs = character(0))okf_resolve_path(raw, src_rel, targets, fallback = TRUE, dirs = character(0))
raw |
The field value as written. |
src_rel |
Bundle-relative path of the concept carrying the field. |
targets |
Character vector of candidate bundle-relative paths. |
fallback |
Whether a value that does not resolve from its own file may be tried from the bundle root. |
dirs |
Character vector of the bundle's directories; a path field may name one. |
The fallback is the v0.2 reading. Upstream's v0.2 reference bundles wrote root-relative paths *without* the leading slash (12 of 12 in 'acme_retail'), so v0.3 keeps it for a bundle that declares 'okf_version' 0.2 or earlier, or no version, and for no other (SPEC 6.2, 12.1). Pass 'fallback = rd$root_fallback'.
A list with 'path' (or 'NA') and 'how': '"spec"', '"root"', '"external"' (the value leaves the bundle root) or 'NA' (it names nothing).
Tokenizes 'query' (lowercase alphanumeric runs, length >= 3, fixed stopword list) and scores every non-reserved concept by simple term presence: +3 per distinct token found in the title, +2 in the description or tags, +1 in the body. No embeddings, no model – the same query always yields the same seeds. Feed the result to [okf_rank()] as multi-seed personalization (done for you by 'okf_context(query = ...)').
okf_seeds(con, query, k = 5L)okf_seeds(con, query, k = 5L)
con |
An open DuckDB connection to an okf catalog. |
query |
Free-text query. |
k |
Number of seed concepts to return. |
A data.frame of 'path', 'score', 'title' for concepts with score > 0, sorted by score descending (ties by path); zero rows if nothing matches.
One row per 'sources[]' entry, with the per-source credibility signals kept as authored – the spec records signals and refuses to store a score, so this does not compute one either. 'cited' records whether the body attributes a claim to the entry through a markdown footnote whose label is the entry's 'id': the join key the spec defines, keyed rather than positional so that reordering the list cannot silently misattribute.
okf_sources(rd)okf_sources(rd)
rd |
A bundle as returned by [okf_read()]. |
A data.frame with 'path', 'idx', 'id', 'resource', 'title', 'author', 'usage_count', 'last_modified', 'is_scope', 'cited'.
Trust tiers follow SPEC 5.3: no *current* verification event is 'unverified', current events by non-'human:' actors only is 'machine-confirmed', and a current event by a 'human:<id>' actor is 'human-reviewed'. An event is current when it is at or after 'generated.at', so a review of an earlier text does not count. Staleness follows SPEC 5.5: a concept is stale when 'now >= stale_after', an absolute instant, and a 'stale_after' that does not parse is never treated as fresh.
okf_trust(rd, now = NULL)okf_trust(rd, now = NULL)
rd |
A bundle as returned by [okf_read()]. |
now |
Reference time as an ISO-8601 string; defaults to the current UTC time. Supply it to keep a report reproducible. |
A data.frame with one row per concept: 'path', 'status' ('NA' when absent or outside the SPEC 5.4 vocabulary), 'status_raw', 'stale_after', 'is_stale', 'trust_tier', 'verified_at' (the latest valid event), 'verified_by', 'generated_by', 'n_verified' (valid events), 'is_current' (the SPEC 5.4 filter to current knowledge: stable or draft, so neither deprecated nor a status outside the vocabulary), 'superseded_by', 'stale_after_malformed' and 'n_current' (events that count toward the tier).
Errors are exactly the conformance failures SPEC 11.1 names: a frontmatter block that is not a YAML mapping with unique keys ('frontmatter_unparseable', 'duplicate_key'), and a reserved file that breaks section 8 or 9 ('index_frontmatter', 'log_frontmatter', 'log_heading_not_date'). Everything else is a warning or an info note: a '.md' file that is not a concept ('not_a_concept'), missing recommended fields, non-ISO timestamps, broken links, orphans. Never rejects the bundle – returns findings.
okf_validate(rd)okf_validate(rd)
rd |
A bundle as returned by [okf_read()]. |
A data.frame with 'path', 'severity', 'rule', 'message'.