hrr-memory 0.3.0 → 0.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/README.md +179 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# hrr-memory
|
|
2
|
+
|
|
3
|
+
**Structured fact recall for AI agents. Sub-2ms queries, zero dependencies.**
|
|
4
|
+
|
|
5
|
+
hrr-memory stores facts as `(subject, relation, object)` triples using Holographic Reduced Representations and retrieves them instantly — no vector database, no embeddings API. Includes built-in temporal awareness, conflict detection, and LLM-driven belief synthesis.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install hrr-memory
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Demo
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { HRRMemory } from 'hrr-memory';
|
|
17
|
+
|
|
18
|
+
const mem = new HRRMemory();
|
|
19
|
+
|
|
20
|
+
mem.store('alice', 'lives_in', 'paris');
|
|
21
|
+
mem.store('alice', 'works_at', 'acme');
|
|
22
|
+
mem.store('bob', 'lives_in', 'tokyo');
|
|
23
|
+
|
|
24
|
+
mem.query('alice', 'lives_in'); // { match: 'paris', confident: true }
|
|
25
|
+
mem.query('bob', 'lives_in'); // { match: 'tokyo', confident: true }
|
|
26
|
+
|
|
27
|
+
mem.querySubject('alice');
|
|
28
|
+
// [{ relation: 'lives_in', object: 'paris' },
|
|
29
|
+
// { relation: 'works_at', object: 'acme' }]
|
|
30
|
+
|
|
31
|
+
mem.ask("What is alice's timezone?");
|
|
32
|
+
// Direct lookup with stop-word stripping and natural language handling
|
|
33
|
+
|
|
34
|
+
mem.save('memory.json');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Why Not Just RAG?
|
|
38
|
+
|
|
39
|
+
| Query type | RAG | hrr-memory |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| "What is Alice's timezone?" | Returns paragraphs, maybe | Returns `cet` in <1ms |
|
|
42
|
+
| "Find notes about deployment" | Ranked chunks | Not suited — use RAG |
|
|
43
|
+
| "What changed about Alice?" | No built-in tracking | Conflict detection + timeline |
|
|
44
|
+
|
|
45
|
+
Use both. HRR for structured facts, RAG for semantic search.
|
|
46
|
+
|
|
47
|
+
## Observation Layer
|
|
48
|
+
|
|
49
|
+
Track how knowledge evolves over time. ObservationMemory wraps HRRMemory with a timeline, automatic conflict detection, and belief synthesis.
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { HRRMemory, ObservationMemory } from 'hrr-memory';
|
|
53
|
+
|
|
54
|
+
const hrr = new HRRMemory();
|
|
55
|
+
const mem = new ObservationMemory(hrr);
|
|
56
|
+
|
|
57
|
+
await mem.store('alice', 'interested_in', 'rust');
|
|
58
|
+
await mem.store('alice', 'interested_in', 'payments');
|
|
59
|
+
|
|
60
|
+
mem.flags();
|
|
61
|
+
// [{ subject: 'alice', oldObject: 'rust', newObject: 'payments', similarity: 0.05 }]
|
|
62
|
+
|
|
63
|
+
mem.history('alice');
|
|
64
|
+
// [{ ts: ..., op: 'store', object: 'rust' },
|
|
65
|
+
// { ts: ..., op: 'store', object: 'payments', conflict: { oldObject: 'rust' } }]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Conflict detection is algebraic — it compares HRR symbol vectors using cosine similarity. Low similarity between old and new values means a belief change, which gets flagged automatically.
|
|
69
|
+
|
|
70
|
+
## Point-in-Time Queries
|
|
71
|
+
|
|
72
|
+
Symbolic replay of the timeline. Fast and cheap — no HRR rebuild.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
mem.at(lastWeek).facts('alice', 'interested_in');
|
|
76
|
+
// ['rust'] — what we knew then
|
|
77
|
+
|
|
78
|
+
mem.at(Date.now()).facts('alice', 'interested_in');
|
|
79
|
+
// ['rust', 'payments'] — what we know now
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## LLM Consolidation
|
|
83
|
+
|
|
84
|
+
Flags accumulate until you consolidate them. The library builds the prompt; you bring the LLM.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const mem = new ObservationMemory(hrr, {
|
|
88
|
+
executor: (prompt) => callYourLLM(prompt),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// After conflicting stores...
|
|
92
|
+
const observations = await mem.consolidate();
|
|
93
|
+
// [{ subject: 'alice', observation: 'Interest shifted from Rust to payments',
|
|
94
|
+
// evidence: [...], confidence: 'high' }]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or skip the LLM and write observations directly:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
mem.addObservation({
|
|
101
|
+
subject: 'alice',
|
|
102
|
+
observation: 'Interest shifted from Rust to payments',
|
|
103
|
+
evidence: [{ ts: 1711234567890, triple: ['alice', 'interested_in', 'rust'] }],
|
|
104
|
+
confidence: 'high',
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Performance
|
|
109
|
+
|
|
110
|
+
| Facts | Accuracy | Query time | RAM |
|
|
111
|
+
|---|---|---|---|
|
|
112
|
+
| 100 | 100% | <1ms | 0.1 MB |
|
|
113
|
+
| 1,000 | 100% | 1.5ms | 4 MB |
|
|
114
|
+
| 10,000 | 100% | 1.8ms | 86 MB |
|
|
115
|
+
|
|
116
|
+
Auto-sharding kicks in at 25 facts per subject. Accuracy stays at 100% across shards.
|
|
117
|
+
|
|
118
|
+
## API
|
|
119
|
+
|
|
120
|
+
### HRRMemory (core)
|
|
121
|
+
|
|
122
|
+
| Method | Returns | Description |
|
|
123
|
+
|---|---|---|
|
|
124
|
+
| `store(s, r, o)` | `boolean` | Store a triple. Returns false if duplicate. |
|
|
125
|
+
| `forget(s, r, o)` | `boolean` | Remove a triple. |
|
|
126
|
+
| `query(s, r)` | `QueryResult` | Retrieve the object for a subject+relation pair. |
|
|
127
|
+
| `querySubject(s)` | `Fact[]` | All facts about a subject. |
|
|
128
|
+
| `search(r?, o?)` | `Triple[]` | Find triples by relation and/or object. |
|
|
129
|
+
| `ask(question)` | `AskResult` | Natural language query with stop-word handling. |
|
|
130
|
+
| `stats()` | `Stats` | Memory usage, bucket info, fact counts. |
|
|
131
|
+
| `save(path)` | `void` | Persist to JSON file. |
|
|
132
|
+
| `HRRMemory.load(path)` | `HRRMemory` | Load from JSON file. |
|
|
133
|
+
|
|
134
|
+
### ObservationMemory (observation layer)
|
|
135
|
+
|
|
136
|
+
All HRRMemory methods are delegated (query, querySubject, search, ask, stats).
|
|
137
|
+
|
|
138
|
+
| Method | Returns | Description |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `await store(s, r, o)` | `boolean` | Store with timeline recording and conflict detection. |
|
|
141
|
+
| `await forget(s, r, o)` | `boolean` | Forget with timeline recording. |
|
|
142
|
+
| `history(s, r?)` | `TimelineEntry[]` | Temporal history, oldest first. |
|
|
143
|
+
| `at(ts).facts(s, r?)` | `string[]` | Point-in-time symbolic query. |
|
|
144
|
+
| `flags()` | `ConflictFlag[]` | Unflushed conflict flags. |
|
|
145
|
+
| `clearFlags(subject)` | `void` | Clear flags for a subject. |
|
|
146
|
+
| `observations(s?)` | `Observation[]` | Synthesized beliefs, newest first. |
|
|
147
|
+
| `addObservation(obs)` | `Observation` | Store observation directly (no LLM). |
|
|
148
|
+
| `await consolidate()` | `Observation[]` | LLM-driven synthesis of flagged changes. |
|
|
149
|
+
| `save(hrrPath, obsPath)` | `void` | Persist both stores. |
|
|
150
|
+
| `ObservationMemory.load(hrrPath, obsPath, opts)` | `ObservationMemory` | Load both stores. |
|
|
151
|
+
|
|
152
|
+
### Standalone Components
|
|
153
|
+
|
|
154
|
+
Each layer works independently:
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import { Timeline, ConflictDetector, defaultPrompt } from 'hrr-memory';
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## TypeScript
|
|
161
|
+
|
|
162
|
+
Full type definitions included. All interfaces and classes are exported from `types/index.d.ts`.
|
|
163
|
+
|
|
164
|
+
## Ecosystem
|
|
165
|
+
|
|
166
|
+
- **[openclaw-hrr-memory](https://github.com/Joncik91/openclaw-hrr-memory)** — OpenClaw plugin for agent fact recall
|
|
167
|
+
|
|
168
|
+
## Migration from hrr-memory-obs
|
|
169
|
+
|
|
170
|
+
The `hrr-memory-obs` package is deprecated. All its exports are now part of `hrr-memory`:
|
|
171
|
+
|
|
172
|
+
```diff
|
|
173
|
+
- import { ObservationMemory } from 'hrr-memory-obs';
|
|
174
|
+
+ import { ObservationMemory } from 'hrr-memory';
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hrr-memory",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Holographic Reduced Representations for structured agent memory. Structured facts, temporal awareness, conflict detection, and belief synthesis. Zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|