Skip to main content

Open Context

Open Context(简称 OCTX)是一种建立在 Google Open Knowledge Format(OKF)之上的开放上下文标准。它把可读 Markdown、稳定身份、版本、完整性信息及可选的 chunks、events、entities、关系和向量封装为可传播的 .octx Package。

Open Context 兼容 SAG 的 Chunk-Event-Entity 超图数据结构,但规范和参考工具不依赖 SAG、zleap-sag、特定数据库或向量后端。

阅读顺序

  1. OCTX v0.1 规范spec-v0.1.md):容器、manifest、知识文档、身份、摘要、版本和扩展规则。
  2. SAG 是什么sag.md):SAG 应用、检索架构、zleap-sag 及其与 OCTX 的关系。
  3. SAG-Structured v0.1 Capabilitysag-structured-v0.1.md):完整的 chunks、events、entities 和关系。
  4. Vectors v0.1 Capabilityvectors-v0.1.md):六种语义角色向量、生成 recipe、输入摘要与兼容性判定。
  5. 工具链概览tooling-lifecycle.md):工具分层及 Asset、Release、Package、Installation 等核心对象。
  6. 构建与集成creating-octx.mdopening-validating-octx.mdimporting-octx.mdexporting-octx.md 分别说明创建、校验、导入和导出。
  7. Python APIapi/overview.md):按功能拆分的创建、读取、校验、安全解包和 CLI 文档。
  8. 机器可读 Schemaschemas/README.md):JSON Schema Draft 2020-12 与语义校验边界。
  9. 领域词汇表GLOSSARY.md):OCTX、SAG 和 zleap-sag 的统一术语。

Python 快速开始

需要 Python 3.11 或更高版本。从 PyPI 安装:

pip install octx

需要向量功能时,安装带 extras 的版本:

pip install "octx[vectors]"

从源码安装(开发模式):

git clone <repository-url> open-context
cd open-context
pip install -e ".[dev]"

从 Markdown 目录创建 Package,然后打开并校验:

from octx import create_octx, open_octx, validate_octx

result = create_octx(
    "./.octx-workspace",
    source="./knowledge",
    name="Product Guide",
    output="./product-guide.octx",
)

with open_octx(result.output) as package:
    for document in package.iter_documents():
        print(document.path, document.metadata["title"])

report = validate_octx(result.output)
assert report.valid

source 不会被修改。持续使用同一个 workspace,可以保留 Asset、Document 和 Release 的稳定身份。向量读取需要安装 octx[vectors]。完整接口见 api/overview.md

展开的外部 Package 未修改时可以无损重新封装;修改或增强后,使用 create_octx(..., derive=True) 创建带 asset.derived_from 的新 Asset,避免冒充原发布者的后续版本。

CLI 快速开始

octx create ./.octx-workspace --from ./knowledge --name "Product Guide" -o ./product-guide.octx
octx inspect ./product-guide.octx
octx validate ./product-guide.octx
octx unpack ./product-guide.octx ./product-guide-expanded

inspect 只读取摘要,不代替完整校验。validate 有效时退出 0,无效时退出 1;所有命令都支持 --json

官网与文档站

官网域名是 opencontext.wiki。独立网站源码位于 site/,直接发布本目录中的完整规范、Python API、Schema 和词汇表,不依赖 SAG 项目的应用代码。

v0.1 要点

  • 发布文件扩展名是 .octx,外层使用 ZIP / ZIP64。
  • 每个 Package 至少包含一篇 OKF Concept Markdown。
  • OCTX 的 knowledge/ 是符合 OKF v0.1 的知识层;完整 OCTX Package 还要求 manifest、资产身份、Release、摘要和可选派生数据。普通 OKF Bundle 不是 OCTX Package。
  • OCTX Package 可以只有 Markdown,不要求预先生成 chunks、events、entities 或 vectors。
  • sag-structured/0.1 是单一显式 Capability,整体包含 chunks、events、entities 和关系,不能根据文件存在情况自动推断。
  • .octx 是不可变完整快照,不是数据库备份、增量包或同步协议。
  • OCTX 不定义搜索 API、召回算法、Agent 协议或向量数据库。

参考实现边界

独立 octx 包提供:

  • create_octx()
  • open_octx()
  • validate_octx()
  • unpack_octx()
  • octx create / inspect / validate / unpack

zleap-sag 依赖并重新导出这些入口,同时增加:

  • import_octx()
  • export_octx()

其他知识系统可以直接使用 octx 并实现自己的适配层。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

octx-0.1.6.tar.gz (179.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

octx-0.1.6-py3-none-any.whl (82.8 kB view details)

Uploaded Python 3

File details

Details for the file octx-0.1.6.tar.gz.

File metadata

  • Download URL: octx-0.1.6.tar.gz
  • Upload date:
  • Size: 179.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.12

File hashes

Hashes for octx-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ce71113859795c92d0f0936f8a473dc666a1ba79fa769b6afc3a582cf09c41a0
MD5 9327b39080735763cf8ace6120c9e5cb
BLAKE2b-256 f099bc1e62ddd5e0c528b8d1981ba3279a2edae4fc2d0560df83f5321ed9ae9d

See more details on using hashes here.

File details

Details for the file octx-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: octx-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 82.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.12

File hashes

Hashes for octx-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 21f5f65ceed84b0a421969f21406244402caa6b7d03ee4583ed1e6996ba56a7e
MD5 25071efe5c21c5e31872a0f0dcbffa76
BLAKE2b-256 5bcc58c51a31703e611ed5a636e8f315a810d10da9b17ccaee5cd5f191365616

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page