hebbrix 2.2.0 → 2.3.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.
- package/CHANGELOG.md +42 -0
- package/README.md +61 -732
- package/dist/index.d.mts +143 -37
- package/dist/index.d.ts +143 -37
- package/dist/index.js +313 -139
- package/dist/index.mjs +311 -138
- package/package.json +5 -8
package/README.md
CHANGED
|
@@ -1,771 +1,100 @@
|
|
|
1
1
|
# Hebbrix TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[](LICENSE)
|
|
3
|
+
Typed TypeScript/JavaScript client for Hebbrix memory, retrieval, and
|
|
4
|
+
outcome-learning APIs.
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## 🚀 Features
|
|
10
|
-
|
|
11
|
-
- ✅ **Complete API Coverage** - All 50+ endpoints supported
|
|
12
|
-
- ✅ **Reinforcement Learning** - Train AI agents to optimize memory operations
|
|
13
|
-
- ✅ **Temporal Knowledge Graphs** - Track facts over time with bi-temporal model
|
|
14
|
-
- ✅ **Procedural Memory** - Store and execute learned skills
|
|
15
|
-
- ✅ **Working Memory** - Short-term context buffer for conversations
|
|
16
|
-
- ✅ **Memory Consolidation** - Automatic compression of episodic memories
|
|
17
|
-
- ✅ **ProofLoop** - Learn from outcomes with automatic, verifiable evidence receipts
|
|
18
|
-
- ✅ **Promise-based** - Native async/await support
|
|
19
|
-
- ✅ **Type-safe** - Complete TypeScript type definitions
|
|
20
|
-
- ✅ **Universal** - Works in Node.js and browsers
|
|
21
|
-
- ✅ **Clean API** - Intuitive, developer-friendly interface
|
|
22
|
-
|
|
23
|
-
## 📦 Installation
|
|
6
|
+
## Install
|
|
24
7
|
|
|
25
8
|
```bash
|
|
26
|
-
npm install hebbrix
|
|
27
|
-
# or
|
|
28
|
-
yarn add hebbrix
|
|
29
|
-
# or
|
|
30
|
-
pnpm add hebbrix
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## 🔥 Quick Start
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
import { MemoryClient } from 'hebbrix';
|
|
37
|
-
|
|
38
|
-
const main = async () => {
|
|
39
|
-
// Initialize client
|
|
40
|
-
const client = new MemoryClient({ apiKey: 'hbx_your_api_key' });
|
|
41
|
-
|
|
42
|
-
// Create a collection
|
|
43
|
-
const collection = await client.collections.create({
|
|
44
|
-
name: 'My AI Agent',
|
|
45
|
-
description: 'Personal memory for my chatbot',
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Store a memory
|
|
49
|
-
const memory = await client.memories.create({
|
|
50
|
-
collection_id: collection.id,
|
|
51
|
-
content: 'User prefers dark mode and loves TypeScript',
|
|
52
|
-
importance: 0.9,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Search memories
|
|
56
|
-
const results = await client.search({
|
|
57
|
-
query: 'What programming language does user like?',
|
|
58
|
-
collection_id: collection.id,
|
|
59
|
-
limit: 5,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
console.log(results);
|
|
63
|
-
|
|
64
|
-
// Reason over memories
|
|
65
|
-
const answer = await client.reason({
|
|
66
|
-
query: 'What are user preferences?',
|
|
67
|
-
provider: 'gemini',
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
console.log(answer.answer);
|
|
71
|
-
console.log(answer.sources);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
main();
|
|
9
|
+
npm install hebbrix@2.3.0
|
|
75
10
|
```
|
|
76
11
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
const search = await client.searchWithProof({
|
|
81
|
-
query: 'What should the agent do next?',
|
|
82
|
-
collection_id: 'collection-42',
|
|
83
|
-
user_id: 'customer-7',
|
|
84
|
-
});
|
|
85
|
-
const decision = await client.proofloop.decide({
|
|
86
|
-
policy_key: 'agent.next_action',
|
|
87
|
-
candidates: [{ action_key: 'act' }, { action_key: 'ask' }],
|
|
88
|
-
collection_id: 'collection-42',
|
|
89
|
-
user_id: 'customer-7',
|
|
90
|
-
proof_context: search.proof_context,
|
|
91
|
-
});
|
|
92
|
-
await client.proofloop.recordOutcome(decision.decision_id, {
|
|
93
|
-
success: true,
|
|
94
|
-
idempotency_key: 'run-123-result',
|
|
95
|
-
});
|
|
96
|
-
const proof = await client.proofloop.proof(decision.decision_id);
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## 📚 Complete API Guide
|
|
100
|
-
|
|
101
|
-
### 1. Authentication
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
import { MemoryClient } from 'hebbrix';
|
|
105
|
-
|
|
106
|
-
// Using API key
|
|
107
|
-
const client = new MemoryClient({ apiKey: 'hbx_...' });
|
|
12
|
+
Node.js 16+ and modern browsers are supported.
|
|
108
13
|
|
|
109
|
-
|
|
110
|
-
const authResponse = await client.auth.register(
|
|
111
|
-
'user@example.com',
|
|
112
|
-
'secure_password',
|
|
113
|
-
'John Doe'
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
// Login
|
|
117
|
-
const loginResponse = await client.auth.login(
|
|
118
|
-
'user@example.com',
|
|
119
|
-
'secure_password'
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
// Create API key
|
|
123
|
-
const apiKey = await client.auth.createApiKey('My App Key');
|
|
124
|
-
console.log(apiKey.api_key); // hbx_...
|
|
125
|
-
|
|
126
|
-
// Get current user
|
|
127
|
-
const user = await client.auth.getMe();
|
|
128
|
-
console.log(user.email);
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### 2. Collections
|
|
14
|
+
## Quick start
|
|
132
15
|
|
|
133
16
|
```typescript
|
|
134
|
-
|
|
135
|
-
const collection = await client.collections.create({
|
|
136
|
-
name: 'Research Notes',
|
|
137
|
-
description: 'AI research papers and notes',
|
|
138
|
-
metadata: { category: 'research' },
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// List collections
|
|
142
|
-
const collections = await client.collections.list({ limit: 10, skip: 0 });
|
|
143
|
-
|
|
144
|
-
// Get collection
|
|
145
|
-
const retrieved = await client.collections.get(collection.id);
|
|
146
|
-
|
|
147
|
-
// Update collection
|
|
148
|
-
const updated = await client.collections.update(collection.id, {
|
|
149
|
-
name: 'Updated Name',
|
|
150
|
-
description: 'New description',
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
// Delete collection
|
|
154
|
-
await client.collections.delete(collection.id);
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### 3. Memories (Episodic)
|
|
17
|
+
import { MemoryClient } from "hebbrix";
|
|
158
18
|
|
|
159
|
-
|
|
160
|
-
|
|
19
|
+
const client = new MemoryClient({ apiKey: "hbx_your_api_key" });
|
|
20
|
+
const collection = await client.collections.create({ name: "Support memory" });
|
|
161
21
|
const memory = await client.memories.create({
|
|
162
22
|
collection_id: collection.id,
|
|
163
|
-
content:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// List memories
|
|
169
|
-
const memories = await client.memories.list({
|
|
170
|
-
collection_id: collection.id,
|
|
171
|
-
limit: 50,
|
|
172
|
-
skip: 0,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// Get memory with metadata
|
|
176
|
-
const retrieved = await client.memories.get(memory.id);
|
|
177
|
-
console.log(retrieved.content);
|
|
178
|
-
console.log(retrieved.importance);
|
|
179
|
-
console.log(retrieved.metadata);
|
|
180
|
-
|
|
181
|
-
// Update memory
|
|
182
|
-
const updated = await client.memories.update(memory.id, {
|
|
183
|
-
content: 'Updated content',
|
|
184
|
-
importance: 0.9,
|
|
23
|
+
content: "Customer prefers concise replies",
|
|
24
|
+
wait_for_index: true,
|
|
25
|
+
idempotency_key: "customer-42-preference-v1",
|
|
185
26
|
});
|
|
186
|
-
|
|
187
|
-
// Delete memory
|
|
188
|
-
await client.memories.delete(memory.id);
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### 4. Search & Retrieval
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
// Hybrid search (Vector + BM25)
|
|
195
27
|
const results = await client.search({
|
|
196
|
-
query:
|
|
28
|
+
query: "How should replies be formatted?",
|
|
197
29
|
collection_id: collection.id,
|
|
198
|
-
limit: 10,
|
|
199
|
-
search_type: 'hybrid', // 'vector' | 'bm25' | 'hybrid' | 'graph'
|
|
200
|
-
filters: { category: 'research' },
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
// Vector-only search
|
|
204
|
-
const vectorResults = await client.search({
|
|
205
|
-
query: 'neural networks',
|
|
206
|
-
search_type: 'vector',
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// BM25 keyword search
|
|
210
|
-
const keywordResults = await client.search({
|
|
211
|
-
query: 'specific technical terms',
|
|
212
|
-
search_type: 'bm25',
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
// Knowledge graph search
|
|
216
|
-
const graphResults = await client.search({
|
|
217
|
-
query: 'related concepts',
|
|
218
|
-
search_type: 'graph',
|
|
219
30
|
});
|
|
31
|
+
console.log(memory, results);
|
|
220
32
|
```
|
|
221
33
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
```typescript
|
|
225
|
-
// Reason over memories with Gemini
|
|
226
|
-
const answer = await client.reason({
|
|
227
|
-
query: 'Summarize what I learned about reinforcement learning',
|
|
228
|
-
collection_id: collection.id,
|
|
229
|
-
provider: 'gemini',
|
|
230
|
-
include_steps: true,
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
console.log(answer.answer);
|
|
234
|
-
console.log(answer.sources); // Source memories used
|
|
235
|
-
console.log(answer.reasoning_context); // Reasoning steps (if include_steps=true)
|
|
236
|
-
|
|
237
|
-
// Use different LLM providers
|
|
238
|
-
const openaiAnswer = await client.reason({
|
|
239
|
-
query: 'Explain the key concepts',
|
|
240
|
-
provider: 'openai', // 'gemini' | 'openai' | 'anthropic'
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
const anthropicAnswer = await client.reason({
|
|
244
|
-
query: 'What are the main takeaways?',
|
|
245
|
-
provider: 'anthropic',
|
|
246
|
-
});
|
|
247
|
-
```
|
|
34
|
+
## Durable readiness
|
|
248
35
|
|
|
249
|
-
|
|
36
|
+
Memory writes return either a searchable completion or a durable `202` receipt.
|
|
37
|
+
A durable receipt means the database commit succeeded while indexing is still
|
|
38
|
+
converging; it is not a failure and does not justify a duplicate write.
|
|
250
39
|
|
|
251
|
-
|
|
40
|
+
When `wait_for_index: true`, the SDK accepts the receipt and polls its status
|
|
41
|
+
URL. It returns only after `searchable: true`. If the client deadline expires,
|
|
42
|
+
it throws `IndexingTimeoutError`; the error retains the receipt, durable memory
|
|
43
|
+
IDs, and status URL. Reuse the same idempotency key with the same body to recover
|
|
44
|
+
the same logical resources.
|
|
252
45
|
|
|
253
46
|
```typescript
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
collection_id: collection
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
console.log(training.metrics); // Training metrics
|
|
261
|
-
|
|
262
|
-
// Train Answer Agent (optimizes retrieval strategy)
|
|
263
|
-
const answerTraining = await client.rl.trainAnswerAgent({
|
|
264
|
-
collection_id: collection.id,
|
|
265
|
-
num_episodes: 50,
|
|
47
|
+
const receipt = await client.memories.createBatch({
|
|
48
|
+
memories: [{ content: "First fact" }, { content: "Second fact" }],
|
|
49
|
+
collection_id: "collection-42",
|
|
50
|
+
wait_for_index: false,
|
|
51
|
+
idempotency_key: "import-42",
|
|
266
52
|
});
|
|
267
|
-
|
|
268
|
-
// Get RL training metrics
|
|
269
|
-
const metrics = await client.rl.getMetrics();
|
|
270
|
-
console.log(metrics.memory_manager_performance);
|
|
271
|
-
console.log(metrics.answer_agent_performance);
|
|
272
|
-
|
|
273
|
-
// Evaluate trained agent
|
|
274
|
-
const evaluation = await client.rl.evaluate('memory-manager', collection.id);
|
|
275
|
-
console.log(evaluation.accuracy);
|
|
276
|
-
console.log(evaluation.recall);
|
|
53
|
+
const completed = await client.memories.waitForBatchSearchable(receipt);
|
|
277
54
|
```
|
|
278
55
|
|
|
279
|
-
|
|
56
|
+
## Pagination
|
|
280
57
|
|
|
281
|
-
|
|
58
|
+
`collections.list()` returns `Promise<CursorPage<Collection>>`, matching the
|
|
59
|
+
runtime response. Read collections from `page.items` and pass
|
|
60
|
+
`page.next_cursor` into the next call. `memories.list()` returns item arrays for
|
|
61
|
+
backward compatibility; use `memories.listPage()` for cursor metadata.
|
|
282
62
|
|
|
283
63
|
```typescript
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
'search(query="today", limit=20)',
|
|
291
|
-
'consolidate(threshold=0.7)',
|
|
292
|
-
'generate_summary()',
|
|
293
|
-
],
|
|
294
|
-
collection_id: collection.id,
|
|
295
|
-
category: 'automation',
|
|
296
|
-
metadata: { frequency: 'daily' },
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// List procedures
|
|
300
|
-
const procedures = await client.procedural.list({
|
|
301
|
-
collection_id: collection.id,
|
|
302
|
-
category: 'automation',
|
|
303
|
-
limit: 50,
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
// Get procedure
|
|
307
|
-
const retrieved = await client.procedural.get(procedure.id);
|
|
308
|
-
|
|
309
|
-
// Execute procedure
|
|
310
|
-
const result = await client.procedural.execute(procedure.id, {
|
|
311
|
-
context: { user_id: 'user_123' },
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
console.log(result.output);
|
|
315
|
-
console.log(result.execution_time);
|
|
316
|
-
|
|
317
|
-
// Update procedure
|
|
318
|
-
const updated = await client.procedural.update(procedure.id, {
|
|
319
|
-
name: 'Updated Daily Summary',
|
|
320
|
-
action_sequence: ['search(query="important", limit=10)', 'summarize()'],
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
// Delete procedure
|
|
324
|
-
await client.procedural.delete(procedure.id);
|
|
64
|
+
let cursor: string | undefined;
|
|
65
|
+
do {
|
|
66
|
+
const page = await client.collections.list({ limit: 100, cursor });
|
|
67
|
+
for (const collection of page.items) console.log(collection.id);
|
|
68
|
+
cursor = page.next_cursor ?? undefined;
|
|
69
|
+
} while (cursor);
|
|
325
70
|
```
|
|
326
71
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
Track facts over time with bi-temporal modeling.
|
|
330
|
-
|
|
331
|
-
```typescript
|
|
332
|
-
// Add temporal fact
|
|
333
|
-
const fact = await client.temporal.addFact({
|
|
334
|
-
subject: 'User_123',
|
|
335
|
-
predicate: 'works_at',
|
|
336
|
-
object: 'TechCorp',
|
|
337
|
-
valid_from: '2024-01-01',
|
|
338
|
-
valid_until: '2024-12-31',
|
|
339
|
-
confidence: 0.95,
|
|
340
|
-
source_memory_id: memory.id,
|
|
341
|
-
metadata: { position: 'Engineer' },
|
|
342
|
-
});
|
|
72
|
+
## Advanced capabilities and entitlements
|
|
343
73
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
// Query facts at specific time
|
|
351
|
-
const historicalFacts = await client.temporal.queryFacts({
|
|
352
|
-
subject: 'User_123',
|
|
353
|
-
at_time: '2024-06-15',
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
// Point-in-time query (knowledge state at timestamp)
|
|
357
|
-
const snapshot = await client.temporal.pointInTime(
|
|
358
|
-
'2024-06-15T10:00:00Z',
|
|
359
|
-
'User_123'
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
console.log(snapshot.facts); // All facts valid at that time
|
|
363
|
-
console.log(snapshot.relationships); // Graph relationships
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
### 9. Working Memory
|
|
367
|
-
|
|
368
|
-
Short-term context buffer for conversations.
|
|
369
|
-
|
|
370
|
-
```typescript
|
|
371
|
-
// Add to working memory
|
|
372
|
-
await client.workingMemory.add({
|
|
373
|
-
role: 'user',
|
|
374
|
-
content: 'I want to learn about machine learning',
|
|
375
|
-
metadata: { timestamp: new Date().toISOString() },
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
await client.workingMemory.add({
|
|
379
|
-
role: 'assistant',
|
|
380
|
-
content: 'I can help you with that! What aspect interests you?',
|
|
381
|
-
metadata: { timestamp: new Date().toISOString() },
|
|
382
|
-
});
|
|
74
|
+
The client exposes the canonical `/v1` temporal, working-memory, consolidation,
|
|
75
|
+
memory-tool, and RL contracts. RL metrics and evaluation require the Pro plan.
|
|
76
|
+
Process-wide RL training and checkpoint mutation require an admin role.
|
|
77
|
+
Entitlement failures throw `EntitlementError` and preserve the stable error
|
|
78
|
+
code, current/required plan, request ID, and support action.
|
|
383
79
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
console.log(context.buffer_size); // Current buffer size
|
|
388
|
-
|
|
389
|
-
// Compress working memory (convert to episodic)
|
|
390
|
-
const compressed = await client.workingMemory.compress();
|
|
391
|
-
console.log(compressed.compressed_memories); // New episodic memories created
|
|
392
|
-
console.log(compressed.compression_ratio);
|
|
393
|
-
|
|
394
|
-
// Clear working memory
|
|
395
|
-
await client.workingMemory.clear();
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
### 10. Memory Consolidation
|
|
399
|
-
|
|
400
|
-
Automatic compression of episodic memories.
|
|
401
|
-
|
|
402
|
-
```typescript
|
|
403
|
-
// Trigger consolidation
|
|
404
|
-
const consolidation = await client.consolidation.consolidate(collection.id, 100);
|
|
405
|
-
|
|
406
|
-
console.log(consolidation.original_count); // Before consolidation
|
|
407
|
-
console.log(consolidation.consolidated_count); // After consolidation
|
|
408
|
-
console.log(consolidation.compression_ratio);
|
|
409
|
-
|
|
410
|
-
// Get consolidation statistics
|
|
411
|
-
const stats = await client.consolidation.getStats(collection.id);
|
|
412
|
-
console.log(stats.total_memories);
|
|
413
|
-
console.log(stats.consolidation_eligible);
|
|
414
|
-
console.log(stats.last_consolidation);
|
|
415
|
-
|
|
416
|
-
// Archive old memories
|
|
417
|
-
const archived = await client.consolidation.archive(
|
|
418
|
-
collection.id,
|
|
419
|
-
'2024-01-01' // Archive memories before this date
|
|
420
|
-
);
|
|
421
|
-
|
|
422
|
-
console.log(archived.archived_count);
|
|
423
|
-
console.log(archived.archived_ids);
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
### 11. Memory Tools (Self-Editing)
|
|
427
|
-
|
|
428
|
-
Advanced memory manipulation tools.
|
|
429
|
-
|
|
430
|
-
```typescript
|
|
431
|
-
// Replace memory content
|
|
432
|
-
const replaced = await client.memoryTools.replace({
|
|
433
|
-
memory_id: memory.id,
|
|
434
|
-
new_content: 'Updated information with corrections',
|
|
435
|
-
reason: 'Fixed inaccurate information',
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
// Insert memory at specific position
|
|
439
|
-
const inserted = await client.memoryTools.insert({
|
|
440
|
-
collection_id: collection.id,
|
|
441
|
-
content: 'Important context that was missing',
|
|
442
|
-
position: 5,
|
|
443
|
-
reason: 'Adding missing context',
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
// Rethink memory in light of new information
|
|
447
|
-
const rethought = await client.memoryTools.rethink(
|
|
448
|
-
memory.id,
|
|
449
|
-
'New evidence suggests different interpretation'
|
|
450
|
-
);
|
|
451
|
-
|
|
452
|
-
console.log(rethought.original_content);
|
|
453
|
-
console.log(rethought.updated_content);
|
|
454
|
-
console.log(rethought.changes);
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
### 12. World Model & Planning
|
|
458
|
-
|
|
459
|
-
Simulate retrieval and plan memory operations.
|
|
460
|
-
|
|
461
|
-
```typescript
|
|
462
|
-
// Imagine retrieval without actually retrieving
|
|
463
|
-
const imagination = await client.worldModel.imagineRetrieval(
|
|
464
|
-
'machine learning papers',
|
|
465
|
-
collection.id
|
|
466
|
-
);
|
|
467
|
-
|
|
468
|
-
console.log(imagination.expected_results); // Predicted results
|
|
469
|
-
console.log(imagination.confidence); // Prediction confidence
|
|
470
|
-
console.log(imagination.should_retrieve); // Recommendation
|
|
471
|
-
|
|
472
|
-
// Plan memory operations to achieve goal
|
|
473
|
-
const plan = await client.worldModel.plan(
|
|
474
|
-
'Prepare comprehensive summary of Q1 research',
|
|
475
|
-
collection.id
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
console.log(plan.steps); // Planned operations
|
|
479
|
-
console.log(plan.estimated_time); // Time estimate
|
|
480
|
-
console.log(plan.required_resources); // Resources needed
|
|
481
|
-
|
|
482
|
-
// Example plan output:
|
|
483
|
-
// {
|
|
484
|
-
// steps: [
|
|
485
|
-
// { action: 'search', params: { query: 'Q1 research', limit: 50 } },
|
|
486
|
-
// { action: 'consolidate', params: { threshold: 0.8 } },
|
|
487
|
-
// { action: 'reason', params: { query: 'summarize findings' } }
|
|
488
|
-
// ],
|
|
489
|
-
// estimated_time: 2.5,
|
|
490
|
-
// required_resources: { tokens: 5000, api_calls: 3 }
|
|
491
|
-
// }
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
## 🎯 Advanced Examples
|
|
495
|
-
|
|
496
|
-
### Building a Smart Chatbot
|
|
497
|
-
|
|
498
|
-
```typescript
|
|
499
|
-
import { MemoryClient } from 'hebbrix';
|
|
500
|
-
|
|
501
|
-
class SmartChatbot {
|
|
502
|
-
private client: MemoryClient;
|
|
503
|
-
private collectionId: string;
|
|
504
|
-
|
|
505
|
-
constructor(apiKey: string) {
|
|
506
|
-
this.client = new MemoryClient({ apiKey });
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
async initialize() {
|
|
510
|
-
const collection = await this.client.collections.create({
|
|
511
|
-
name: 'Chatbot Memory',
|
|
512
|
-
description: 'User interactions and preferences',
|
|
513
|
-
});
|
|
514
|
-
this.collectionId = collection.id;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
async chat(userMessage: string): Promise<string> {
|
|
518
|
-
// Add to working memory
|
|
519
|
-
await this.client.workingMemory.add({
|
|
520
|
-
role: 'user',
|
|
521
|
-
content: userMessage,
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
// Search relevant memories
|
|
525
|
-
const relevantMemories = await this.client.search({
|
|
526
|
-
query: userMessage,
|
|
527
|
-
collection_id: this.collectionId,
|
|
528
|
-
limit: 5,
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
// Generate response using reasoning
|
|
532
|
-
const response = await this.client.reason({
|
|
533
|
-
query: userMessage,
|
|
534
|
-
collection_id: this.collectionId,
|
|
535
|
-
provider: 'gemini',
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
// Store interaction
|
|
539
|
-
await this.client.memories.create({
|
|
540
|
-
collection_id: this.collectionId,
|
|
541
|
-
content: `User asked: "${userMessage}". Bot responded: "${response.answer}"`,
|
|
542
|
-
importance: 0.6,
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
// Add response to working memory
|
|
546
|
-
await this.client.workingMemory.add({
|
|
547
|
-
role: 'assistant',
|
|
548
|
-
content: response.answer,
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
return response.answer;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
async trainOnConversations() {
|
|
555
|
-
// Train RL agent to optimize memory management
|
|
556
|
-
await this.client.rl.trainMemoryManager({
|
|
557
|
-
collection_id: this.collectionId,
|
|
558
|
-
num_episodes: 100,
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// Usage
|
|
564
|
-
const bot = new SmartChatbot('hbx_...');
|
|
565
|
-
await bot.initialize();
|
|
566
|
-
|
|
567
|
-
const answer = await bot.chat('What did we discuss yesterday?');
|
|
568
|
-
console.log(answer);
|
|
569
|
-
|
|
570
|
-
await bot.trainOnConversations();
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
### Knowledge Graph Construction
|
|
574
|
-
|
|
575
|
-
```typescript
|
|
576
|
-
// Build temporal knowledge graph from documents
|
|
577
|
-
async function buildKnowledgeGraph(client: MemoryClient, collectionId: string) {
|
|
578
|
-
// Add entities and relationships
|
|
579
|
-
await client.temporal.addFact({
|
|
580
|
-
subject: 'GPT-5',
|
|
581
|
-
predicate: 'developed_by',
|
|
582
|
-
object: 'OpenAI',
|
|
583
|
-
valid_from: '2025-08-01',
|
|
584
|
-
confidence: 1.0,
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
await client.temporal.addFact({
|
|
588
|
-
subject: 'GPT-5',
|
|
589
|
-
predicate: 'is_a',
|
|
590
|
-
object: 'Large Language Model',
|
|
591
|
-
valid_from: '2025-08-01',
|
|
592
|
-
confidence: 1.0,
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
await client.temporal.addFact({
|
|
596
|
-
subject: 'OpenAI',
|
|
597
|
-
predicate: 'founded_in',
|
|
598
|
-
object: '2015',
|
|
599
|
-
valid_from: '2015-12-11',
|
|
600
|
-
confidence: 1.0,
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
// Query relationships
|
|
604
|
-
const facts = await client.temporal.queryFacts({
|
|
605
|
-
subject: 'GPT-5',
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
console.log(facts); // All facts about GPT-5
|
|
609
|
-
|
|
610
|
-
// Historical query
|
|
611
|
-
const snapshot = await client.temporal.pointInTime(
|
|
612
|
-
'2025-01-01T00:00:00Z',
|
|
613
|
-
'OpenAI'
|
|
614
|
-
);
|
|
615
|
-
|
|
616
|
-
console.log(snapshot); // OpenAI's state before GPT-5 release
|
|
617
|
-
}
|
|
618
|
-
```
|
|
619
|
-
|
|
620
|
-
## 🛡️ Error Handling
|
|
621
|
-
|
|
622
|
-
```typescript
|
|
623
|
-
import {
|
|
624
|
-
HebbrixError,
|
|
625
|
-
AuthenticationError,
|
|
626
|
-
ValidationError,
|
|
627
|
-
NotFoundError,
|
|
628
|
-
RateLimitError,
|
|
629
|
-
ServerError,
|
|
630
|
-
} from '@hebbrix/sdk';
|
|
631
|
-
|
|
632
|
-
try {
|
|
633
|
-
const memory = await client.memories.get('invalid_id');
|
|
634
|
-
} catch (error) {
|
|
635
|
-
if (error instanceof NotFoundError) {
|
|
636
|
-
console.log('Memory not found');
|
|
637
|
-
} else if (error instanceof AuthenticationError) {
|
|
638
|
-
console.log('Invalid API key');
|
|
639
|
-
} else if (error instanceof RateLimitError) {
|
|
640
|
-
console.log('Rate limit exceeded, retry after:', error.retryAfter);
|
|
641
|
-
} else if (error instanceof ValidationError) {
|
|
642
|
-
console.log('Validation errors:', error.errors);
|
|
643
|
-
} else if (error instanceof ServerError) {
|
|
644
|
-
console.log('Server error:', error.message);
|
|
645
|
-
} else if (error instanceof HebbrixError) {
|
|
646
|
-
console.log('API error:', error.statusCode, error.message);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
```
|
|
650
|
-
|
|
651
|
-
## ⚙️ Configuration
|
|
652
|
-
|
|
653
|
-
```typescript
|
|
654
|
-
const client = new MemoryClient({
|
|
655
|
-
// Required: API key
|
|
656
|
-
apiKey: 'hbx_...',
|
|
657
|
-
|
|
658
|
-
// Optional: Custom base URL (default: https://api.hebbrix.com)
|
|
659
|
-
baseUrl: 'https://api.yourdomain.com',
|
|
660
|
-
|
|
661
|
-
// Optional: Request timeout in milliseconds (default: 30000)
|
|
662
|
-
timeout: 60000,
|
|
663
|
-
});
|
|
664
|
-
```
|
|
665
|
-
|
|
666
|
-
## 🌐 Browser Usage
|
|
667
|
-
|
|
668
|
-
The SDK works in browsers with native Fetch API support:
|
|
669
|
-
|
|
670
|
-
```html
|
|
671
|
-
<script type="module">
|
|
672
|
-
import { MemoryClient } from 'https://cdn.jsdelivr.net/npm/hebbrix/dist/index.mjs';
|
|
673
|
-
|
|
674
|
-
const client = new MemoryClient({ apiKey: 'hbx_...' });
|
|
675
|
-
|
|
676
|
-
const results = await client.search({ query: 'test' });
|
|
677
|
-
console.log(results);
|
|
678
|
-
</script>
|
|
679
|
-
```
|
|
680
|
-
|
|
681
|
-
## 📊 Comparison with Competitors
|
|
682
|
-
|
|
683
|
-
| Feature | Hebbrix | Mem0 | Zep | Letta | Supermemory |
|
|
684
|
-
|---------|-----------|------|-----|-------|-------------|
|
|
685
|
-
| Reinforcement Learning | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
686
|
-
| Temporal Knowledge Graphs | ✅ | ❌ | ✅ | ❌ | ❌ |
|
|
687
|
-
| Procedural Memory | ✅ | ❌ | ❌ | ✅ | ❌ |
|
|
688
|
-
| Working Memory Buffer | ✅ | ❌ | ✅ | ✅ | ❌ |
|
|
689
|
-
| Memory Consolidation | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
690
|
-
| Hybrid Search | ✅ | ✅ | ✅ | ❌ | ✅ |
|
|
691
|
-
| Graph Search | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
692
|
-
| Self-Editing Tools | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
693
|
-
| World Model Planning | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
694
|
-
| Multi-LLM Support | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
695
|
-
|
|
696
|
-
**Hebbrix is the only memory API with:**
|
|
697
|
-
- RL-based memory optimization (Memory-R1 framework)
|
|
698
|
-
- Bi-temporal knowledge graphs
|
|
699
|
-
- Full memory consolidation pipeline
|
|
700
|
-
- Self-editing capabilities
|
|
701
|
-
- World model-based planning
|
|
702
|
-
|
|
703
|
-
## 🏗️ Development
|
|
704
|
-
|
|
705
|
-
```bash
|
|
706
|
-
# Install dependencies
|
|
707
|
-
npm install
|
|
708
|
-
|
|
709
|
-
# Build
|
|
710
|
-
npm run build
|
|
711
|
-
|
|
712
|
-
# Development mode with watch
|
|
713
|
-
npm run dev
|
|
714
|
-
|
|
715
|
-
# Run tests
|
|
716
|
-
npm test
|
|
717
|
-
|
|
718
|
-
# Lint code
|
|
719
|
-
npm run lint
|
|
720
|
-
|
|
721
|
-
# Format code
|
|
722
|
-
npm run format
|
|
723
|
-
```
|
|
724
|
-
|
|
725
|
-
## 📘 TypeScript Support
|
|
726
|
-
|
|
727
|
-
The SDK is written in TypeScript and includes complete type definitions:
|
|
728
|
-
|
|
729
|
-
```typescript
|
|
730
|
-
import type {
|
|
731
|
-
MemoryClient,
|
|
732
|
-
Memory,
|
|
733
|
-
Collection,
|
|
734
|
-
SearchResult,
|
|
735
|
-
ReasoningResponse,
|
|
736
|
-
} from '@hebbrix/sdk';
|
|
737
|
-
|
|
738
|
-
const client = new MemoryClient({ apiKey: 'hbx_...' });
|
|
739
|
-
|
|
740
|
-
// Full type inference
|
|
741
|
-
const memory: Memory = await client.memories.create({
|
|
742
|
-
collection_id: 'col_123',
|
|
743
|
-
content: 'Typed content',
|
|
744
|
-
});
|
|
745
|
-
|
|
746
|
-
// Type-safe search results
|
|
747
|
-
const results: SearchResult[] = await client.search({
|
|
748
|
-
query: 'test',
|
|
749
|
-
});
|
|
750
|
-
|
|
751
|
-
// Type-safe reasoning response
|
|
752
|
-
const answer: ReasoningResponse = await client.reason({
|
|
753
|
-
query: 'question',
|
|
754
|
-
});
|
|
755
|
-
```
|
|
80
|
+
The experimental World Model is intentionally not exported by this public SDK.
|
|
81
|
+
It remains withdrawn until a trained, versioned production model artifact and
|
|
82
|
+
an end-to-end public serving contract are available.
|
|
756
83
|
|
|
757
|
-
|
|
84
|
+
The authoritative account capability matrix is available from
|
|
85
|
+
`GET /v1/users/me/capabilities`.
|
|
758
86
|
|
|
759
|
-
|
|
760
|
-
- **API Reference**: https://api.hebbrix.com/docs
|
|
761
|
-
- **GitHub**: https://github.com/hebbrix/hebbrix
|
|
762
|
-
- **Examples**: https://github.com/hebbrix/examples
|
|
763
|
-
- **npm Package**: https://www.npmjs.com/package/hebbrix
|
|
87
|
+
## Release compatibility
|
|
764
88
|
|
|
765
|
-
|
|
89
|
+
The production API publishes exact build and artifact compatibility at
|
|
90
|
+
[`GET /v1/release`](https://api.hebbrix.com/v1/release). The public OpenAPI is
|
|
91
|
+
[`/openapi.json`](https://api.hebbrix.com/openapi.json).
|
|
766
92
|
|
|
767
|
-
|
|
93
|
+
- [Documentation](https://docs.hebbrix.com)
|
|
94
|
+
- [API reference](https://api.hebbrix.com/docs)
|
|
95
|
+
- [npm package](https://www.npmjs.com/package/hebbrix)
|
|
96
|
+
- [Support](https://www.hebbrix.com/contact)
|
|
768
97
|
|
|
769
|
-
|
|
98
|
+
## License
|
|
770
99
|
|
|
771
|
-
|
|
100
|
+
MIT. See `LICENSE` in the distribution.
|