Skip to content

Commit f9ed4f3

Browse files
committed
docs(CLAUDE.md): clarify project positioning and architecture overview
Refactor the documentation to better explain Vectorless as having two distinct layers: the Rust standard (IR + navigation primitives) and the Python reference implementation. Update project structure description with clearer crate categorization and dependency layers. Revise development workflow guidelines to emphasize the contract between the standard and reference implementation.
1 parent 2451fea commit f9ed4f3

1 file changed

Lines changed: 75 additions & 69 deletions

File tree

CLAUDE.md

Lines changed: 75 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,55 @@
11
# CLAUDE.md
22

3-
Vectorless is a Document Understanding Engine for AI. Compile pipeline is written in Rust; the reasoning/retrieval (ask) layer is written in Python on top of LLM tool-use. See `README.md` for the project's public positioning.
3+
Vectorless is a Document Understanding Engine for AI. See `README.md` for the project's public positioning.
44

5-
## Project Structure
5+
## Positioning: a standard + a reference implementation
66

7-
Cargo workspace with **13 Rust crates** (compile pipeline + bindings) plus a **Python package** (`vectorless/`) that owns the ask/reasoning loop.
7+
Vectorless is split into two layers that are **independently consumable**:
88

9-
### Rust crates (`crates/`)
9+
1. **The Rust side defines two standards.**
10+
- **The IR** (`vectorless-document::Document`) — a single, versioned, serializable artifact that fully represents an understood document. Produced by the compile pipeline; can be persisted, transmitted, and re-loaded.
11+
- **The navigation primitives** (`vectorless-primitives::DocumentNavigator`) — a fixed set of shell-style operations (`ls`, `cd`, `cat`, `grep`, `find`, `head`, `wc`, `pwd`, `back`, plus inspection and reasoning-index queries) that any agent uses to read an IR. Exposed to Python via PyO3.
1012

11-
```
12-
crates/
13-
├── vectorless-error/ # Error types (Result, Error enum)
14-
├── vectorless-document/ # Document types (Document, Tree, NavigationIndex)
15-
├── vectorless-config/ # Configuration hub (aggregates all config types)
16-
├── vectorless-utils/ # Utilities (fingerprinting, token counting, keyword extraction)
17-
├── vectorless-graph/ # Cross-document relationship graph
18-
├── vectorless-events/ # Event system for progress monitoring
19-
├── vectorless-metrics/ # Metrics collection and reporting
20-
├── vectorless-llm/ # LLM client (pool, memo/cache, throttle)
21-
├── vectorless-storage/ # Persistence (Workspace, LRU cache, file backend)
22-
├── vectorless-compiler/ # Compile pipeline (frontend → transform → analysis → backend)
23-
├── vectorless-primitives/ # Document navigation primitives (DocumentNavigator)
24-
├── vectorless-engine/ # Facade (Engine, EngineBuilder) — re-exports public API
25-
└── vectorless-py/ # PyO3 bindings (compiled into Python native module)
26-
```
13+
These two together are **the standard**. Anything that produces a valid `Document` and consumes it via `DocumentNavigator` is a conforming participant.
2714

28-
### Python package (`vectorless/`)
15+
2. **The Python side is one reference agent implementation.** `vectorless/ask/` is a multi-agent system (Orchestrator + Workers + reasoning + verify) that ships in the box. It is the default `engine.ask()` — but it is not load-bearing for the standard. Developers can:
16+
- Replace `ask/` entirely with their own Python agent built on the same `Document` / `DocumentNavigator` primitives.
17+
- Skip Python and consume the IR + primitives directly from Rust.
18+
- Produce IRs from a non-Rust source (the IR is serializable JSON) and feed them into any compatible navigator/agent.
19+
20+
The reason this matters: the value of Vectorless is the **IR + primitives contract**, not the bundled reasoning loop. The reference implementation is a courtesy, not a lock-in.
21+
22+
## Project Structure
2923

