Skip to main content

Make any OKF knowledge bundle searchable: DuckDB + embeddings in Python

Python
OKF
DuckDB
RAG
LLM
agents

The Open Knowledge Format describes curated knowledge for AI agents as a folder of markdown files. This post loads one into a DuckDB catalog from Python, then 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-ingest 0.14.2. The June version of this post covered v0.1.

An AI agent is only as good as the context it is given. The Open Knowledge Format (OKF) is a small, vendor-neutral convention for that context: a directory of markdown files with YAML frontmatter, one concept per file, with ordinary links between files forming a graph. There is no database and no required tooling. Google Cloud proposed it in June 2026, and the spec, now at v0.3, lives in its own organisation.

That minimalism leaves a practical question. Once you have a bundle, how do you query it, check it, or feed it to a retrieval pipeline? okf-ingest is my answer: it reads a bundle, validates it the permissive way the spec asks for, and loads it into a DuckDB catalog you can query from Python or R. Disclosure: I wrote it.

Install, and get a bundle

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

pip install okf-ingest
git clone --depth 1 https://github.com/open-knowledge-format/open-knowledge-format.git

Validate

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.

okf validate open-knowledge-format/bundles/acme_retail
#> bundle: open-knowledge-format/bundles/acme_retail
#> conformant: True  (errors: 0, warnings: 0)
#>   [info ] non_concept_target     attesters/index.md — reference resolves to a non-concept file: sql_equality.py
#>   [info ] non_concept_target     computations/gross-margin-period.md — reference resolves to a non-concept file: /attesters/sql_equality.py
#>   [info ] non_concept_target     computations/revenue-ytd.md — reference resolves to a non-concept file: /attesters/sql_equality.py

The three info lines say that some concepts point at a Python file. That is a real file in the bundle, so the link is fine; it just is not a concept. okf validate exits non-zero on a non-conformant bundle, so it works as a CI check.

Load it into DuckDB

okf ingest open-knowledge-format/bundles/acme_retail --db kb.duckdb
#> ingested open-knowledge-format/bundles/acme_retail -> kb.duckdb
#>   concepts=9 conformant=9 (True) errors=0 warnings=0 links=44 broken=0

From here it is plain DuckDB. No okf code is needed to read the catalog:

import duckdb

con = duckdb.connect("kb.duckdb")

con.sql("SELECT okf_version, title, n_concepts, conformant FROM okf_bundle").fetchall()
#> [('0.3', 'Acme Retail', 9, True)]

con.sql("""
    SELECT type, count(*) AS n FROM okf_concept
    WHERE NOT reserved GROUP BY type ORDER BY n DESC, type
""").df()
#>                 type  n
#>               Metric  3
#> Attested Computation  2
#>               Policy  2
#>       BigQuery Table  1
#>                Skill  1

type is a free string, not an enum. The bundle’s author chose these five.

Trust and lifecycle

A concept can say who verified it, when, and whether it is still current. okf trust reads those fields into one line per file: status, trust tier, and the last verification.

okf trust open-knowledge-format/bundles/acme_retail
#> attesters/index.md                             -           unverified       -
#> computations/gross-margin-period.md            stable      human-reviewed   2026-07-01T09:00:00Z
#> computations/index.md                          -           unverified       -
#> computations/revenue-ytd.md                    stable      human-reviewed   2026-07-01T09:00:00Z
#> index.md                                       -           unverified       -
#> log.md                                         -           unverified       -
#> metrics/gross-margin-legacy.md                 deprecated  human-reviewed   NOT-CURRENT 2024-01-15T10:00:00Z
#> metrics/gross-margin.md                        stable      human-reviewed   2026-07-01T09:00:00Z
#> metrics/index.md                               -           unverified       -
#> metrics/revenue.md                             stable      human-reviewed   2026-07-01T09:00:00Z
#> policies/index.md                              -           unverified       -
#> policies/margin-standard.md                    stable      human-reviewed   2026-06-15T09:00:00Z
#> policies/revenue-recognition.md                stable      human-reviewed   2026-06-15T09:00:00Z
#> skills/index.md                                -           unverified       -
#> skills/run-on-bq.md                            stable      unverified       -
#> tables/index.md                                -           unverified       -
#> tables/orders.md                               stable      human-reviewed   2026-07-01T16:00:00Z

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

for flag in (False, True):
    print("current_only =", flag)
    for path, type_, title in okf.search(con, "gross margin", current_only=flag):
        if type_:                       # skip the directory index pages
            print("  ", path, "|", title)
#> current_only = False
#>    metrics/gross-margin-legacy.md | Gross Margin (legacy, pre-FY2026)
#>    metrics/gross-margin.md | Gross Margin
#>    policies/margin-standard.md | Acme Retail — Cost Allocation & Margin Standard (FY2026)
#>    policies/revenue-recognition.md | Acme Retail — Revenue Recognition Policy (FY2026)
#> current_only = True
#>    metrics/gross-margin.md | Gross Margin
#>    policies/margin-standard.md | Acme Retail — Cost Allocation & Margin Standard (FY2026)
#>    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)
print(ctx["est_tokens"], "tokens")
print("included:", ctx["included"])
print("omitted: ", ctx["omitted"])
#> 1409 tokens
#> included: ['computations/revenue-ytd.md', 'policies/revenue-recognition.md', 'metrics/revenue.md']
#> omitted:  ['computations/gross-margin-period.md', 'metrics/gross-margin.md', 'tables/orders.md', 'policies/margin-standard.md', 'skills/run-on-bq.md', 'metrics/gross-margin-legacy.md']

ctx["text"] is ready to paste into a prompt. It is deterministic: the same bundle and question give the same string, with no model involved. For a small, well-linked bundle this is often all the retrieval you need.

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.

print(okf.embed(con), "chunks embedded")
for path, title, chunk, score, text in okf.rag_search(con, "how is revenue recognized?", k=3):
    print(f"[{score:.3f}] {path}#{chunk}  {title}")
#> 32 chunks embedded
#> [0.729] policies/revenue-recognition.md#1  Acme Retail — Revenue Recognition Policy (FY2026)
#> [0.713] policies/revenue-recognition.md#4  Acme Retail — Revenue Recognition Policy (FY2026)
#> [0.712] metrics/revenue.md#1  Revenue

The search is a brute-force cosine over a DuckDB list column. No vector extension is required, which is the right trade for bundles of hundreds to tens of thousands of chunks.

Straight from a URL

You do not need a clone. okf ingest takes a git URL or a tar/zip archive, fetches it to a temporary directory, and cleans up:

okf ingest https://github.com/open-knowledge-format/open-knowledge-format.git \
  --subdir bundles/crypto_bitcoin --db btc.duckdb
#> ingested https://github.com/open-knowledge-format/open-knowledge-format.git -> btc.duckdb
#>   concepts=9 conformant=9 (True) errors=0 warnings=0 links=39 broken=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-ingest is for the step after: a queryable catalog, the graph, lifecycle-aware retrieval, and the same result from Python and R.
  • 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 · PyPI · OKF spec. Issues and pull requests are welcome.

Run with okf-ingest 0.14.2 on Python 3.12.10, against the spec repository at commit 527e81a (2026-11-18). 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_py_intro.py.