-
Notifications
You must be signed in to change notification settings - Fork 4
Storage and Data Model
Language: English · 简体中文
LWC stores durable knowledge in SQLite and keeps filesystem projections explicitly subordinate to it. This page describes the ownership model, table families, identities, and migration rules behind the public CLI.
Read it before changing schema, backup behavior, source identity, Page replacement, or filesystem layout.
project/
`-- .lwc/
|-- wiki.db canonical project Wiki
|-- config.json project deployment configuration
|-- wiki/ generated Markdown
|-- work/ live durable Work
|-- checkpoints/ named SQLite checkpoints
|-- changesets/
| |-- <name>.db sparse draft database
| `-- draft-<name>/ draft Work and graph sidecar
|-- graph-grafeo/ selected derived document graph
|-- graph-surrealdb/
`-- codegraph/ project-local code index
user home/
`-- .lwc/
|-- wiki.db global Wiki
|-- config.json global defaults
|-- runtime/codegraph/ pinned runtime cache by version and target
`-- agent-installs/ integration ownership receipts
The exact graph sidecar present depends on configuration. None of these directories is a supported manual editing surface.
| Family | Main records | Invariant |
|---|---|---|
| Identity and governance | meta |
Store ID is stable; revision changes with canonical state; Purpose and Schema are non-empty |
| Evidence |
sources, source_path_revisions
|
Source content is immutable and SHA-256 deduplicated; path observations are revisioned |
| Maintained knowledge |
pages, page_sources, page_provenance, links
|
Page replacement updates body, grounding, provenance, and links together |
| Ingest | ingest_jobs |
One durable state machine per Source |
| Strong context |
tags, page_tags
|
Membership is explicit and priority ordered |
| Semantic graph | semantic_relations |
Explicit typed relation keeps provenance, reason, and cited Source IDs |
| Retrieval control |
retrieval_weights, retrieval_feedback
|
Audited adjustments never create lexical candidates |
| Search projection |
search_fts, search_spans, span_fts
|
Derived rows correspond to active canonical documents and fingerprints |
| Audit and recovery |
operations, changesets and inverse metadata |
State-changing behavior remains attributable and recoverable |
SQLite foreign keys and CHECK constraints enforce supported status values, provenance classes, weight ranges, tag budgets, and relation ownership where possible. Higher-level invariants that cross projections are enforced in Store transactions and lint.
A Source has two complementary identities:
-
content_hashidentifies immutable UTF-8 bytes globally within one Wiki. -
source_path_revisionsrecords that a tracked path pointed to a Source at revision N.
Adding identical content reuses the Source instead of storing a second copy. A file that changes receives a new Source ID and advances its path head; historical revisions remain frozen.
Removing the current tracked revision untracks the path rather than revealing an older revision as current. Deleting Source evidence is constrained when Pages or history still depend on it.
The Page slug is its stable identity and Wiki filename. A replacement preserves created_at, updates updated_at, and replaces the maintained fields as one logical operation:
- title, kind, summary, and body;
- cited Source set;
- explicit provenance set;
- parsed outgoing
[[wikilinks]]; - document and span search rows;
- operation record and Store revision;
- dirty graph document key when graph projection is enabled.
Callers must read the current Page and preserve still-valid knowledge. Replacement semantics are intentional: omitted citations or provenance do not linger invisibly.
Document FTS rows are contentless projections keyed by document type and identifier. Separate active span records point to exact byte ranges in the current body and carry:
- passage or sentence type;
- parent and ordinal;
- byte start and end;
- content fingerprint;
- segmenter version.
When a document changes, old locators become inactive. span get refuses stale fingerprints instead of guessing a nearby replacement.
Canonical mutations append an operations row with action, target, structured detail, and timestamp. Search and lint remain private reads unless the caller explicitly requests recording.
Store revision is a content fingerprint, not a monotonically increasing integer. Changesets capture base fingerprints for touched entities; checkpoint restore also checks that live revision did not advance between safety snapshot and replacement.
Do not infer chronology from the revision string. Use operation IDs and timestamps for audit order.
LWC uses WAL-mode SQLite with foreign keys enabled and a bounded busy timeout. Mutations use an immediate transaction when they must reserve the write path before reading and changing related rows.
The transaction covers canonical state and SQLite search projections. External graph Work and filesystem materialization happen after canonical commit because they live outside the database transaction.
That split produces an explicit partial-success contract instead of a distributed transaction illusion.
Materialization renders Purpose, Schema, index, Pages, and Source-facing navigation from SQLite. Files are staged and replaced as owned artifacts. Extra or obsolete generated files are removed only through LWC's manifest-aware projection logic.
Edits made directly under .lwc/wiki/ are overwritten or ignored. To change knowledge, use Page, Source, tag, Purpose, or Schema commands.
Sparse changesets store only touched entities, base observations, staged operations, and merge metadata. The live store is attached read-only for overlay queries and lint.
Every draft has a dedicated runtime directory derived from its validated name. Work and graph sidecars are scoped there so draft A cannot query or cancel draft B's Work or see its projected graph nodes.
Commit persists a checksummed inverse payload before applying the live merge. Optional fields serialize compatibly so older inverse patches remain verifiable after upgrades.
Named checkpoints use SQLite's online backup API and are stored as regular .db files under checkpoints/. Restore validates a private candidate before writing live data and creates a pre-restore-* safety checkpoint.
Checkpoint files contain the complete SQLite database, including derived FTS tables, but not external filesystem state. Restore re-materializes Markdown and queues a fresh document-graph projection.
PRAGMA user_version and meta.format_version identify the Store format. The tokenizer identifier is also stored because changing normalization invalidates search projections.
Supported migrations run in explicit ordered steps. Long schema migrations execute as Work through a shadow database and safety checkpoint rather than mutating an old database in place without recovery.
An unknown future version returns unsupported_store_version. LWC never guesses how to downgrade a newer store.
Do not:
- open
wiki.dbin a GUI and edit rows; - copy only
wiki.dbwhile a WAL write may be active; - create fake checkpoint files in the checkpoint directory;
- move a draft database without its validated live binding;
- edit FTS, Work, graph, or materialized files to repair canonical knowledge;
- commit
.lwcruntime state to source control.
Use CLI mutations, lint, checkpoint, changeset recovery, maintenance Work, and graph verify instead.
LWC Wiki
- Home · 首页
- Project overview · 项目简介
- Basic concepts · 基本概念
- Use cases · 应用场景
- Installation and upgrades · 安装与升级
- Quick start · 快速开始
- Persistent memory · 持久记忆体系
- Agent workflow and memory policy · Agent 工作流与主动记忆策略
- Sources and ingestion · 来源与知识整合
- Wiki pages and provenance · Wiki 页面与来源证明
- Search and context · 搜索与上下文载入
- Document knowledge graph · 文档知识图(记忆图网)
- Code graph · 代码图
- Word graph · 词图
- Tags and strong context · 标签与强上下文
- Document conversion · 文档转换
-
MCP server and
lwc_explore· MCP 服务与lwc_explore - Skills, Hooks, and Instructions · Skills、Hooks 与 Instructions
- AgentTarget installation · AgentTarget 安装与集成
- Changesets · Changeset 原子变更
- Work system · Work 任务系统
- Checkpoints and rollback · Checkpoint、恢复与回滚
- Read-only Viewer · 只读可视化界面
- Architecture overview · 总体架构
- Storage and data model · 存储与数据模型
- Retrieval and indexing · 检索与索引设计
- Graph projection and performance · 图投影与性能设计
- MCP, Hooks, and AgentTarget design · MCP、Hook 与 AgentTarget 设计
- Safety and trust boundaries · 安全模型与信任边界
- Maintenance and diagnostics · 维护与诊断
- Troubleshooting and FAQ · 故障排查与常见问题
- Migration and compatibility · 迁移与版本兼容
- Support and issue reporting · 获取帮助与问题反馈
- CLI and configuration reference · CLI 与配置参考
- JSON output and error contract · JSON 输出与错误契约
- Limits and glossary · 系统限制与术语表
- Contributing and development · 贡献与开发指南
- Testing and release process · 测试与发布流程
- Wiki style guide · Wiki 编写规范