3024
```
31-
vectorless/
32-
├── ask/ # Reasoning loop (Orchestrator + Workers + supervisor)
33-
│ ├── orchestrator.py # Top-level coordinator
34-
│ ├── worker/ # Navigation Worker (ls/cd/cat/grep/find/head/wc/chain)
35-
│ ├── dispatcher.py # Worker dispatch
36-
│ ├── plan.py # Replanning
37-
│ ├── understand.py # Query understanding → QueryPlan
38-
│ ├── reasoning/ # Reasoning chain analyzer
39-
│ ├── evaluate.py # Evidence sufficiency evaluation
40-
│ ├── verify/ # Answer verifier
41-
│ ├── blackboard.py # Shared evidence state
42-
│ └── prompts.py
43-
├── rerank/ # Dedup + quality scoring + synthesis
44-
├── _internal/ # Wrappers around the PyO3 native module
45-
├── engine.py # User-facing Engine class
46-
└── cli/ # CLI entrypoint
25+
crates/ Rust — the standard
26+
├── vectorless-error/ Result / Error
27+
├── vectorless-document/ ★ IR types: Document, DocumentTree, NavigationIndex, ReasoningIndex,
28+
│ QueryRoutingTable, ChainIndex, ContentOverlapMap, EvidenceScoreMap
29+
├── vectorless-primitives/ ★ DocumentNavigator (the navigation API)
30+
├── vectorless-config/ Configuration hub
31+
├── vectorless-utils/ Fingerprinting, token counting, keyword extraction
32+
├── vectorless-graph/ Cross-document relationship graph
33+
├── vectorless-events/ Progress event bus
34+
├── vectorless-metrics/ Metrics collection
35+
├── vectorless-llm/ LLM client (pool, throttle, retry)
36+
├── vectorless-storage/ Workspace persistence (file backend, LRU cache)
37+
├── vectorless-compiler/ Compile pipeline (frontend → transform → analysis → backend)
38+
├── vectorless-engine/ Facade: Engine, EngineBuilder, compile() / forget() / load_document()
39+
└── vectorless-py/ PyO3 bindings → produces the `_vectorless` native module
40+
41+
vectorless/ Python — the reference multi-agent implementation
42+
├── ask/ Orchestrator + Worker + reasoning + verify (the default agent)
43+
├── rerank/ Dedup + quality scoring + synthesis
44+
├── _internal/ Wrappers around the PyO3 native module
45+
├── engine.py User-facing Engine (delegates compile to Rust, ask to ask/)
46+
└── cli/ CLI entrypoint
47+
48+
examples/ Python examples
49+
docs/ Docusaurus documentation site
4750
```
4851

49-
- `examples/` — Python examples (primary, for Python ecosystem)
50-
- `docs/` — Docusaurus documentation site
52+
The two crates marked ★ are the **standard surface**. Everything else in `crates/` is implementation detail that produces and serves that standard.
5153

5254
### Dependency Layers (Rust)
5355

@@ -58,47 +60,51 @@ Layer 2: config · metrics (depends on Layer 0–1
5860
Layer 3: llm · storage · primitives (depends on Layer 0–2)
5961
Layer 4: compiler (depends on Layer 0–3)
6062
Layer 5: engine (depends on Layer 0–4)
61-
Layer 6: vectorless-py (PyO3 bindings) (depends on engine + primitives)
63+
Layer 6: vectorless-py (PyO3 bindings) (engine + document + primitives)
6264
```
6365

64-
### Compile Pipeline
66+
`vectorless-document` and `vectorless-primitives` have no dependency on `compiler`, `llm`, `storage`, or `engine` — by design, so the standard can be consumed without dragging in the pipeline.
67+
68+
### Compile Pipeline (the IR producer)
6569

6670
The compiler runs documents through four stage groups (`crates/vectorless-compiler/src/passes/`):
6771

6872
```
69-
frontend (parse, build) raw bytes → DocumentTree
70-
transform (split, enrich) chunking + section enrichment
71-
analysis (validate, enhance) structure checks + augmentation
73+
frontend (parse, build) raw bytes → DocumentTree
74+
transform (split, enrich) chunking + section enrichment
75+
analysis (validate, enhance) structure checks + augmentation
7276
backend (route, concept, navigation,
7377
chain, overlap, reasoning,
74-
score, optimize, verify) retrieval-acceleration artifacts
78+
score, optimize, verify) retrieval-acceleration artifacts
7579
```
7680

81+
Every backend pass attaches an optional acceleration field to the `Document`. The IR is valid without any of them (an agent can navigate using only `tree` + `nav_index`); the acceleration fields exist so well-equipped agents can short-circuit reasoning.
82+
7783
### Compilation Isolation
7884

7985
改一个模块只重编译该 crate + 上游 facade:
86+
8087
-`llm` → llm, compiler, engine, py 重编译;storage/graph 不动
8188
-`compiler` → compiler, engine, py 重编译;llm/storage 不动
82-
-`document` → 全部重编译(核心类型,预期行为)
83-
- 改 Python `ask/``rerank/` → 不触发 Rust 重编译
89+
-`document` `primitives` → 全部重编译(标准变更,预期行为)
90+
- 改 Python `ask/` / `rerank/` → 不触发 Rust 重编译
8491

85-
### Ask Call Flow
92+
### How third parties consume the standard
8693

87-
```
88-
engine.ask() [Python]
89-
→ ask/understand() → QueryPlan (intent + concepts + strategy, LLM-driven)
90-
→ ask/orchestrator
91-
├── analyze(QueryPlan) → dispatch plan
92-
└── supervisor loop:
93-
dispatch Workers (Rust DocumentNavigator via PyO3)
94-
→ execute nav commands (ls/cd/cat/grep/find/head/wc/chain)
95-
→ evaluate(blackboard) → sufficiency check
96-
→ if insufficient: plan.replan() → loop
97-
→ rerank/ (dedup → quality score → synthesize)
98-
→ verify/ → final answer check
94+
Anyone building a custom agent works against two types and two crates only:
95+
96+
```rust
97+
use vectorless_document::Document; // The IR
98+
use vectorless_primitives::DocumentNavigator; // The primitive API
99+
100+
let doc: Document = load_ir_from_disk()?; // produced by our compiler, or yours
101+
let mut nav = DocumentNavigator::new(doc);
102+
let children = nav.ls().await;
103+
nav.cd("n3").await?;
104+
let body = nav.cat(None).await?;
99105
```
100106

