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