Skip to main content

Querying Google’s Open Knowledge Format from R

R
OKF
DuckDB
RAG
knowledge
data.table

The Open Knowledge Format stores curated knowledge for AI agents as a folder of markdown files. This post validates one from R, loads it into a DuckDB catalog, and queries its graph, its trust and lifecycle fields, and its text.

Author

Travis Jakel

Published

June 22, 2026

Modified

November 30, 2026

Rewritten on 2026-11-30 for OKF v0.3 and okf 0.14.2. The June version of this post covered v0.1.

The Open Knowledge Format (OKF) is a vendor-neutral way to write down the curated knowledge an AI agent needs as context. Google Cloud proposed it in June 2026 and the spec, now at v0.3, lives in its own organisation. The format is plain: a directory of markdown files with YAML frontmatter, one concept per file, with markdown links between files forming a graph. If you can read a text file, you can read OKF.

What the format does not give you is a way to query a bundle. I wrote okf-ingest for that. Its R package, okf, reads a bundle, validates it, and loads it into a DuckDB catalog that you work with through DBI and, here, data.table. Disclosure: it is my package.

Install, and get a bundle

install.packages("okf", repos = c(
  travisjakel = "https://travisjakel.r-universe.dev",
  CRAN        = "https://cloud.r-project.org"
))

CRAN carries an older release of okf. Everything below needs the r-universe build.

The spec repository ships four reference bundles. This post uses acme_retail, a small finance knowledge base with metrics, policies and attested SQL computations.

git clone --depth 1 https://github.com/open-knowledge-format/open-knowledge-format.git

Validate, permissively

OKF’s conformance bar is deliberately low. A file with no frontmatter or no type is simply not a concept. Broken links, missing recommended fields and unknown types are findings, never rejections.

library(okf)
library(DBI)
library(data.table)

B   <- "open-knowledge-format/bundles/acme_retail"
rd  <- okf_read(B)
val <- as.data.table(okf_validate(rd))
val[, .N, by = .(severity, rule)]
#>    severity               rule N
#> 1:     info non_concept_target 3

Three informational findings and nothing else. They say that some concepts point at a Python file in the bundle, which is a real file but not a concept.

Load it into DuckDB

res <- okf_ingest(B, db_path = "kb.duckdb")
str(res$summary)
#> List of 9
#>  $ n_files     : int 17
#>  $ n_concepts  : int 9
#>  $ n_conformant: int 9
#>  $ conformant  : logi TRUE
#>  $ errors      : int 0
#>  $ warnings    : int 0
#>  $ links_total : int 44
#>  $ links_broken: int 0
#>  $ not_concepts: int 0
con <- res$con

res$con is an ordinary DuckDB connection. From here it is DBI and data.table:

dbGetQuery(con, "SELECT okf_version, title, n_concepts, conformant FROM okf_bundle")
#>   okf_version       title n_concepts conformant
#> 1         0.3 Acme Retail          9       TRUE

concepts <- as.data.table(dbGetQuery(con, "SELECT path, type, title FROM okf_concept WHERE NOT reserved"))
concepts[, .N, by = type][order(-N, type)]
#>                    type N
#> 1:               Metric 3
#> 2: Attested Computation 2
#> 3:               Policy 2
#> 4:       BigQuery Table 1
#> 5:                Skill 1

type is a free string, not an enum. The bundle’s author chose these five. The catalog is a single file, and the Python package writes the same tables, so a bundle ingested in one language can be queried from the other.

Trust and lifecycle

A concept can say who verified it, when, and whether it is still current. okf_trust() reads those fields into one row per file.

tr <- as.data.table(okf_trust(rd))
tr[!is.na(status), .(path, status, trust_tier, verified_at, is_current)]
#>                                   path     status     trust_tier          verified_at is_current
#> 1: computations/gross-margin-period.md     stable human-reviewed 2026-07-01T09:00:00Z       TRUE
#> 2:         computations/revenue-ytd.md     stable human-reviewed 2026-07-01T09:00:00Z       TRUE
#> 3:      metrics/gross-margin-legacy.md deprecated human-reviewed 2024-01-15T10:00:00Z      FALSE
#> 4:             metrics/gross-margin.md     stable human-reviewed 2026-07-01T09:00:00Z       TRUE
#> 5:                  metrics/revenue.md     stable human-reviewed 2026-07-01T09:00:00Z       TRUE
#> 6:         policies/margin-standard.md     stable human-reviewed 2026-06-15T09:00:00Z       TRUE
#> 7:     policies/revenue-recognition.md     stable human-reviewed 2026-06-15T09:00:00Z       TRUE
#> 8:                 skills/run-on-bq.md     stable     unverified                 <NA>       TRUE
#> 9:                    tables/orders.md     stable human-reviewed 2026-07-01T16:00:00Z       TRUE