101-
The Rust side exposes `DocumentNavigator` (`vectorless-primitives`) and compiled artifacts; the Python orchestrator drives the LLM reasoning loop and calls back into Rust for fast document operations.
107+
The Python reference agent (`vectorless/ask/`) is just one consumer of this same surface.
102108

103109
## Build Commands
104110

@@ -107,7 +113,7 @@ The Rust side exposes `DocumentNavigator` (`vectorless-primitives`) and compiled
107113
cargo build # Build all crates
108114
cargo test # Run workspace tests
109115
cargo clippy # Lint
110-
cargo fmt # Format code
116+
cargo fmt # Format
111117

112118
# Build a single crate (fast — only that crate + dependents)
113119
cargo build -p vectorless-compiler
@@ -199,10 +205,10 @@ When uncertain whether an operation is safe, **default to asking user confirmati
199205

200206
## Common Development Workflow
201207

202-
1. **Adding compile-pipeline features**: implement under `crates/vectorless-compiler/src/passes/` (frontend/transform/analysis/backend), add tests in the same module.
203-
2. **Adding reasoning/ask features**: implement under `vectorless/ask/` (Python), add prompts in `prompts.py`.
204-
3. **Fixing bugs**: write a failing test first, then fix.
205-
4. **Adding crates**: new modules get their own crate under `crates/`, registered in workspace `Cargo.toml`.
206-
5. **Python bindings**: update `crates/vectorless-py/src/lib.rs` (PyO3) when Rust APIs cross the FFI boundary; corresponding wrappers go in `vectorless/_internal/`.
207-
6. **Python SDK surface**: update `vectorless/engine.py` and related modules when the public API changes.
208-
7. **Committing**: use Conventional Commits — `feat(compiler): ...`, `fix(ask): ...`, `refactor(engine): ...`.
208+
1. **Touching the standard (`document` or `primitives`):** this is a public-contract change. Bump `CURRENT_SCHEMA_VERSION` if the IR's serialized shape changes; document the new field; add tests.
209+
2. **Adding a compile-pipeline pass:** implement under `crates/vectorless-compiler/src/passes/` (frontend/transform/analysis/backend), wire into the pipeline, attach output to `Document` as an `Option<...>` so old IRs still load.
210+
3. **Adding/modifying reasoning behavior:** implement under `vectorless/ask/` (Python). This is reference-implementation work, not standard work — it should not require Rust changes.
211+
4. **Fixing bugs:** write a failing test first, then fix.
212+
5. **Adding crates:** new modules get their own crate under `crates/`, registered in workspace `Cargo.toml`.
213+
6. **PyO3 bindings:** update `crates/vectorless-py/src/lib.rs` when Rust types cross the FFI boundary; corresponding Python wrappers in `vectorless/_internal/`.
214+
7. **Committing:** Conventional Commits — `feat(compiler): ...`, `fix(ask): ...`, `refactor(primitives): ...`.

0 commit comments

Comments
 (0)