hrr-memory 0.3.2 → 0.4.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/types/index.d.ts CHANGED
@@ -1,257 +1,257 @@
1
- // ── Core types ───────────────────────────────────────
2
-
3
- export interface QueryResult {
4
- match: string | null;
5
- score: number;
6
- confident: boolean;
7
- bucket: string | null;
8
- }
9
-
10
- export interface Fact {
11
- relation: string;
12
- object: string;
13
- }
14
-
15
- export interface Triple {
16
- subject: string;
17
- relation: string;
18
- object: string;
19
- }
20
-
21
- export interface DirectAskResult {
22
- type: 'direct';
23
- match: string;
24
- score: number;
25
- confident: boolean;
26
- subject: string;
27
- relation: string;
28
- bucket: string | null;
29
- }
30
-
31
- export interface SubjectAskResult {
32
- type: 'subject';
33
- subject: string;
34
- facts: Fact[];
35
- }
36
-
37
- export interface SearchAskResult {
38
- type: 'search';
39
- term: string;
40
- results: Triple[];
41
- }
42
-
43
- export interface MissAskResult {
44
- type: 'miss';
45
- query: string;
46
- }
47
-
48
- export type AskResult = DirectAskResult | SubjectAskResult | SearchAskResult | MissAskResult;
49
-
50
- export interface BucketStats {
51
- name: string;
52
- facts: number;
53
- full: boolean;
54
- }
55
-
56
- export interface Stats {
57
- dimensions: number;
58
- maxBucketSize: number;
59
- symbols: number;
60
- buckets: number;
61
- subjects: number;
62
- totalFacts: number;
63
- ramBytes: number;
64
- ramMB: number;
65
- perBucket: BucketStats[];
66
- }
67
-
68
- export interface SerializedMemory {
69
- version: number;
70
- d: number;
71
- symbols: Record<string, number[]>;
72
- buckets: Record<string, unknown>;
73
- routing: Record<string, string[]>;
74
- }
75
-
76
- export class HRRMemory {
77
- constructor(dimensions?: number);
78
-
79
- store(subject: string, relation: string, object: string): boolean;
80
- forget(subject: string, relation: string, object: string): boolean;
81
- query(subject: string, relation: string): QueryResult;
82
- querySubject(subject: string): Fact[];
83
- search(relation: string | null, object: string | null): Triple[];
84
- ask(question: string): AskResult;
85
- stats(): Stats;
86
-
87
- save(filePath: string): void;
88
- static load(filePath: string, dimensions?: number): HRRMemory;
89
-
90
- toJSON(): SerializedMemory;
91
- static fromJSON(data: SerializedMemory): HRRMemory;
92
- }
93
-
94
- export class SymbolTable {
95
- constructor(dimensions?: number);
96
- get(name: string): Float32Array;
97
- has(name: string): boolean;
98
- readonly size: number;
99
- readonly bytes: number;
100
- nearest(
101
- vec: Float32Array,
102
- candidates?: Map<string, Float32Array> | null,
103
- topK?: number
104
- ): { name: string; score: number } | { name: string; score: number }[] | null;
105
- toJSON(): Record<string, number[]>;
106
- static fromJSON(data: Record<string, number[]>, dimensions: number): SymbolTable;
107
- }
108
-
109
- export class Bucket {
110
- constructor(name: string, dimensions?: number);
111
- readonly name: string;
112
- readonly count: number;
113
- readonly isFull: boolean;
114
- storeVector(association: Float32Array, triple: Triple): void;
115
- rebuild(symbols: SymbolTable): void;
116
- toJSON(): unknown;
117
- static fromJSON(data: unknown, dimensions: number): Bucket;
118
- }
119
-
120
- export function bind(a: Float32Array, b: Float32Array): Float32Array;
121
- export function unbind(key: Float32Array, memory: Float32Array): Float32Array;
122
- export function similarity(a: Float32Array, b: Float32Array): number;
123
- export function randomVector(dimensions: number): Float32Array;
124
- export function normalize(v: Float32Array): Float32Array;
125
-
126
- // ── Observation layer types ───��──────────────────────
127
-
128
- export interface TimelineEntry {
129
- ts: number;
130
- subject: string;
131
- relation: string;
132
- object: string;
133
- op: 'store' | 'forget';
134
- conflict?: { oldObject: string; similarity: number };
135
- }
136
-
137
- export interface ConflictFlag {
138
- ts: number;
139
- subject: string;
140
- relation: string;
141
- newObject: string;
142
- oldObject: string;
143
- similarity: number;
144
- }
145
-
146
- export interface Observation {
147
- id: string;
148
- subject: string;
149
- observation: string;
150
- evidence: Array<{ ts: number; triple: [string, string, string] }>;
151
- confidence: 'high' | 'medium' | 'low';
152
- supersedes: string[];
153
- createdAt: number;
154
- }
155
-
156
- export interface ConsolidationInput {
157
- entries: TimelineEntry[];
158
- flags: ConflictFlag[];
159
- existingObservations: Array<{
160
- id: string;
161
- subject: string;
162
- observation: string;
163
- confidence: string;
164
- }>;
165
- }
166
-
167
- export interface ObservationMemoryOptions {
168
- executor?: (prompt: string) => Promise<string>;
169
- autoConsolidateAfter?: number | null;
170
- promptFn?: (input: ConsolidationInput) => string;
171
- conflictThreshold?: number;
172
- }
173
-
174
- export interface SerializedObservationMemory {
175
- version: number;
176
- meta: {
177
- createdAt: number;
178
- lastConsolidation: number | null;
179
- totalStores: number;
180
- totalForgets: number;
181
- totalConsolidations: number;
182
- };
183
- timeline: TimelineEntry[];
184
- observations: Observation[];
185
- flags: ConflictFlag[];
186
- obsCounter: number;
187
- }
188
-
189
- export class Timeline {
190
- constructor();
191
- append(entry: TimelineEntry): void;
192
- history(subject: string, relation?: string): TimelineEntry[];
193
- all(): TimelineEntry[];
194
- readonly length: number;
195
- at(ts: number): SymbolicProxy;
196
- toJSON(): TimelineEntry[];
197
- static fromJSON(data: TimelineEntry[]): Timeline;
198
- }
199
-
200
- export class SymbolicProxy {
201
- constructor(entries: TimelineEntry[], ts: number);
202
- facts(subject: string, relation?: string): string[];
203
- }
204
-
205
- export class ConflictDetector {
206
- constructor(hrr: HRRMemory, threshold?: number);
207
- track(subject: string, relation: string): void;
208
- check(subject: string, relation: string, object: string, ts?: number): ConflictFlag | null;
209
- }
210
-
211
- export class ObservationParseError extends Error {
212
- constructor(message: string, raw: string);
213
- readonly name: 'ObservationParseError';
214
- readonly raw: string;
215
- }
216
-
217
- export class ObservationMemory {
218
- constructor(hrr: HRRMemory, options?: ObservationMemoryOptions);
219
-
220
- // Delegated to HRRMemory
221
- query(subject: string, relation: string): QueryResult;
222
- querySubject(subject: string): Fact[];
223
- search(relation: string | null, object: string | null): Triple[];
224
- ask(question: string): AskResult;
225
- stats(): Stats;
226
-
227
- // Store/forget with observation tracking
228
- store(subject: string, relation: string, object: string): Promise<boolean>;
229
- forget(subject: string, relation: string, object: string): Promise<boolean>;
230
-
231
- // Timeline
232
- history(subject: string, relation?: string): TimelineEntry[];
233
- at(ts: number): SymbolicProxy;
234
-
235
- // Conflict flags
236
- flags(): ConflictFlag[];
237
- clearFlags(subject: string): void;
238
-
239
- // Observations
240
- observations(subject?: string): Observation[];
241
- addObservation(obs: {
242
- subject: string;
243
- observation: string;
244
- evidence: Array<{ ts: number; triple: [string, string, string] }>;
245
- confidence: 'high' | 'medium' | 'low';
246
- supersedes?: string[];
247
- }): Observation;
248
- consolidate(): Promise<Observation[]>;
249
-
250
- // Persistence
251
- save(hrrPath: string, obsPath: string): void;
252
- static load(hrrPath: string, obsPath: string, options?: ObservationMemoryOptions): ObservationMemory;
253
- toJSON(): SerializedObservationMemory;
254
- static fromJSON(hrr: HRRMemory, data: SerializedObservationMemory, options?: ObservationMemoryOptions): ObservationMemory;
255
- }
256
-
257
- export function defaultPrompt(input: ConsolidationInput): string;
1
+ // ── Core types ───────────────────────────────────────
2
+
3
+ export interface QueryResult {
4
+ match: string | null;
5
+ score: number;
6
+ confident: boolean;
7
+ bucket: string | null;
8
+ }
9
+
10
+ export interface Fact {
11
+ relation: string;
12
+ object: string;
13
+ }
14
+
15
+ export interface Triple {
16
+ subject: string;
17
+ relation: string;
18
+ object: string;
19
+ }
20
+
21
+ export interface DirectAskResult {
22
+ type: 'direct';
23
+ match: string;
24
+ score: number;
25
+ confident: boolean;
26
+ subject: string;
27
+ relation: string;
28
+ bucket: string | null;
29
+ }
30
+
31
+ export interface SubjectAskResult {
32
+ type: 'subject';
33
+ subject: string;
34
+ facts: Fact[];
35
+ }
36
+
37
+ export interface SearchAskResult {
38
+ type: 'search';
39
+ term: string;
40
+ results: Triple[];
41
+ }
42
+
43
+ export interface MissAskResult {
44
+ type: 'miss';
45
+ query: string;
46
+ }
47
+
48
+ export type AskResult = DirectAskResult | SubjectAskResult | SearchAskResult | MissAskResult;
49
+
50
+ export interface BucketStats {
51
+ name: string;
52
+ facts: number;
53
+ full: boolean;
54
+ }
55
+
56
+ export interface Stats {
57
+ dimensions: number;
58
+ maxBucketSize: number;
59
+ symbols: number;
60
+ buckets: number;
61
+ subjects: number;
62
+ totalFacts: number;
63
+ ramBytes: number;
64
+ ramMB: number;
65
+ perBucket: BucketStats[];
66
+ }
67
+
68
+ export interface SerializedMemory {
69
+ version: number;
70
+ d: number;
71
+ symbols: Record<string, number[]>;
72
+ buckets: Record<string, unknown>;
73
+ routing: Record<string, string[]>;
74
+ }
75
+
76
+ export class HRRMemory {
77
+ constructor(dimensions?: number);
78
+
79
+ store(subject: string, relation: string, object: string): boolean;
80
+ forget(subject: string, relation: string, object: string): boolean;
81
+ query(subject: string, relation: string): QueryResult;
82
+ querySubject(subject: string): Fact[];
83
+ search(relation: string | null, object: string | null): Triple[];
84
+ ask(question: string): AskResult;
85
+ stats(): Stats;
86
+
87
+ save(filePath: string): void;
88
+ static load(filePath: string, dimensions?: number): HRRMemory;
89
+
90
+ toJSON(): SerializedMemory;
91
+ static fromJSON(data: SerializedMemory): HRRMemory;
92
+ }
93
+
94
+ export class SymbolTable {
95
+ constructor(dimensions?: number);
96
+ get(name: string): Float32Array;
97
+ has(name: string): boolean;
98
+ readonly size: number;
99
+ readonly bytes: number;
100
+ nearest(
101
+ vec: Float32Array,
102
+ candidates?: Map<string, Float32Array> | null,
103
+ topK?: number
104
+ ): { name: string; score: number } | { name: string; score: number }[] | null;
105
+ toJSON(): Record<string, number[]>;
106
+ static fromJSON(data: Record<string, number[]>, dimensions: number): SymbolTable;
107
+ }
108
+
109
+ export class Bucket {
110
+ constructor(name: string, dimensions?: number);
111
+ readonly name: string;
112
+ readonly count: number;
113
+ readonly isFull: boolean;
114
+ storeVector(association: Float32Array, triple: Triple): void;
115
+ rebuild(symbols: SymbolTable): void;
116
+ toJSON(): unknown;
117
+ static fromJSON(data: unknown, dimensions: number): Bucket;
118
+ }
119
+
120
+ export function bind(a: Float32Array, b: Float32Array): Float32Array;
121
+ export function unbind(key: Float32Array, memory: Float32Array): Float32Array;
122
+ export function similarity(a: Float32Array, b: Float32Array): number;
123
+ export function randomVector(dimensions: number): Float32Array;
124
+ export function normalize(v: Float32Array): Float32Array;
125
+
126
+ // ── Observation layer types ───��──────────────────────
127
+
128
+ export interface TimelineEntry {
129
+ ts: number;
130
+ subject: string;
131
+ relation: string;
132
+ object: string;
133
+ op: 'store' | 'forget';
134
+ conflict?: { oldObject: string; similarity: number };
135
+ }
136
+
137
+ export interface ConflictFlag {
138
+ ts: number;
139
+ subject: string;
140
+ relation: string;
141
+ newObject: string;
142
+ oldObject: string;
143
+ similarity: number;
144
+ }
145
+
146
+ export interface Observation {
147
+ id: string;
148
+ subject: string;
149
+ observation: string;
150
+ evidence: Array<{ ts: number; triple: [string, string, string] }>;
151
+ confidence: 'high' | 'medium' | 'low';
152
+ supersedes: string[];
153
+ createdAt: number;
154
+ }
155
+
156
+ export interface ConsolidationInput {
157
+ entries: TimelineEntry[];
158
+ flags: ConflictFlag[];
159
+ existingObservations: Array<{
160
+ id: string;
161
+ subject: string;
162
+ observation: string;
163
+ confidence: string;
164
+ }>;
165
+ }
166
+
167
+ export interface ObservationMemoryOptions {
168
+ executor?: (prompt: string) => Promise<string>;
169
+ autoConsolidateAfter?: number | null;
170
+ promptFn?: (input: ConsolidationInput) => string;
171
+ conflictThreshold?: number;
172
+ }
173
+
174
+ export interface SerializedObservationMemory {
175
+ version: number;
176
+ meta: {
177
+ createdAt: number;
178
+ lastConsolidation: number | null;
179
+ totalStores: number;
180
+ totalForgets: number;
181
+ totalConsolidations: number;
182
+ };
183
+ timeline: TimelineEntry[];
184
+ observations: Observation[];
185
+ flags: ConflictFlag[];
186
+ obsCounter: number;
187
+ }
188
+
189
+ export class Timeline {
190
+ constructor();
191
+ append(entry: TimelineEntry): void;
192
+ history(subject: string, relation?: string): TimelineEntry[];
193
+ all(): TimelineEntry[];
194
+ readonly length: number;
195
+ at(ts: number): SymbolicProxy;
196
+ toJSON(): TimelineEntry[];
197
+ static fromJSON(data: TimelineEntry[]): Timeline;
198
+ }
199
+
200
+ export class SymbolicProxy {
201
+ constructor(entries: TimelineEntry[], ts: number);
202
+ facts(subject: string, relation?: string): string[];
203
+ }
204
+
205
+ export class ConflictDetector {
206
+ constructor(hrr: HRRMemory, threshold?: number);
207
+ track(subject: string, relation: string): void;
208
+ check(subject: string, relation: string, object: string, ts?: number): ConflictFlag | null;
209
+ }
210
+
211
+ export class ObservationParseError extends Error {
212
+ constructor(message: string, raw: string);
213
+ readonly name: 'ObservationParseError';
214
+ readonly raw: string;
215
+ }
216
+
217
+ export class ObservationMemory {
218
+ constructor(hrr: HRRMemory, options?: ObservationMemoryOptions);
219
+
220
+ // Delegated to HRRMemory
221
+ query(subject: string, relation: string): QueryResult;
222
+ querySubject(subject: string): Fact[];
223
+ search(relation: string | null, object: string | null): Triple[];
224
+ ask(question: string): AskResult;
225
+ stats(): Stats;
226
+
227
+ // Store/forget with observation tracking
228
+ store(subject: string, relation: string, object: string): Promise<boolean>;
229
+ forget(subject: string, relation: string, object: string): Promise<boolean>;
230
+
231
+ // Timeline
232
+ history(subject: string, relation?: string): TimelineEntry[];
233
+ at(ts: number): SymbolicProxy;
234
+
235
+ // Conflict flags
236
+ flags(): ConflictFlag[];
237
+ clearFlags(subject: string): void;
238
+
239
+ // Observations
240
+ observations(subject?: string): Observation[];
241
+ addObservation(obs: {
242
+ subject: string;
243
+ observation: string;
244
+ evidence: Array<{ ts: number; triple: [string, string, string] }>;
245
+ confidence: 'high' | 'medium' | 'low';
246
+ supersedes?: string[];
247
+ }): Observation;
248
+ consolidate(): Promise<Observation[]>;
249
+
250
+ // Persistence
251
+ save(hrrPath: string, obsPath: string): void;
252
+ static load(hrrPath: string, obsPath: string, options?: ObservationMemoryOptions): ObservationMemory;
253
+ toJSON(): SerializedObservationMemory;
254
+ static fromJSON(hrr: HRRMemory, data: SerializedObservationMemory, options?: ObservationMemoryOptions): ObservationMemory;
255
+ }
256
+
257
+ export function defaultPrompt(input: ConsolidationInput): string;