Add persistent layer tree for overlay-aware retrieval#7
Open
Add persistent layer tree for overlay-aware retrieval#7
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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