One metric is deprecated. An agent that retrieves it by keyword would use a definition the finance team retired. current_only drops concepts that are not current:

hits <- as.data.table(okf_search(con, "gross margin"))
hits[!is.na(type), .(path, title)]
#>                               path                                                    title
#> 1:  metrics/gross-margin-legacy.md                        Gross Margin (legacy, pre-FY2026)
#> 2:         metrics/gross-margin.md                                             Gross Margin
#> 3:     policies/margin-standard.md Acme Retail — Cost Allocation & Margin Standard (FY2026)
#> 4: policies/revenue-recognition.md        Acme Retail — Revenue Recognition Policy (FY2026)

hits <- as.data.table(okf_search(con, "gross margin", current_only = TRUE))
hits[!is.na(type), .(path, title)]
#>                               path                                                    title
#> 1:         metrics/gross-margin.md                                             Gross Margin
#> 2:     policies/margin-standard.md Acme Retail — Cost Allocation & Margin Standard (FY2026)
#> 3: policies/revenue-recognition.md        Acme Retail — Revenue Recognition Policy (FY2026)

Context for a model, without embeddings

The format’s own idea of retrieval is not vector search. It is: read the index, then follow links. okf_context() does that. It seeds on the concepts whose text matches the question, follows their links outward, and packs whole concepts into a token budget as one markdown string.

ctx <- okf_context(con, query = "how is revenue recognized", max_tokens = 1500)
ctx$est_tokens
#> [1] 1409
ctx$included
#> [1] "computations/revenue-ytd.md"     "policies/revenue-recognition.md" "metrics/revenue.md"
length(ctx$omitted)
#> [1] 6

ctx$text is ready to paste into a prompt. It is deterministic: the same bundle and question give the same string, and no model is involved.

Semantic search, no vector database

For a large bundle, or questions that share no words with the answer, embed the concept bodies. okf_embed() chunks and embeds them and stores the vectors in the same catalog. The default embedder is a local Ollama nomic-embed-text, so nothing leaves your machine, and any function from texts to vectors can replace it.

okf_embed(con)
#> [1] 32

hits <- as.data.table(okf_rag(con, "how is revenue recognized?", k = 3))
hits[, .(path, title, score = round(score, 3))]
#>                               path                                             title score
#> 1: policies/revenue-recognition.md Acme Retail — Revenue Recognition Policy (FY2026) 0.729
#> 2: policies/revenue-recognition.md Acme Retail — Revenue Recognition Policy (FY2026) 0.713
#> 3:              metrics/revenue.md                                           Revenue 0.712

The search is a brute-force cosine in DuckDB over the stored vectors. No vector extension is required.

Straight from a URL

okf_ingest() also takes a git URL or a tar/zip archive. It fetches to a temporary directory, finds the bundle, and cleans up:

btc <- okf_ingest("https://github.com/open-knowledge-format/open-knowledge-format.git",
                  subdir = "bundles/crypto_bitcoin", db_path = "btc.duckdb")
as.data.table(btc$summary[c("n_concepts", "conformant", "errors", "warnings", "links_total", "links_broken")])
#>    n_concepts conformant errors warnings links_total links_broken
#> 1:          9       TRUE      0        0          39            0

Scope, honestly

  • OKF is young. v0.3 made breaking changes to v0.2, and it may change again.
  • Validators are plentiful. If you only need a linter, there are several. okf is for the step after: a queryable catalog, the graph, lifecycle-aware retrieval, and the same result from R and Python.
  • Some features are mine, not OKF’s. [[wikilinks]], a .okfignore file and a .okfstatus file are okf-ingest extensions. The spec says wikilinks are not links in OKF.
  • A catalog records where it was built. okf_bundle.root holds the path the bundle was read from. Check it before you publish a .duckdb file.

Links: okf-ingest · r-universe · OKF spec. Issues and pull requests are welcome.

Run with okf 0.14.2 installed from r-universe, R 4.5.0, duckdb 1.3.2 and data.table 1.17.6, against the spec repository at commit 527e81a. Embeddings came from nomic-embed-text on a local server. The script that produced every output above is in this blog’s repository under _runs/okf_r_intro.R.