@sochdb/sochdb 0.4.0 → 0.4.2
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 +416 -34
- package/_bin/aarch64-apple-darwin/libsochdb_storage.dylib +0 -0
- package/_bin/aarch64-apple-darwin/sochdb-bulk +0 -0
- package/_bin/aarch64-apple-darwin/sochdb-grpc-server +0 -0
- package/_bin/aarch64-apple-darwin/sochdb-server +0 -0
- package/_bin/x86_64-pc-windows-msvc/sochdb-bulk.exe +0 -0
- package/_bin/x86_64-pc-windows-msvc/sochdb-grpc-server.exe +0 -0
- package/_bin/x86_64-pc-windows-msvc/sochdb_storage.dll +0 -0
- package/_bin/x86_64-unknown-linux-gnu/libsochdb_storage.so +0 -0
- package/_bin/x86_64-unknown-linux-gnu/sochdb-bulk +0 -0
- package/_bin/x86_64-unknown-linux-gnu/sochdb-grpc-server +0 -0
- package/_bin/x86_64-unknown-linux-gnu/sochdb-server +0 -0
- package/bin/sochdb-bulk.js +1 -1
- package/bin/sochdb-grpc-server.js +1 -1
- package/bin/sochdb-server.js +1 -1
- package/dist/cjs/context-builder.js +280 -0
- package/dist/cjs/database.js +2 -2
- package/dist/cjs/embedded/database.js +2 -2
- package/dist/cjs/embedded/ffi/hnsw-bindings.js +295 -0
- package/dist/cjs/embedded/ffi/library-finder.js +10 -3
- package/dist/cjs/embedded/index.js +5 -2
- package/dist/cjs/errors.js +99 -7
- package/dist/cjs/index.js +46 -6
- package/dist/cjs/ipc-client.js +2 -2
- package/dist/cjs/memory/consolidation.js +202 -0
- package/dist/cjs/memory/extraction.js +181 -0
- package/dist/cjs/memory/index.js +26 -0
- package/dist/cjs/memory/retrieval.js +232 -0
- package/dist/cjs/memory/types.js +69 -0
- package/dist/cjs/namespace.js +255 -0
- package/dist/cjs/queue.js +289 -0
- package/dist/cjs/semantic-cache.js +220 -0
- package/dist/esm/context-builder.js +280 -0
- package/dist/esm/database.js +2 -2
- package/dist/esm/embedded/database.js +2 -2
- package/dist/esm/embedded/ffi/hnsw-bindings.js +316 -0
- package/dist/esm/embedded/ffi/library-finder.js +10 -3
- package/dist/esm/embedded/index.js +5 -2
- package/dist/esm/errors.js +107 -7
- package/dist/esm/index.js +46 -6
- package/dist/esm/ipc-client.js +2 -2
- package/dist/esm/memory/consolidation.js +206 -0
- package/dist/esm/memory/extraction.js +185 -0
- package/dist/esm/memory/index.js +26 -0
- package/dist/esm/memory/retrieval.js +243 -0
- package/dist/esm/memory/types.js +72 -0
- package/dist/esm/namespace.js +262 -0
- package/dist/esm/queue.js +291 -0
- package/dist/esm/semantic-cache.js +223 -0
- package/dist/types/context-builder.d.ts +97 -0
- package/dist/types/context-builder.d.ts.map +1 -0
- package/dist/types/database.d.ts +1 -1
- package/dist/types/embedded/database.d.ts +1 -1
- package/dist/types/embedded/ffi/hnsw-bindings.d.ts +90 -0
- package/dist/types/embedded/ffi/hnsw-bindings.d.ts.map +1 -0
- package/dist/types/embedded/ffi/library-finder.d.ts.map +1 -1
- package/dist/types/embedded/index.d.ts +1 -0
- package/dist/types/embedded/index.d.ts.map +1 -1
- package/dist/types/errors.d.ts +57 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +15 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/ipc-client.d.ts +1 -1
- package/dist/types/memory/consolidation.d.ts +66 -0
- package/dist/types/memory/consolidation.d.ts.map +1 -0
- package/dist/types/memory/extraction.d.ts +82 -0
- package/dist/types/memory/extraction.d.ts.map +1 -0
- package/dist/types/memory/index.d.ts +10 -0
- package/dist/types/memory/index.d.ts.map +1 -0
- package/dist/types/memory/retrieval.d.ts +46 -0
- package/dist/types/memory/retrieval.d.ts.map +1 -0
- package/dist/types/memory/types.d.ts +147 -0
- package/dist/types/memory/types.d.ts.map +1 -0
- package/dist/types/namespace.d.ts +129 -0
- package/dist/types/namespace.d.ts.map +1 -0
- package/dist/types/queue.d.ts +120 -0
- package/dist/types/queue.d.ts.map +1 -0
- package/dist/types/semantic-cache.d.ts +84 -0
- package/dist/types/semantic-cache.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,202 @@
|
|
|
1
|
-
# SochDB Node.js SDK
|
|
1
|
+
# SochDB Node.js SDK
|
|
2
2
|
|
|
3
3
|
**Dual-mode architecture: Embedded (FFI) + Server (gRPC/IPC)**
|
|
4
4
|
Choose the deployment mode that fits your needs.
|
|
5
5
|
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
### Memory System - LLM-Native Memory for AI Agents
|
|
9
|
+
Complete memory system with extraction, consolidation, and hybrid retrieval:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import {
|
|
13
|
+
EmbeddedDatabase,
|
|
14
|
+
ExtractionPipeline,
|
|
15
|
+
Consolidator,
|
|
16
|
+
HybridRetriever,
|
|
17
|
+
AllowedSet,
|
|
18
|
+
} from '@sochdb/sochdb';
|
|
19
|
+
|
|
20
|
+
const db = await EmbeddedDatabase.open('./memory_db');
|
|
21
|
+
|
|
22
|
+
// Extract entities and relations from text
|
|
23
|
+
const pipeline = ExtractionPipeline.fromDatabase(db, 'user_123', {
|
|
24
|
+
entityTypes: ['person', 'organization', 'location'],
|
|
25
|
+
minConfidence: 0.7,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const result = await pipeline.extractAndCommit(
|
|
29
|
+
'Alice works at Acme Corp',
|
|
30
|
+
myLLMExtractor // Your LLM integration
|
|
31
|
+
);
|
|
32
|
+
console.log(`Extracted ${result.entities.length} entities`);
|
|
33
|
+
|
|
34
|
+
// Consolidate facts with event sourcing
|
|
35
|
+
const consolidator = Consolidator.fromDatabase(db, 'user_123');
|
|
36
|
+
await consolidator.add({
|
|
37
|
+
fact: { subject: 'Alice', predicate: 'lives_in', object: 'SF' },
|
|
38
|
+
source: 'conversation_1',
|
|
39
|
+
confidence: 0.9,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const updated = await consolidator.consolidate();
|
|
43
|
+
const facts = await consolidator.getCanonicalFacts();
|
|
44
|
+
|
|
45
|
+
// Hybrid retrieval with RRF fusion
|
|
46
|
+
const retriever = HybridRetriever.fromDatabase(db, 'user_123', 'documents');
|
|
47
|
+
await retriever.indexDocuments(docs);
|
|
48
|
+
|
|
49
|
+
const results = await retriever.retrieve(
|
|
50
|
+
'machine learning papers',
|
|
51
|
+
queryEmbedding,
|
|
52
|
+
AllowedSet.fromNamespace('user_123')
|
|
53
|
+
);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**[→ See Full Example](./examples/memory-system-example.ts)**
|
|
57
|
+
|
|
58
|
+
**Key Features:**
|
|
59
|
+
- ✅ Extraction Pipeline: Compile LLM outputs into typed facts
|
|
60
|
+
- ✅ Event-Sourced Consolidation: Append-only with temporal updates
|
|
61
|
+
- ✅ Hybrid Retrieval: RRF fusion of vector + keyword search
|
|
62
|
+
- ✅ Namespace Isolation: Multi-tenant security with pre-filtering
|
|
63
|
+
- ✅ Schema Validation: Type checking and confidence thresholds
|
|
64
|
+
|
|
65
|
+
### Semantic Cache - LLM Response Caching
|
|
66
|
+
Vector similarity-based caching for LLM responses to reduce costs and latency:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { EmbeddedDatabase, SemanticCache } from '@sochdb/sochdb';
|
|
70
|
+
|
|
71
|
+
const db = await EmbeddedDatabase.open('./mydb');
|
|
72
|
+
const cache = new SemanticCache(db, 'llm_responses');
|
|
73
|
+
|
|
74
|
+
// Store LLM response with embedding
|
|
75
|
+
await cache.put(
|
|
76
|
+
'What is machine learning?',
|
|
77
|
+
'Machine learning is a subset of AI...',
|
|
78
|
+
embedding, // 384-dim vector
|
|
79
|
+
3600, // TTL in seconds
|
|
80
|
+
{ model: 'gpt-4', tokens: 150 }
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Check cache before calling LLM
|
|
84
|
+
const hit = await cache.get(queryEmbedding, 0.85);
|
|
85
|
+
if (hit) {
|
|
86
|
+
console.log(`Cache HIT! Similarity: ${hit.score.toFixed(4)}`);
|
|
87
|
+
console.log(`Response: ${hit.value}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Get statistics
|
|
91
|
+
const stats = await cache.stats();
|
|
92
|
+
console.log(`Hit rate: ${(stats.hitRate * 100).toFixed(1)}%`);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**[→ See Full Example](./examples/semantic-cache-example.ts)**
|
|
96
|
+
|
|
97
|
+
**Key Benefits:**
|
|
98
|
+
- ✅ Cosine similarity matching (0-1 threshold)
|
|
99
|
+
- ✅ TTL-based expiration
|
|
100
|
+
- ✅ Hit/miss statistics tracking
|
|
101
|
+
- ✅ Memory usage monitoring
|
|
102
|
+
- ✅ Automatic expired entry purging
|
|
103
|
+
|
|
104
|
+
### Context Query Builder - Token-Aware LLM Context
|
|
105
|
+
Assemble LLM context with priority-based truncation and token budgeting:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { ContextQueryBuilder, ContextOutputFormat, TruncationStrategy } from '@sochdb/sochdb';
|
|
109
|
+
|
|
110
|
+
const builder = new ContextQueryBuilder()
|
|
111
|
+
.withBudget(4096) // Token limit
|
|
112
|
+
.setFormat(ContextOutputFormat.TOON)
|
|
113
|
+
.setTruncation(TruncationStrategy.TAIL_DROP);
|
|
114
|
+
|
|
115
|
+
builder
|
|
116
|
+
.literal('SYSTEM', 0, 'You are a helpful AI assistant.')
|
|
117
|
+
.literal('USER_PROFILE', 1, 'User: Alice, Role: Engineer')
|
|
118
|
+
.literal('HISTORY', 2, 'Recent conversation context...')
|
|
119
|
+
.literal('KNOWLEDGE', 3, 'Retrieved documents...');
|
|
120
|
+
|
|
121
|
+
const result = builder.execute();
|
|
122
|
+
console.log(`Tokens: ${result.tokenCount}/${4096}`);
|
|
123
|
+
console.log(`Context:\n${result.text}`);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**[→ See Full Example](./examples/context-builder-example.ts)**
|
|
127
|
+
|
|
128
|
+
**Key Benefits:**
|
|
129
|
+
- ✅ Priority-based section ordering (lower = higher priority)
|
|
130
|
+
- ✅ Token budget enforcement
|
|
131
|
+
- ✅ Multiple truncation strategies (tail drop, head drop, proportional)
|
|
132
|
+
- ✅ Multiple output formats (TOON, JSON, Markdown)
|
|
133
|
+
- ✅ Token count estimation
|
|
134
|
+
|
|
135
|
+
### Namespace API - Multi-Tenant Isolation
|
|
136
|
+
First-class namespace handles for secure multi-tenancy and data isolation:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { Database, Namespace, Collection, DistanceMetric } from '@sochdb/sochdb';
|
|
140
|
+
|
|
141
|
+
const db = await Database.open('./mydb');
|
|
142
|
+
|
|
143
|
+
// Create isolated namespace for each tenant
|
|
144
|
+
const namespace = new Namespace(db, 'tenant_acme', {
|
|
145
|
+
name: 'tenant_acme',
|
|
146
|
+
displayName: 'ACME Corporation',
|
|
147
|
+
labels: { plan: 'enterprise', region: 'us-west' }
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Create vector collection
|
|
151
|
+
const collection = await namespace.createCollection({
|
|
152
|
+
name: 'documents',
|
|
153
|
+
dimension: 384,
|
|
154
|
+
metric: DistanceMetric.Cosine,
|
|
155
|
+
indexed: true
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Insert and search vectors
|
|
159
|
+
await collection.insert([1.0, 2.0, ...], { title: 'Doc 1' });
|
|
160
|
+
const results = await collection.search({ queryVector: [...], k: 10 });
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**[→ See Full Example](./examples/namespace-example.ts)**
|
|
164
|
+
|
|
165
|
+
### Priority Queue API - Task Processing
|
|
166
|
+
Efficient priority queue with ordered-key storage (no O(N) blob rewrites):
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { Database, PriorityQueue } from '@sochdb/sochdb';
|
|
170
|
+
|
|
171
|
+
const db = await Database.open('./queue_db');
|
|
172
|
+
const queue = PriorityQueue.fromDatabase(db, 'tasks');
|
|
173
|
+
|
|
174
|
+
// Enqueue with priority (lower = higher urgency)
|
|
175
|
+
await queue.enqueue(1, Buffer.from('urgent task'), { type: 'payment' });
|
|
176
|
+
|
|
177
|
+
// Worker processes tasks
|
|
178
|
+
const task = await queue.dequeue('worker-1');
|
|
179
|
+
if (task) {
|
|
180
|
+
// Process task...
|
|
181
|
+
await queue.ack(task.taskId);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Get statistics
|
|
185
|
+
const stats = await queue.stats();
|
|
186
|
+
console.log(`Pending: ${stats.pending}, Completed: ${stats.completed}`);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**[→ See Full Example](./examples/queue-example.ts)**
|
|
190
|
+
|
|
191
|
+
**Key Benefits:**
|
|
192
|
+
- ✅ O(log N) enqueue/dequeue with ordered scans
|
|
193
|
+
- ✅ Atomic claim protocol for concurrent workers
|
|
194
|
+
- ✅ Visibility timeout for crash recovery
|
|
195
|
+
- ✅ Dead letter queue for failed tasks
|
|
196
|
+
- ✅ Multiple queues per database
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
6
200
|
## Architecture: Flexible Deployment
|
|
7
201
|
|
|
8
202
|
```
|
|
@@ -57,9 +251,204 @@ cd sochdb-typescript-sdk
|
|
|
57
251
|
npm install
|
|
58
252
|
```
|
|
59
253
|
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 🆕 Vector Search - Native HNSW (v0.4.2)
|
|
257
|
+
|
|
258
|
+
SochDB now includes **native HNSW (Hierarchical Navigable Small World)** vector search for sub-millisecond similarity search across millions of vectors.
|
|
259
|
+
|
|
260
|
+
### Quick Start - Vector Search
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { HnswIndex } from '@sochdb/sochdb';
|
|
264
|
+
|
|
265
|
+
// Create HNSW index
|
|
266
|
+
const index = new HnswIndex({
|
|
267
|
+
dimension: 384, // Vector dimension
|
|
268
|
+
maxConnections: 16, // M parameter (default: 16)
|
|
269
|
+
efConstruction: 200, // Build quality (default: 200)
|
|
270
|
+
efSearch: 100 // Search quality (default: 100)
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// Insert vectors (batch is 10-100× faster)
|
|
274
|
+
index.insertBatch(
|
|
275
|
+
['doc1', 'doc2', 'doc3'],
|
|
276
|
+
[[1.0, 2.0, ...], [3.0, 4.0, ...], [5.0, 6.0, ...]]
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
// Search for similar vectors
|
|
280
|
+
const results = index.search(queryVector, 10);
|
|
281
|
+
console.log(results);
|
|
282
|
+
// [{ id: 'doc1', distance: 0.15 }, { id: 'doc3', distance: 0.23 }, ...]
|
|
283
|
+
|
|
284
|
+
// Clean up
|
|
285
|
+
index.close();
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Performance Comparison
|
|
289
|
+
|
|
290
|
+
| Implementation | 10K vectors | 100K vectors | 1M vectors |
|
|
291
|
+
|----------------|-------------|--------------|------------|
|
|
292
|
+
| **Linear Scan (old)** | ~50ms | ~500ms | ~5000ms |
|
|
293
|
+
| **Native HNSW (new)** | <0.5ms | <1ms | <1ms |
|
|
294
|
+
| **Speedup** | **100×** | **500×** | **5000×** |
|
|
295
|
+
|
|
296
|
+
### Two Ways to Use Vector Search
|
|
297
|
+
|
|
298
|
+
#### 1. Direct HNSW API (Recommended for Production)
|
|
299
|
+
|
|
300
|
+
Best performance, full control:
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
import { HnswIndex } from '@sochdb/sochdb';
|
|
304
|
+
|
|
305
|
+
const index = new HnswIndex({ dimension: 1536 });
|
|
306
|
+
index.insertBatch(ids, embeddings);
|
|
307
|
+
const results = index.search(queryEmbedding, 10);
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**✅ Use when:**
|
|
311
|
+
- You need maximum performance
|
|
312
|
+
- Working with large datasets (>10K vectors)
|
|
313
|
+
- Building RAG/AI applications
|
|
314
|
+
- Have existing embedding pipeline
|
|
315
|
+
|
|
316
|
+
#### 2. Collection API (Simple, High-Level)
|
|
317
|
+
|
|
318
|
+
Convenient API with metadata support:
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
import { Database } from '@sochdb/sochdb';
|
|
322
|
+
|
|
323
|
+
const db = await Database.open('./mydb');
|
|
324
|
+
const ns = await db.createNamespace({ name: 'docs' });
|
|
325
|
+
|
|
326
|
+
const collection = await ns.createCollection({
|
|
327
|
+
name: 'embeddings',
|
|
328
|
+
dimension: 384,
|
|
329
|
+
indexed: true // Note: Currently uses linear search in embedded mode
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
await collection.insert([1.0, 2.0, ...], { title: 'Document 1' }, 'doc1');
|
|
333
|
+
const results = await collection.search({ queryVector: [...], k: 10 });
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**⚠️ Current Limitation:** Collection API uses O(n) linear search in embedded mode. For production use with >10K vectors, use:
|
|
337
|
+
- Direct HNSW API (above), OR
|
|
338
|
+
- gRPC Server Mode (see below)
|
|
339
|
+
|
|
340
|
+
**✅ Coming in v0.4.3:** Collection API will automatically use native HNSW
|
|
341
|
+
|
|
342
|
+
#### 3. gRPC Server Mode (Production-Ready)
|
|
343
|
+
|
|
344
|
+
For distributed systems, multi-language support:
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
import { SochDBClient } from '@sochdb/sochdb';
|
|
348
|
+
|
|
349
|
+
// Start server: sochdb-grpc --port 50051
|
|
350
|
+
const client = new SochDBClient({ address: 'localhost:50051' });
|
|
351
|
+
|
|
352
|
+
// Create HNSW index
|
|
353
|
+
await client.createIndex('docs', {
|
|
354
|
+
dimension: 1536,
|
|
355
|
+
config: { m: 16, ef_construction: 200 },
|
|
356
|
+
metric: 'cosine'
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// Insert and search
|
|
360
|
+
await client.insertBatch('docs', ids, vectors);
|
|
361
|
+
const results = await client.search('docs', queryVector, 10);
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
**✅ Full HNSW support with:**
|
|
365
|
+
- Native Rust implementation
|
|
366
|
+
- Persistence
|
|
367
|
+
- Distributed queries
|
|
368
|
+
- Multi-language clients
|
|
369
|
+
|
|
370
|
+
### Migration from Linear Search
|
|
371
|
+
|
|
372
|
+
If you're using the Collection API with large datasets and experiencing slow search:
|
|
373
|
+
|
|
374
|
+
**Before (slow):**
|
|
375
|
+
```typescript
|
|
376
|
+
// O(n) scan through all documents
|
|
377
|
+
const results = await collection.search({ queryVector, k: 10 });
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
**After (fast) - Option 1: Use HnswIndex directly:**
|
|
381
|
+
```typescript
|
|
382
|
+
import { HnswIndex } from '@sochdb/sochdb';
|
|
383
|
+
|
|
384
|
+
const index = new HnswIndex({ dimension: 384 });
|
|
385
|
+
index.insertBatch(ids, vectors);
|
|
386
|
+
const results = index.search(queryVector, 10); // <1ms
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
**After (fast) - Option 2: Use gRPC mode:**
|
|
390
|
+
```bash
|
|
391
|
+
# Terminal 1: Start server
|
|
392
|
+
sochdb-grpc --port 50051
|
|
393
|
+
|
|
394
|
+
# Terminal 2: Use client
|
|
395
|
+
```
|
|
396
|
+
```typescript
|
|
397
|
+
const client = new SochDBClient({ address: 'localhost:50051' });
|
|
398
|
+
await client.createIndex('docs', { dimension: 384 });
|
|
399
|
+
const results = await client.search('docs', queryVector, 10);
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Complete Examples
|
|
403
|
+
|
|
404
|
+
- **[06_native_vector_search.ts](https://github.com/sochdb/sochdb-nodejs-examples/blob/main/06_native_vector_search.ts)** - Direct HNSW usage with benchmarks
|
|
405
|
+
- **[AI PDF Chatbot](https://github.com/sochdb/sochdb-nodejs-examples/tree/main/ai-pdf-chatbot-langchain)** - LangChain RAG example
|
|
406
|
+
|
|
407
|
+
### API Reference
|
|
408
|
+
|
|
409
|
+
```typescript
|
|
410
|
+
// HnswIndex Configuration
|
|
411
|
+
interface HnswConfig {
|
|
412
|
+
dimension: number; // Required: vector dimension
|
|
413
|
+
maxConnections?: number; // M parameter (default: 16)
|
|
414
|
+
efConstruction?: number; // Build quality (default: 200)
|
|
415
|
+
efSearch?: number; // Search quality (default: 100)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Search Result
|
|
419
|
+
interface SearchResult {
|
|
420
|
+
id: string; // Vector ID
|
|
421
|
+
distance: number; // Distance (lower = more similar)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Main Methods
|
|
425
|
+
class HnswIndex {
|
|
426
|
+
constructor(config: HnswConfig)
|
|
427
|
+
insert(id: string, vector: number[]): void
|
|
428
|
+
insertBatch(ids: string[], vectors: number[][]): void
|
|
429
|
+
search(queryVector: number[], k: number, fast?: boolean): SearchResult[]
|
|
430
|
+
searchUltra(queryVector: number[], k: number): SearchResult[]
|
|
431
|
+
close(): void
|
|
432
|
+
|
|
433
|
+
// Properties
|
|
434
|
+
get length(): number // Number of vectors
|
|
435
|
+
get dimension(): number // Vector dimension
|
|
436
|
+
get efSearch(): number
|
|
437
|
+
set efSearch(value: number) // Adjust search quality
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Roadmap
|
|
442
|
+
|
|
443
|
+
- **v0.4.2** (current): Direct HNSW FFI bindings
|
|
444
|
+
- **v0.4.3** (next): Collection API auto-uses HNSW in embedded mode
|
|
445
|
+
- **v0.5.0**: Persistent HNSW indexes with disk storage
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
60
449
|
# SochDB Node.js SDK Documentation
|
|
61
450
|
|
|
62
|
-
**Version 0.4.
|
|
451
|
+
**Version 0.4.2** | LLM-Optimized Embedded Database with Native Vector Search
|
|
63
452
|
|
|
64
453
|
---
|
|
65
454
|
|
|
@@ -67,40 +456,33 @@ npm install
|
|
|
67
456
|
|
|
68
457
|
1. [Quick Start](#1-quick-start)
|
|
69
458
|
2. [Installation](#2-installation)
|
|
70
|
-
3. [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
459
|
+
3. [Features](#3-features)
|
|
460
|
+
- [Namespace API](#namespace-api---multi-tenant-isolation)
|
|
461
|
+
- [Priority Queue API](#priority-queue-api---task-processing)
|
|
462
|
+
4. [Architecture Overview](#4-architecture-overview)
|
|
463
|
+
5. [Core Key-Value Operations](#5-core-key-value-operations)
|
|
464
|
+
6. [Transactions (ACID with SSI)](#6-transactions-acid-with-ssi)
|
|
465
|
+
7. [Query Builder](#7-query-builder)
|
|
466
|
+
8. [Prefix Scanning](#8-prefix-scanning)
|
|
467
|
+
9. [SQL Operations](#9-sql-operations)
|
|
468
|
+
10. [Table Management & Index Policies](#10-table-management--index-policies)
|
|
469
|
+
11. [Namespaces & Collections](#11-namespaces--collections)
|
|
470
|
+
12. [Priority Queues](#12-priority-queues)
|
|
471
|
+
13. [Vector Search](#13-vector-search)
|
|
472
|
+
14. [Hybrid Search (Vector + BM25)](#14-hybrid-search-vector--bm25)
|
|
473
|
+
15. [Graph Operations](#15-graph-operations)
|
|
474
|
+
16. [Temporal Graph (Time-Travel)](#16-temporal-graph-time-travel)
|
|
475
|
+
17. [Semantic Cache](#17-semantic-cache)
|
|
476
|
+
18. [Context Query Builder (LLM Optimization)](#18-context-query-builder-llm-optimization)
|
|
477
|
+
19. [Atomic Multi-Index Writes](#19-atomic-multi-index-writes)
|
|
478
|
+
20. [Recovery & WAL Management](#20-recovery--wal-management)
|
|
479
|
+
21. [Checkpoints & Snapshots](#21-checkpoints--snapshots)
|
|
480
|
+
22. [Compression & Storage](#22-compression--storage)
|
|
481
|
+
23. [Statistics & Monitoring](#23-statistics--monitoring)
|
|
91
482
|
24. [Server Mode (gRPC Client)](#24-server-mode-grpc-client)
|
|
92
483
|
25. [IPC Client (Unix Sockets)](#25-ipc-client-unix-sockets)
|
|
93
|
-
26. [
|
|
94
|
-
27. [
|
|
95
|
-
28. [Data Formats (TOON/JSON/Columnar)](#28-data-formats-toonjsoncolumnar)
|
|
96
|
-
29. [Policy Service](#29-policy-service)
|
|
97
|
-
30. [MCP (Model Context Protocol)](#30-mcp-model-context-protocol)
|
|
98
|
-
31. [Configuration Reference](#31-configuration-reference)
|
|
99
|
-
32. [Error Handling](#32-error-handling)
|
|
100
|
-
33. [Async Support](#33-async-support)
|
|
101
|
-
34. [Building & Development](#34-building--development)
|
|
102
|
-
35. [Complete Examples](#35-complete-examples)
|
|
103
|
-
36. [Migration Guide](#36-migration-guide)
|
|
484
|
+
26. [Error Handling](#26-error-handling)
|
|
485
|
+
27. [Complete Examples](#27-complete-examples)
|
|
104
486
|
|
|
105
487
|
---
|
|
106
488
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/bin/sochdb-bulk.js
CHANGED
|
@@ -46,7 +46,7 @@ sochdb-bulk binary not found!
|
|
|
46
46
|
Searched at: ${bundledPath}
|
|
47
47
|
|
|
48
48
|
To fix:
|
|
49
|
-
1. Reinstall the package: npm install --force @
|
|
49
|
+
1. Reinstall the package: npm install --force @sochdb/sochdb
|
|
50
50
|
2. Or set SOCHDB_BULK_PATH environment variable
|
|
51
51
|
`);
|
|
52
52
|
}
|
|
@@ -46,7 +46,7 @@ sochdb-grpc-server binary not found!
|
|
|
46
46
|
Searched at: ${bundledPath}
|
|
47
47
|
|
|
48
48
|
To fix:
|
|
49
|
-
1. Reinstall the package: npm install --force @
|
|
49
|
+
1. Reinstall the package: npm install --force @sochdb/sochdb
|
|
50
50
|
2. Or set SOCHDB_GRPC_SERVER_PATH environment variable
|
|
51
51
|
`);
|
|
52
52
|
}
|
package/bin/sochdb-server.js
CHANGED
|
@@ -46,7 +46,7 @@ sochdb-server binary not found!
|
|
|
46
46
|
Searched at: ${bundledPath}
|
|
47
47
|
|
|
48
48
|
To fix:
|
|
49
|
-
1. Reinstall the package: npm install --force @
|
|
49
|
+
1. Reinstall the package: npm install --force @sochdb/sochdb
|
|
50
50
|
2. Or set SOCHDB_SERVER_PATH environment variable
|
|
51
51
|
`);
|
|
52
52
|
}
|