@zabaca/lattice 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +82 -222
  2. package/dist/cli.js +11 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,109 +1,73 @@
1
1
  # @zabaca/lattice
2
2
 
3
- **Human-initiated, AI-powered knowledge graph for markdown documentation**
3
+ **Build a knowledge base with Claude Code — using your existing subscription**
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@zabaca/lattice.svg)](https://www.npmjs.com/package/@zabaca/lattice)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
- [![Node.js](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg)](https://nodejs.org/)
8
7
 
9
- ---
10
-
11
- ## Features
12
-
13
- - **Knowledge Graph Sync** - Automatically sync entities and relationships from markdown frontmatter to a graph database
14
- - **Semantic Search** - AI-powered search using Voyage AI embeddings for intelligent document discovery
15
- - **Entity Extraction** - Define entities (concepts, technologies, patterns) directly in your documentation
16
- - **Relationship Mapping** - Model connections between entities with typed relationships (USES, IMPLEMENTS, DEPENDS_ON)
17
- - **FalkorDB Backend** - High-performance graph database built on Redis for fast queries
18
- - **Incremental Sync** - Smart change detection syncs only modified documents
19
- - **CLI Interface** - Simple commands for sync, search, validation, and migration
20
-
21
- ---
22
-
23
- ## Quick Start
24
-
25
- ### 1. Install Lattice
26
-
27
- ```bash
28
- npm install -g @zabaca/lattice
29
- ```
8
+ Lattice turns your markdown documentation into a searchable knowledge graph. Unlike other GraphRAG tools that require separate LLM APIs, **Lattice uses Claude Code for entity extraction** — so you're already paying for it.
30
9
 
31
- Or with bun:
10
+ ## The Workflow
32
11
 
33
12
  ```bash
34
- bun add -g @zabaca/lattice
13
+ /research "knowledge graphs" # Find existing docs or create new research
14
+ /graph-sync # Extract entities & sync (automatic)
15
+ lattice search "your query" # Semantic search your knowledge base
35
16
  ```
36
17
 
37
- ### 2. Start FalkorDB
18
+ That's it. Two commands to build a knowledge base.
38
19
 
39
- Using Docker Compose:
40
-
41
- ```bash
42
- # Create docker-compose.yaml (see Infrastructure section)
43
- docker-compose up -d
44
- ```
45
-
46
- Or pull and run directly:
47
-
48
- ```bash
49
- docker run -d -p 6379:6379 falkordb/falkordb:latest
50
- ```
20
+ ---
51
21
 
52
- ### 3. Configure Environment
22
+ ## Why Lattice?
53
23
 
54
- Create a `.env` file in your project root:
24
+ | Feature | Lattice | Other GraphRAG Tools |
25
+ |---------|---------|---------------------|
26
+ | **LLM for extraction** | Your Claude Code subscription | Separate API key + costs |
27
+ | **Setup time** | 5 minutes | 30+ minutes |
28
+ | **Containers** | 1 (FalkorDB) | 2-3 (DB + vector + graph) |
29
+ | **API keys needed** | 1 (Voyage AI for embeddings) | 2-3 (LLM + embedding + rerank) |
30
+ | **Workflow** | `/research` → `/graph-sync` | Custom scripts |
55
31
 
56
- ```bash
57
- # FalkorDB Connection
58
- FALKORDB_HOST=localhost
59
- FALKORDB_PORT=6379
60
- FALKORDB_GRAPH_NAME=lattice
32
+ ---
61
33
 
62
- # Embedding Provider (Voyage AI)
63
- VOYAGE_API_KEY=your-voyage-api-key-here
64
- VOYAGE_MODEL=voyage-3
34
+ ## Quick Start (5 Minutes)
65
35
 
66
- # Logging
67
- LOG_LEVEL=info
68
- ```
36
+ ### What You Need
69
37
 
70
- ### 4. Initialize Claude Code Integration
38
+ - **Claude Code** (you probably already have it)
39
+ - **Docker** (for FalkorDB)
40
+ - **Voyage AI API key** ([get one here](https://www.voyageai.com/) - embeddings only, ~$0.01/1M tokens)
71
41
 
72
- Install Lattice slash commands for Claude Code:
42
+ ### 1. Install & Start
73
43
 
74
44
  ```bash
75
- lattice init # For this project only
76
- # or
77
- lattice init --global # For all projects (~/.claude/commands/)
45
+ bun add -g @zabaca/lattice # Install CLI
46
+ docker run -d -p 6379:6379 falkordb/falkordb # Start database
47
+ export VOYAGE_API_KEY=your-key-here # Set API key
48
+ lattice init --global # Install Claude Code commands
78
49
  ```
79
50
 
80
- ### 5. Launch Claude Code
51
+ ### 2. Start Researching
81
52
 
82
53
  ```bash
83
- claude
54
+ claude # Launch Claude Code
55
+ /research "your topic" # Find or create documentation
56
+ /graph-sync # Build knowledge graph (automatic)
57
+ lattice search "your query" # Semantic search
84
58
  ```
85
59
 
86
- ### 6. Research a Topic
60
+ ### That's It!
87
61
 
88
- Use the `/research` command to search existing knowledge or create new documentation:
89
-
90
- ```bash
91
- /research "knowledge graphs"
92
- ```
93
-
94
- This will:
62
+ The `/research` command will:
95
63
  - Search your existing docs for related content
96
- - Present findings and ask if you need new research
97
- - Create organized documentation if requested
98
-
99
- ### 7. Sync & Search
100
-
101
- After creating or updating documents, sync to the graph and search:
64
+ - Ask if you need new research
65
+ - Create organized documentation with AI assistance
102
66
 
103
- ```bash
104
- /graph-sync # Extract entities and sync
105
- lattice search "your query" # Semantic search
106
- ```
67
+ The `/graph-sync` command will:
68
+ - Detect all new/changed documents
69
+ - Extract entities using Claude Code (your subscription)
70
+ - Sync to FalkorDB for semantic search
107
71
 
108
72
  ---
109
73
 
@@ -148,7 +112,12 @@ If no existing docs match, Claude will:
148
112
 
149
113
  ---
150
114
 
151
- ## CLI Commands
115
+ ## CLI Reference
116
+
117
+ The Lattice CLI runs behind the scenes. You typically won't use it directly — the Claude Code slash commands handle everything.
118
+
119
+ <details>
120
+ <summary><b>CLI Commands (Advanced)</b></summary>
152
121
 
153
122
  ### `lattice init`
154
123
 
@@ -167,18 +136,14 @@ Synchronize documents to the knowledge graph.
167
136
  lattice sync [paths...] # Sync specified paths or current directory
168
137
  lattice sync --force # Force re-sync (rebuilds entire graph)
169
138
  lattice sync --dry-run # Preview changes without applying
170
- lattice sync --verbose # Show detailed output
171
- lattice sync --watch # Watch for changes and auto-sync
172
- lattice sync --no-embeddings # Skip embedding generation
173
139
  ```
174
140
 
175
141
  ### `lattice status`
176
142
 
177
- Show the current sync status and pending changes.
143
+ Show documents that need syncing.
178
144
 
179
145
  ```bash
180
- lattice status # Show documents that need syncing
181
- lattice status --verbose # Include detailed change information
146
+ lattice status # Show new/changed documents
182
147
  ```
183
148
 
184
149
  ### `lattice search`
@@ -186,17 +151,7 @@ lattice status --verbose # Include detailed change information
186
151
  Semantic search across the knowledge graph.
187
152
 
188
153
  ```bash
189
- lattice search "query" # Search all entity types
190
- lattice search --label Technology "query" # Filter by entity label
191
- lattice search --limit 10 "query" # Limit results (default: 20)
192
- ```
193
-
194
- ### `lattice stats`
195
-
196
- Display graph statistics.
197
-
198
- ```bash
199
- lattice stats # Show node/edge counts and graph metrics
154
+ lattice search "query" # Search all entity types
200
155
  ```
201
156
 
202
157
  ### `lattice validate`
@@ -214,9 +169,10 @@ Display the derived ontology from your documents.
214
169
 
215
170
  ```bash
216
171
  lattice ontology # Show entity types and relationship types
217
- lattice ontology --format json # Output as JSON
218
172
  ```
219
173
 
174
+ </details>
175
+
220
176
  ---
221
177
 
222
178
  ## Configuration
@@ -225,75 +181,43 @@ lattice ontology --format json # Output as JSON
225
181
 
226
182
  | Variable | Description | Default |
227
183
  |----------|-------------|---------|
184
+ | `VOYAGE_API_KEY` | Voyage AI API key for embeddings | *required* |
228
185
  | `FALKORDB_HOST` | FalkorDB server hostname | `localhost` |
229
186
  | `FALKORDB_PORT` | FalkorDB server port | `6379` |
230
- | `FALKORDB_GRAPH_NAME` | Name of the graph database | `lattice` |
231
- | `VOYAGE_API_KEY` | Voyage AI API key for embeddings | *required* |
232
- | `VOYAGE_MODEL` | Voyage AI model to use | `voyage-3` |
233
- | `LOG_LEVEL` | Logging verbosity (debug, info, warn, error) | `info` |
234
187
 
235
- ### Frontmatter Schema
188
+ <details>
189
+ <summary><b>How It Works (Technical Details)</b></summary>
236
190
 
237
- Lattice extracts knowledge from YAML frontmatter in your markdown files:
191
+ ### Entity Extraction
192
+
193
+ When you run `/graph-sync`, Claude Code extracts entities from your documents and writes them to YAML frontmatter. The Lattice CLI then syncs this to FalkorDB.
238
194
 
239
195
  ```yaml
240
196
  ---
241
- title: Document Title
242
- description: Brief description of the document
243
- created: 2024-01-15
244
- updated: 2024-01-20
245
-
246
197
  entities:
247
198
  - name: React
248
199
  type: technology
249
200
  description: JavaScript library for building user interfaces
250
- - name: Component Architecture
251
- type: pattern
252
- description: Modular UI building blocks
253
201
 
254
202
  relationships:
255
203
  - source: React
256
204
  target: Component Architecture
257
- type: IMPLEMENTS
258
- - source: React
259
- target: Virtual DOM
260
- type: USES
205
+ relation: REFERENCES
261
206
  ---
262
-
263
- # Document content here...
264
207
  ```
265
208
 
266
- ### Entity Types
267
-
268
- Common entity types (you can define your own):
269
-
270
- - `concept` - Abstract ideas and principles
271
- - `technology` - Tools, frameworks, and libraries
272
- - `pattern` - Design patterns and architectural approaches
273
- - `service` - External services and APIs
274
- - `component` - System components and modules
275
- - `person` - People and contributors
276
- - `organization` - Companies and teams
209
+ You don't need to write this manually — Claude Code handles it automatically.
277
210
 
278
- ### Relationship Types
279
-
280
- Common relationship types:
281
-
282
- - `USES` - Entity A uses Entity B
283
- - `IMPLEMENTS` - Entity A implements Entity B
284
- - `DEPENDS_ON` - Entity A depends on Entity B
285
- - `EXTENDS` - Entity A extends Entity B
286
- - `CONTAINS` - Entity A contains Entity B
287
- - `RELATED_TO` - General relationship
288
- - `SUPERSEDES` - Entity A replaces Entity B
211
+ </details>
289
212
 
290
213
  ---
291
214
 
292
215
  ## Infrastructure
293
216
 
294
- ### Docker Compose
217
+ <details>
218
+ <summary><b>Docker Compose (Alternative Setup)</b></summary>
295
219
 
296
- Create `docker-compose.yaml`:
220
+ If you prefer Docker Compose over a single `docker run` command:
297
221
 
298
222
  ```yaml
299
223
  version: '3.8'
@@ -301,44 +225,31 @@ version: '3.8'
301
225
  services:
302
226
  falkordb:
303
227
  image: falkordb/falkordb:latest
304
- container_name: lattice-falkordb
305
228
  ports:
306
229
  - "6379:6379"
307
230
  volumes:
308
231
  - falkordb-data:/data
309
- environment:
310
- - FALKORDB_ARGS=--requirepass ""
311
232
  restart: unless-stopped
312
- healthcheck:
313
- test: ["CMD", "redis-cli", "ping"]
314
- interval: 10s
315
- timeout: 5s
316
- retries: 3
317
233
 
318
234
  volumes:
319
235
  falkordb-data:
320
- driver: local
321
236
  ```
322
237
 
323
- Start the database:
324
-
325
238
  ```bash
326
239
  docker-compose up -d
327
240
  ```
328
241
 
329
- ### Kubernetes (k3s)
242
+ </details>
243
+
244
+ <details>
245
+ <summary><b>Kubernetes (k3s)</b></summary>
330
246
 
331
247
  For production deployments, use the provided k3s manifests:
332
248
 
333
249
  ```bash
334
- # Create namespace
335
250
  kubectl apply -f infra/k3s/namespace.yaml
336
-
337
- # Deploy storage
338
251
  kubectl apply -f infra/k3s/pv.yaml
339
252
  kubectl apply -f infra/k3s/pvc.yaml
340
-
341
- # Deploy FalkorDB
342
253
  kubectl apply -f infra/k3s/deployment.yaml
343
254
  kubectl apply -f infra/k3s/service.yaml
344
255
 
@@ -349,9 +260,14 @@ kubectl apply -f infra/k3s/nodeport-service.yaml
349
260
  kubectl apply -f infra/k3s/ingress.yaml
350
261
  ```
351
262
 
263
+ </details>
264
+
352
265
  ---
353
266
 
354
- ## Development
267
+ ## Contributing
268
+
269
+ <details>
270
+ <summary><b>Development Setup</b></summary>
355
271
 
356
272
  ### Prerequisites
357
273
 
@@ -362,64 +278,25 @@ kubectl apply -f infra/k3s/ingress.yaml
362
278
  ### Setup
363
279
 
364
280
  ```bash
365
- # Clone the repository
366
281
  git clone https://github.com/Zabaca/lattice.git
367
282
  cd lattice
368
-
369
- # Install dependencies
370
283
  bun install
371
-
372
- # Copy environment configuration
373
284
  cp .env.example .env
374
- # Edit .env with your settings
375
-
376
- # Start FalkorDB
377
285
  docker-compose -f infra/docker-compose.yaml up -d
378
286
  ```
379
287
 
380
288
  ### Running Locally
381
289
 
382
290
  ```bash
383
- # Development mode
384
- bun run dev
385
-
386
- # Run CLI commands during development
387
- bun run lattice sync
388
- bun run lattice status
389
-
390
- # Run tests
391
- bun test
392
-
393
- # Build for production
394
- bun run build
395
- ```
396
-
397
- ### Project Structure
398
-
291
+ bun run dev # Development mode
292
+ bun test # Run tests
293
+ bun run build # Build for production
399
294
  ```
400
- lattice/
401
- ├── src/
402
- │ ├── commands/ # CLI command implementations
403
- │ ├── embedding/ # Voyage AI embedding service
404
- │ ├── graph/ # FalkorDB graph operations
405
- │ ├── query/ # Query builders and parsers
406
- │ ├── sync/ # Document sync logic
407
- │ ├── utils/ # Shared utilities
408
- │ ├── app.module.ts # NestJS application module
409
- │ ├── cli.ts # CLI entry point
410
- │ └── main.ts # Main application entry
411
- ├── infra/
412
- │ ├── docker-compose.yaml
413
- │ └── k3s/ # Kubernetes manifests
414
- ├── examples/ # Usage examples
415
- └── dist/ # Build output
416
- ```
417
-
418
- ---
419
295
 
420
- ## API Usage
296
+ </details>
421
297
 
422
- Lattice can also be used programmatically:
298
+ <details>
299
+ <summary><b>Programmatic API</b></summary>
423
300
 
424
301
  ```typescript
425
302
  import { NestFactory } from '@nestjs/core';
@@ -427,16 +304,11 @@ import { AppModule } from '@zabaca/lattice';
427
304
 
428
305
  async function main() {
429
306
  const app = await NestFactory.createApplicationContext(AppModule);
430
-
431
- // Get services
432
307
  const syncService = app.get(SyncService);
433
- const graphService = app.get(GraphService);
434
308
 
435
- // Sync documents
436
309
  const result = await syncService.sync({
437
310
  paths: ['./docs'],
438
- force: false,
439
- dryRun: false
311
+ force: false
440
312
  });
441
313
 
442
314
  console.log(`Synced ${result.added} new documents`);
@@ -445,18 +317,10 @@ async function main() {
445
317
  }
446
318
  ```
447
319
 
448
- ---
449
-
450
- ## Contributing
320
+ </details>
451
321
 
452
322
  Contributions are welcome! Please feel free to submit a Pull Request.
453
323
 
454
- 1. Fork the repository
455
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
456
- 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
457
- 4. Push to the branch (`git push origin feature/amazing-feature`)
458
- 5. Open a Pull Request
459
-
460
324
  ---
461
325
 
462
326
  ## License
@@ -465,8 +329,4 @@ MIT License - see [LICENSE](LICENSE) for details.
465
329
 
466
330
  ---
467
331
 
468
- ## Acknowledgments
469
-
470
- - [FalkorDB](https://www.falkordb.com/) - High-performance graph database
471
- - [Voyage AI](https://www.voyageai.com/) - State-of-the-art embeddings
472
- - [NestJS](https://nestjs.com/) - Progressive Node.js framework
332
+ Built with [FalkorDB](https://www.falkordb.com/), [Voyage AI](https://www.voyageai.com/), and [Claude Code](https://claude.ai/code)
package/dist/cli.js CHANGED
@@ -257,7 +257,7 @@ class GraphService {
257
257
  this.logger.log(`Created vector index on ${label}.${property} with ${dimensions} dimensions`);
258
258
  } catch (error) {
259
259
  const errorMessage = error instanceof Error ? error.message : String(error);
260
- if (!errorMessage.includes("already exists")) {
260
+ if (!errorMessage.includes("already indexed")) {
261
261
  this.logger.error(`Failed to create vector index: ${errorMessage}`);
262
262
  throw error;
263
263
  }
@@ -339,10 +339,10 @@ class GraphService {
339
339
  return String(value);
340
340
  }
341
341
  parseStats(result) {
342
- if (!Array.isArray(result) || result.length < 2) {
342
+ if (!Array.isArray(result) || result.length < 3) {
343
343
  return;
344
344
  }
345
- const statsStr = result[1];
345
+ const statsStr = result[2];
346
346
  if (!statsStr || typeof statsStr !== "string") {
347
347
  return;
348
348
  }
@@ -2473,9 +2473,14 @@ Note: Semantic search requires embeddings to be generated first.`);
2473
2473
  const outgoing = [];
2474
2474
  results.forEach((row) => {
2475
2475
  const [source, rel, target] = row;
2476
- const sourceName = source.properties?.name || "unknown";
2477
- const targetName = target.properties?.name || "unknown";
2478
- const relType = rel.type || "UNKNOWN";
2476
+ const sourceObj = Object.fromEntries(source);
2477
+ const targetObj = Object.fromEntries(target);
2478
+ const relObj = Object.fromEntries(rel);
2479
+ const sourceProps = Object.fromEntries(sourceObj.properties || []);
2480
+ const targetProps = Object.fromEntries(targetObj.properties || []);
2481
+ const sourceName = sourceProps.name || "unknown";
2482
+ const targetName = targetProps.name || "unknown";
2483
+ const relType = relObj.type || "UNKNOWN";
2479
2484
  if (sourceName === name) {
2480
2485
  outgoing.push(` -[${relType}]-> ${targetName}`);
2481
2486
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zabaca/lattice",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Human-initiated, AI-powered knowledge graph for markdown documentation",
5
5
  "type": "module",
6
6
  "bin": {