rvlite 0.2.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.
package/README.md ADDED
@@ -0,0 +1,270 @@
1
+ # RvLite
2
+
3
+ Lightweight vector database with SQL, SPARQL, and Cypher - runs everywhere (Node.js, Browser, Edge).
4
+
5
+ Built on WebAssembly for maximum performance and portability. Only ~850KB!
6
+
7
+ ## Features
8
+
9
+ - **Vector Search** - Semantic similarity with cosine, euclidean, or dot product distance
10
+ - **SQL** - Query vectors with standard SQL plus distance operations
11
+ - **Cypher** - Property graph queries (Neo4j-compatible syntax)
12
+ - **SPARQL** - RDF triple store with W3C SPARQL queries
13
+ - **Persistence** - Save/load to file (Node.js) or IndexedDB (browser)
14
+ - **Tiny** - ~850KB WASM bundle, no external dependencies
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install rvlite
20
+ ```
21
+
22
+ ## CLI Usage
23
+
24
+ ```bash
25
+ # Initialize a new database
26
+ npx rvlite init
27
+
28
+ # Insert a vector
29
+ npx rvlite insert "[0.1, 0.2, 0.3, ...]" --metadata '{"text": "Hello"}'
30
+
31
+ # Search for similar vectors
32
+ npx rvlite search "[0.1, 0.2, 0.3, ...]" --top 5
33
+
34
+ # SQL queries
35
+ npx rvlite sql "SELECT * FROM vectors LIMIT 10"
36
+
37
+ # Cypher queries
38
+ npx rvlite cypher "CREATE (p:Person {name: 'Alice'})"
39
+ npx rvlite cypher "MATCH (p:Person) RETURN p"
40
+
41
+ # SPARQL queries
42
+ npx rvlite triple "http://example.org/alice" "http://xmlns.com/foaf/0.1/name" "Alice"
43
+ npx rvlite sparql "SELECT ?s ?p ?o WHERE { ?s ?p ?o }"
44
+
45
+ # Interactive REPL
46
+ npx rvlite repl
47
+
48
+ # Database stats
49
+ npx rvlite stats
50
+
51
+ # Export/Import
52
+ npx rvlite export backup.json
53
+ npx rvlite import backup.json
54
+ ```
55
+
56
+ ### REPL Commands
57
+
58
+ ```
59
+ .sql - Switch to SQL mode
60
+ .cypher - Switch to Cypher mode
61
+ .sparql - Switch to SPARQL mode
62
+ .stats - Show database statistics
63
+ .save - Save database
64
+ .exit - Exit REPL
65
+ ```
66
+
67
+ ## SDK Usage
68
+
69
+ ### Basic Vector Operations
70
+
71
+ ```typescript
72
+ import { RvLite, createRvLite } from 'rvlite';
73
+
74
+ // Create instance
75
+ const db = await createRvLite({ dimensions: 384 });
76
+
77
+ // Insert vectors
78
+ const id = await db.insert([0.1, 0.2, 0.3, ...], { text: "Hello world" });
79
+
80
+ // Insert with custom ID
81
+ await db.insertWithId("my-doc-1", [0.1, 0.2, ...], { source: "article" });
82
+
83
+ // Search similar
84
+ const results = await db.search([0.1, 0.2, ...], 5);
85
+ // [{ id: "...", score: 0.95, metadata: {...} }, ...]
86
+
87
+ // Get by ID
88
+ const item = await db.get("my-doc-1");
89
+
90
+ // Delete
91
+ await db.delete("my-doc-1");
92
+ ```
93
+
94
+ ### SQL Queries
95
+
96
+ ```typescript
97
+ // Create table and insert
98
+ await db.sql("CREATE TABLE documents (id TEXT, title TEXT, embedding VECTOR)");
99
+ await db.sql("INSERT INTO documents VALUES ('doc1', 'Hello', '[0.1, 0.2, ...]')");
100
+
101
+ // Query with vector distance
102
+ const results = await db.sql(`
103
+ SELECT id, title, distance(embedding, '[0.1, 0.2, ...]') as dist
104
+ FROM documents
105
+ WHERE dist < 0.5
106
+ ORDER BY dist
107
+ `);
108
+ ```
109
+
110
+ ### Cypher Graph Queries
111
+
112
+ ```typescript
113
+ // Create nodes
114
+ await db.cypher("CREATE (alice:Person {name: 'Alice', age: 30})");
115
+ await db.cypher("CREATE (bob:Person {name: 'Bob', age: 25})");
116
+
117
+ // Create relationships
118
+ await db.cypher(`
119
+ MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
120
+ CREATE (a)-[:KNOWS {since: 2020}]->(b)
121
+ `);
122
+
123
+ // Query
124
+ const friends = await db.cypher(`
125
+ MATCH (p:Person)-[:KNOWS]->(friend:Person)
126
+ WHERE p.name = 'Alice'
127
+ RETURN friend.name
128
+ `);
129
+ ```
130
+
131
+ ### SPARQL RDF Queries
132
+
133
+ ```typescript
134
+ // Add triples
135
+ await db.addTriple(
136
+ "http://example.org/alice",
137
+ "http://xmlns.com/foaf/0.1/name",
138
+ "Alice"
139
+ );
140
+
141
+ await db.addTriple(
142
+ "http://example.org/alice",
143
+ "http://xmlns.com/foaf/0.1/knows",
144
+ "http://example.org/bob"
145
+ );
146
+
147
+ // Query
148
+ const results = await db.sparql(`
149
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
150
+ SELECT ?name WHERE {
151
+ <http://example.org/alice> foaf:name ?name
152
+ }
153
+ `);
154
+ ```
155
+
156
+ ### Persistence
157
+
158
+ ```typescript
159
+ // Node.js - Export to file
160
+ const state = await db.exportJson();
161
+ fs.writeFileSync('db.json', JSON.stringify(state));
162
+
163
+ // Node.js - Import from file
164
+ const data = JSON.parse(fs.readFileSync('db.json'));
165
+ await db.importJson(data);
166
+
167
+ // Browser - Save to IndexedDB
168
+ await db.save();
169
+
170
+ // Browser - Load from IndexedDB
171
+ const db = await RvLite.load({ dimensions: 384 });
172
+
173
+ // Browser - Clear storage
174
+ await RvLite.clearStorage();
175
+ ```
176
+
177
+ ### Semantic Memory for AI
178
+
179
+ ```typescript
180
+ import { RvLite, SemanticMemory, createRvLite } from 'rvlite';
181
+
182
+ // Create with embedding provider
183
+ const db = await createRvLite({ dimensions: 1536 });
184
+ const memory = new SemanticMemory(db);
185
+
186
+ // Store memories with embeddings
187
+ await memory.store("conv-1", "User asked about weather", embedding1);
188
+ await memory.store("conv-2", "Discussed travel plans", embedding2);
189
+
190
+ // Add relationships
191
+ await memory.addRelation("conv-1", "LEADS_TO", "conv-2");
192
+
193
+ // Query by similarity
194
+ const similar = await memory.query("What was the weather question?", queryEmbedding);
195
+
196
+ // Find related through graph
197
+ const related = await memory.findRelated("conv-1", 2);
198
+ ```
199
+
200
+ ## Integration with claude-flow
201
+
202
+ RvLite can enhance claude-flow's memory system with semantic search:
203
+
204
+ ```typescript
205
+ import { RvLite, SemanticMemory } from 'rvlite';
206
+
207
+ // In your claude-flow hooks
208
+ const db = await createRvLite({ dimensions: 1536 });
209
+
210
+ // Pre-task hook: Find relevant context
211
+ async function preTask(task) {
212
+ const embedding = await getEmbedding(task.description);
213
+ const context = await db.search(embedding, 5);
214
+ return { ...task, context };
215
+ }
216
+
217
+ // Post-task hook: Store results
218
+ async function postTask(task, result) {
219
+ const embedding = await getEmbedding(result.summary);
220
+ await db.insert(embedding, {
221
+ task: task.id,
222
+ result: result.summary,
223
+ timestamp: Date.now()
224
+ });
225
+ }
226
+ ```
227
+
228
+ ## API Reference
229
+
230
+ ### RvLite Class
231
+
232
+ | Method | Description |
233
+ |--------|-------------|
234
+ | `insert(vector, metadata?)` | Insert vector, returns ID |
235
+ | `insertWithId(id, vector, metadata?)` | Insert with custom ID |
236
+ | `search(query, k)` | Find k nearest vectors |
237
+ | `get(id)` | Get vector by ID |
238
+ | `delete(id)` | Delete vector by ID |
239
+ | `len()` | Count of vectors |
240
+ | `sql(query)` | Execute SQL query |
241
+ | `cypher(query)` | Execute Cypher query |
242
+ | `cypherStats()` | Get graph statistics |
243
+ | `sparql(query)` | Execute SPARQL query |
244
+ | `addTriple(s, p, o, graph?)` | Add RDF triple |
245
+ | `tripleCount()` | Count of triples |
246
+ | `exportJson()` | Export state to JSON |
247
+ | `importJson(data)` | Import state from JSON |
248
+ | `save()` | Save to IndexedDB (browser) |
249
+ | `RvLite.load(config)` | Load from IndexedDB |
250
+ | `RvLite.clearStorage()` | Clear IndexedDB |
251
+
252
+ ### CLI Commands
253
+
254
+ | Command | Description |
255
+ |---------|-------------|
256
+ | `rvlite init` | Initialize database |
257
+ | `rvlite insert <vector>` | Insert vector |
258
+ | `rvlite search <vector>` | Search similar |
259
+ | `rvlite sql <query>` | Execute SQL |
260
+ | `rvlite cypher <query>` | Execute Cypher |
261
+ | `rvlite sparql <query>` | Execute SPARQL |
262
+ | `rvlite triple <s> <p> <o>` | Add triple |
263
+ | `rvlite stats` | Show statistics |
264
+ | `rvlite export <file>` | Export to JSON |
265
+ | `rvlite import <file>` | Import from JSON |
266
+ | `rvlite repl` | Start interactive mode |
267
+
268
+ ## License
269
+
270
+ MIT OR Apache-2.0