Skip to content

Add persistent layer tree for overlay-aware retrieval#7

Open
eiderman wants to merge 1 commit intomasterfrom
eider/layer-model
Open

Add persistent layer tree for overlay-aware retrieval#7
eiderman wants to merge 1 commit intomasterfrom
eider/layer-model

Conversation

@eiderman
Copy link
Copy Markdown
Contributor

Witchcraft needs overlay-aware indexing for use cases where a large corpus has concurrent branch-scoped views (e.g., a monorepo where feature branches modify a handful of files). The basic document model requires duplicating the entire index per view, which is infeasible at scale. The layer model adds a lightweight structural primitive (inspired by OverlayFS and Clojure's persistent data structures) that lets overlays store only deltas while sharing the embedding store and IVF globally.

Changes
src/layer.rs (new) — LayerStatus enum (Active/Sealed/Compacted), Layer struct, LayerChain for query resolution, LayerError for distinguishable error variants (NotFound, HasChildren, NotActive, NotInChain).
src/db.rs — layer table DDL (parent-pointer tree with status CHECK constraint, parent/status indices). Layer CRUD: create_layer, seal_layer, get_layer, layer_chain (recursive CTE), layer_children, layer_tree, delete_layer (refuses with children), compact_layers (transactional, validates stop_at ancestry, reparents orphaned children).
src/lib.rs — Wires pub mod layer and re-exports types.
docs/layers.md (new) — User-facing documentation: when to use layers vs the basic model vs separate databases, API examples, design rationale.
src/tests.rs — 19 tests covering flat/deep topology chain resolution, seal with error variants, compaction edge cases (sub-chain, full chain, single layer, invalid/self stop_at), reparenting via compaction, clear, metadata round-trip, and error distinguishability.
No changes to the existing document path. No schema version bump (additive CREATE TABLE IF NOT EXISTS).

Test plan
19 layer-specific tests passing
All 36 fast tests pass (existing document-path tests unaffected)
Full test suite including embedding-dependent tests

Introduces the layer model as the first building block for
overlay-aware indexing. The layer table stores a parent-pointer tree
with status lifecycle (active → sealed → compacted). CRUD operations
include chain resolution via recursive CTE, compaction with child
reparenting, and safe deletion (refuses when children exist).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant