@zabaca/lattice 0.1.0

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +398 -0
  3. package/dist/cli.js +2712 -0
  4. package/package.json +61 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Zabaca
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,398 @@
1
+ # @zabaca/lattice
2
+
3
+ **Human-initiated, AI-powered knowledge graph for markdown documentation**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@zabaca/lattice.svg)](https://www.npmjs.com/package/@zabaca/lattice)
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
+
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
+ ```
30
+
31
+ Or with bun:
32
+
33
+ ```bash
34
+ bun add -g @zabaca/lattice
35
+ ```
36
+
37
+ ### 2. Start FalkorDB
38
+
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
+ ```
51
+
52
+ ### 3. Configure Environment
53
+
54
+ Create a `.env` file in your project root:
55
+
56
+ ```bash
57
+ # FalkorDB Connection
58
+ FALKORDB_HOST=localhost
59
+ FALKORDB_PORT=6379
60
+ FALKORDB_GRAPH_NAME=lattice
61
+
62
+ # Embedding Provider (Voyage AI)
63
+ VOYAGE_API_KEY=your-voyage-api-key-here
64
+ VOYAGE_MODEL=voyage-3
65
+
66
+ # Logging
67
+ LOG_LEVEL=info
68
+ ```
69
+
70
+ ### 4. Sync Your Documents
71
+
72
+ ```bash
73
+ # Sync all markdown files with frontmatter
74
+ lattice sync
75
+
76
+ # Sync specific paths
77
+ lattice sync ./docs ./notes
78
+
79
+ # Check what would change without syncing
80
+ lattice sync --dry-run
81
+ ```
82
+
83
+ ---
84
+
85
+ ## CLI Commands
86
+
87
+ ### `lattice sync`
88
+
89
+ Synchronize documents to the knowledge graph.
90
+
91
+ ```bash
92
+ lattice sync [paths...] # Sync specified paths or current directory
93
+ lattice sync --force # Force re-sync (rebuilds entire graph)
94
+ lattice sync --dry-run # Preview changes without applying
95
+ lattice sync --verbose # Show detailed output
96
+ lattice sync --watch # Watch for changes and auto-sync
97
+ lattice sync --no-embeddings # Skip embedding generation
98
+ ```
99
+
100
+ ### `lattice status`
101
+
102
+ Show the current sync status and pending changes.
103
+
104
+ ```bash
105
+ lattice status # Show documents that need syncing
106
+ lattice status --verbose # Include detailed change information
107
+ ```
108
+
109
+ ### `lattice search`
110
+
111
+ Search the knowledge graph.
112
+
113
+ ```bash
114
+ lattice search --semantic "query" # Semantic search using embeddings
115
+ lattice search --keyword "term" # Keyword-based search
116
+ lattice search --type concept # Filter by entity type
117
+ lattice search --limit 10 # Limit results
118
+ ```
119
+
120
+ ### `lattice stats`
121
+
122
+ Display graph statistics.
123
+
124
+ ```bash
125
+ lattice stats # Show node/edge counts and graph metrics
126
+ ```
127
+
128
+ ### `lattice validate`
129
+
130
+ Validate entity references and relationships.
131
+
132
+ ```bash
133
+ lattice validate # Check for broken references
134
+ lattice validate --fix # Attempt to fix validation issues
135
+ ```
136
+
137
+ ### `lattice ontology`
138
+
139
+ Display the derived ontology from your documents.
140
+
141
+ ```bash
142
+ lattice ontology # Show entity types and relationship types
143
+ lattice ontology --format json # Output as JSON
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Configuration
149
+
150
+ ### Environment Variables
151
+
152
+ | Variable | Description | Default |
153
+ |----------|-------------|---------|
154
+ | `FALKORDB_HOST` | FalkorDB server hostname | `localhost` |
155
+ | `FALKORDB_PORT` | FalkorDB server port | `6379` |
156
+ | `FALKORDB_GRAPH_NAME` | Name of the graph database | `lattice` |
157
+ | `VOYAGE_API_KEY` | Voyage AI API key for embeddings | *required* |
158
+ | `VOYAGE_MODEL` | Voyage AI model to use | `voyage-3` |
159
+ | `LOG_LEVEL` | Logging verbosity (debug, info, warn, error) | `info` |
160
+
161
+ ### Frontmatter Schema
162
+
163
+ Lattice extracts knowledge from YAML frontmatter in your markdown files:
164
+
165
+ ```yaml
166
+ ---
167
+ title: Document Title
168
+ description: Brief description of the document
169
+ created: 2024-01-15
170
+ updated: 2024-01-20
171
+
172
+ entities:
173
+ - name: React
174
+ type: technology
175
+ description: JavaScript library for building user interfaces
176
+ - name: Component Architecture
177
+ type: pattern
178
+ description: Modular UI building blocks
179
+
180
+ relationships:
181
+ - source: React
182
+ target: Component Architecture
183
+ type: IMPLEMENTS
184
+ - source: React
185
+ target: Virtual DOM
186
+ type: USES
187
+ ---
188
+
189
+ # Document content here...
190
+ ```
191
+
192
+ ### Entity Types
193
+
194
+ Common entity types (you can define your own):
195
+
196
+ - `concept` - Abstract ideas and principles
197
+ - `technology` - Tools, frameworks, and libraries
198
+ - `pattern` - Design patterns and architectural approaches
199
+ - `service` - External services and APIs
200
+ - `component` - System components and modules
201
+ - `person` - People and contributors
202
+ - `organization` - Companies and teams
203
+
204
+ ### Relationship Types
205
+
206
+ Common relationship types:
207
+
208
+ - `USES` - Entity A uses Entity B
209
+ - `IMPLEMENTS` - Entity A implements Entity B
210
+ - `DEPENDS_ON` - Entity A depends on Entity B
211
+ - `EXTENDS` - Entity A extends Entity B
212
+ - `CONTAINS` - Entity A contains Entity B
213
+ - `RELATED_TO` - General relationship
214
+ - `SUPERSEDES` - Entity A replaces Entity B
215
+
216
+ ---
217
+
218
+ ## Infrastructure
219
+
220
+ ### Docker Compose
221
+
222
+ Create `docker-compose.yaml`:
223
+
224
+ ```yaml
225
+ version: '3.8'
226
+
227
+ services:
228
+ falkordb:
229
+ image: falkordb/falkordb:latest
230
+ container_name: lattice-falkordb
231
+ ports:
232
+ - "6379:6379"
233
+ volumes:
234
+ - falkordb-data:/data
235
+ environment:
236
+ - FALKORDB_ARGS=--requirepass ""
237
+ restart: unless-stopped
238
+ healthcheck:
239
+ test: ["CMD", "redis-cli", "ping"]
240
+ interval: 10s
241
+ timeout: 5s
242
+ retries: 3
243
+
244
+ volumes:
245
+ falkordb-data:
246
+ driver: local
247
+ ```
248
+
249
+ Start the database:
250
+
251
+ ```bash
252
+ docker-compose up -d
253
+ ```
254
+
255
+ ### Kubernetes (k3s)
256
+
257
+ For production deployments, use the provided k3s manifests:
258
+
259
+ ```bash
260
+ # Create namespace
261
+ kubectl apply -f infra/k3s/namespace.yaml
262
+
263
+ # Deploy storage
264
+ kubectl apply -f infra/k3s/pv.yaml
265
+ kubectl apply -f infra/k3s/pvc.yaml
266
+
267
+ # Deploy FalkorDB
268
+ kubectl apply -f infra/k3s/deployment.yaml
269
+ kubectl apply -f infra/k3s/service.yaml
270
+
271
+ # Optional: NodePort for external access
272
+ kubectl apply -f infra/k3s/nodeport-service.yaml
273
+
274
+ # Optional: Ingress
275
+ kubectl apply -f infra/k3s/ingress.yaml
276
+ ```
277
+
278
+ ---
279
+
280
+ ## Development
281
+
282
+ ### Prerequisites
283
+
284
+ - Node.js >= 18.0.0
285
+ - Bun (recommended) or npm
286
+ - Docker (for FalkorDB)
287
+
288
+ ### Setup
289
+
290
+ ```bash
291
+ # Clone the repository
292
+ git clone https://github.com/Zabaca/lattice.git
293
+ cd lattice
294
+
295
+ # Install dependencies
296
+ bun install
297
+
298
+ # Copy environment configuration
299
+ cp .env.example .env
300
+ # Edit .env with your settings
301
+
302
+ # Start FalkorDB
303
+ docker-compose -f infra/docker-compose.yaml up -d
304
+ ```
305
+
306
+ ### Running Locally
307
+
308
+ ```bash
309
+ # Development mode
310
+ bun run dev
311
+
312
+ # Run CLI commands during development
313
+ bun run lattice sync
314
+ bun run lattice status
315
+
316
+ # Run tests
317
+ bun test
318
+
319
+ # Build for production
320
+ bun run build
321
+ ```
322
+
323
+ ### Project Structure
324
+
325
+ ```
326
+ lattice/
327
+ ├── src/
328
+ │ ├── commands/ # CLI command implementations
329
+ │ ├── embedding/ # Voyage AI embedding service
330
+ │ ├── graph/ # FalkorDB graph operations
331
+ │ ├── query/ # Query builders and parsers
332
+ │ ├── sync/ # Document sync logic
333
+ │ ├── utils/ # Shared utilities
334
+ │ ├── app.module.ts # NestJS application module
335
+ │ ├── cli.ts # CLI entry point
336
+ │ └── main.ts # Main application entry
337
+ ├── infra/
338
+ │ ├── docker-compose.yaml
339
+ │ └── k3s/ # Kubernetes manifests
340
+ ├── examples/ # Usage examples
341
+ └── dist/ # Build output
342
+ ```
343
+
344
+ ---
345
+
346
+ ## API Usage
347
+
348
+ Lattice can also be used programmatically:
349
+
350
+ ```typescript
351
+ import { NestFactory } from '@nestjs/core';
352
+ import { AppModule } from '@zabaca/lattice';
353
+
354
+ async function main() {
355
+ const app = await NestFactory.createApplicationContext(AppModule);
356
+
357
+ // Get services
358
+ const syncService = app.get(SyncService);
359
+ const graphService = app.get(GraphService);
360
+
361
+ // Sync documents
362
+ const result = await syncService.sync({
363
+ paths: ['./docs'],
364
+ force: false,
365
+ dryRun: false
366
+ });
367
+
368
+ console.log(`Synced ${result.added} new documents`);
369
+
370
+ await app.close();
371
+ }
372
+ ```
373
+
374
+ ---
375
+
376
+ ## Contributing
377
+
378
+ Contributions are welcome! Please feel free to submit a Pull Request.
379
+
380
+ 1. Fork the repository
381
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
382
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
383
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
384
+ 5. Open a Pull Request
385
+
386
+ ---
387
+
388
+ ## License
389
+
390
+ MIT License - see [LICENSE](LICENSE) for details.
391
+
392
+ ---
393
+
394
+ ## Acknowledgments
395
+
396
+ - [FalkorDB](https://www.falkordb.com/) - High-performance graph database
397
+ - [Voyage AI](https://www.voyageai.com/) - State-of-the-art embeddings
398
+ - [NestJS](https://nestjs.com/) - Progressive Node.js framework