open-knowledge-format README

The project's README from github.com/GoogleCloudPlatform/open-knowledge-format. As one markdown file: README.md.

Open Knowledge Format (OKF)

📖 Read the Open Knowledge Format v0.2 specification → SPEC.md

This repository is primarily about the Open Knowledge Format (OKF).

OKF is a universal, vendor-neutral format for representing knowledge as plain markdown files with YAML frontmatter. It is not tied to any particular agent, framework, model provider, or serving system. The goal is simple:

  • Anyone can produce OKF — humans authoring by hand, agents built on any framework (Google ADK, LangChain, custom), export pipelines from existing catalogs (Dataplex, Unity Catalog, Collibra, …), or scripts walking a database.
  • Anyone can serve and consume OKF — a static file server, a knowledge-management UI (Obsidian, Notion, MkDocs), an LLM loading files into context, a search index, or a graph viewer like the one bundled in this repo.

The agent below is a proof of concept demonstrating one way to produce OKF bundles automatically. The format itself is the contribution; this agent and the visualizer exist to make the format tangible at both ends — production and consumption.

See OKF in practice — three ready-to-browse bundles produced by this agent, checked into bundles/:

Why OKF?

OKF represents catalog knowledge as plain markdown files with YAML frontmatter, organized in a directory hierarchy. That choice unlocks a few properties that are hard to get from a service-owned metadata store:

The net effect is that reference agents, consumption agents, and humans collaborate on the same artifacts in the same way they already collaborate on source code.

Install

python3.13 -m venv .venv
.venv/bin/pip install --index-url https://pypi.org/simple/ -e .[dev]

Credentials

How the reference agent works

The reference agent runs in two passes. The BQ pass writes one OKF doc per concept the source advertises, using BigQuery metadata alone. The web pass then runs the LLM as its own crawler: it receives a list of seed URLs (provided via --web-seed or --web-seed-file), fetches the seeds via the fetch_url tool, and decides which outbound links are worth following based on whether they look like authoritative documentation for the existing concepts. For each page it fetches, the agent chooses to (a) enrich one or more existing concept docs, (b) mint a standalone references/<slug> doc, or (c) skip. A hard --web-max-pages cap and a same-domain allowed-hosts filter (configurable via --web-allowed-host) are enforced inside the tool, so the agent cannot overrun. Use --no-web to skip the web pass.

Run

Minimum invocation — point at a BigQuery dataset and a bundle output directory. Seeds for the web pass are explicit; omit them (or pass --no-web) to run BQ-only:

.venv/bin/python -m reference_agent enrich \
    --source bq \
    --dataset <project>.<dataset> \
    --web-seed-file <path/to/seeds.txt> \
    --out ./bundles/<name>

Iterate on a single concept by adding --concept <type>/<name> (e.g. --concept tables/events_); repeatable.

Samples

Each sample pairs a recipe (samples/<name>/, with the seed URLs and exact enrich command) with the produced bundle (bundles/<name>/) that the recipe generated. Open the recipe to reproduce; open the bundle to browse the result directly.

Visualize

The visualize subcommand renders any OKF bundle as a self-contained interactive HTML file — one file, no backend, no install on the viewing side. Open it in any modern browser, share it as an artifact, host it on a static file server, or commit it next to the bundle (as this repo does).

The viewer is itself a proof-of-concept consumer of OKF, mirroring the way the reference agent is a proof-of-concept producer. OKF bundles can be consumed by anything that reads markdown; this is just one shape.

What it shows

Generate

.venv/bin/python -m reference_agent visualize --bundle ./bundles/<name>

That writes bundles/<name>/viz.html. Flags:

Flag Default Description
--bundle (required) Bundle root directory.
--out <bundle>/viz.html Output HTML path.
--name bundle directory name Display name shown in the viewer header.

Example, writing the output somewhere else and overriding the header:

.venv/bin/python -m reference_agent visualize \
    --bundle ./bundles/crypto_bitcoin \
    --out /tmp/btc.html \
    --name "Bitcoin OKF"

How it's built

The HTML embeds the bundle as a JSON blob and uses Cytoscape.js for the graph and marked for in-browser markdown rendering, both loaded from a CDN. No data leaves the page; the bundle is parsed once at generation time and serialized into the file.

Tests

.venv/bin/pytest

open-knowledge-format (GoogleCloudPlatform/open-knowledge-format)

Searching Database…

这是什么?OKF(Open Knowledge Format)是 Google Cloud 推出的一个供应商中立的规范,用于将目录知识表示为带 YAML frontmatter 的纯 markdown 文件,不绑定任何特定的代理、框架或模型提供商。本仓库还附带一个生成 OKF bundle 的参考代理和一个渲染它们的可视化工具。
这只是一个文件格式规范,还是也包含可用的工具?两者都是:SPEC.md 定义了 v0.2 格式本身,仓库还附带一个概念验证的 Python 代理,可从 BigQuery 和网页文档自动生成 OKF bundle,另有一个独立的 visualize 命令,能把任何 bundle 变成交互式 HTML 图谱。
怎么用参考代理生成 OKF bundle?把代理指向一个 BigQuery 数据集和一个输出目录;它会根据 BigQuery 元数据为每个概念写一份文档,然后可选地抓取你通过 --web-seed 传入的种子 URL 来充实这些文档,之后你可以运行 visualize 子命令生成 viz.html。
参考代理运行之前需要什么凭据?你需要通过 application-default login 完成 gcloud 认证,并设置一个结算项目以访问 BigQuery;LLM 方面则需要来自 AI Studio 的 GEMINI_API_KEY,或 Vertex AI 环境变量(GOOGLE_GENAI_USE_VERTEXAI、GOOGLE_CLOUD_PROJECT、GOOGLE_CLOUD_LOCATION)。
代理的网页抓取环节会在整个互联网上乱爬吗?不会——它受 --web-max-pages 上限和同域名允许主机过滤器(通过 --web-allowed-host 配置)的约束,整个网页抓取环节也可以用 --no-web 跳过,只跑 BigQuery。
生成的 viz.html 会把 bundle 数据发送到别处吗?不会。查看器是一个独立的自包含 HTML 文件,bundle 以 JSON 块的形式内嵌其中;在浏览器中打开时不会向外发送任何数据。
仓库附带哪些示例 bundle?bundles/ 中检入了四个可直接浏览的 bundle:GA4(Google Analytics 电商数据集)、Stack Overflow(公开 schema)、Bitcoin(区块/交易)和 Acme Retail,每个都带有自己的 viz.html。
OKF 查看器实际显示什么?一张按类型着色、以连线表示交叉引用的概念力导向图;一个详情面板,显示所选概念的 frontmatter 和渲染后的 markdown;一个「Cited by」反向链接列表;此外还有搜索、类型筛选和可切换的布局(cose、concentric、breadth-first、circle、grid)。
为什么用 markdown 和 YAML frontmatter,而不用数据库支撑的目录?因为它不需要 SDK 就能被人或代理阅读,存放在 git 中便于 diff/PR/评审,以普通可移植文件的形式分发、没有供应商锁定,同时仍允许你查询少量结构化的 frontmatter 字段,例如 type、tags 和信任信号。
可视化工具没有后端怎么渲染图谱?它把整个 bundle 以 JSON 块的形式嵌入单个 HTML 文件,用 Cytoscape.js 绘制图谱、用 marked 在浏览器内渲染 markdown,两者都从 CDN 加载,因此输出文件可以在任何现代浏览器中独立运行。
Size
0.2 MB
Stars
1K
Updated
CommitAug 21
Age
2mo
Commits · 90 Days