infinitydb 1.0.0 → 1.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/LICENSE +118 -118
- package/README.md +186 -137
- package/index.d.ts +45 -43
- package/index.js +829 -330
- package/package.json +39 -35
package/LICENSE
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work.
|
|
38
|
-
|
|
39
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
-
form, that is based on (or derived from) the Work and for which the
|
|
41
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
-
of this License, Derivative Works shall not include works that remain
|
|
44
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
-
the Work and Derivative Works thereof.
|
|
46
|
-
|
|
47
|
-
"Contribution" shall mean any work of authorship, including
|
|
48
|
-
the original version of the Work and any modifications or additions
|
|
49
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
50
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
51
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
52
|
-
the copyright owner.
|
|
53
|
-
|
|
54
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
-
Work and such Derivative Works in Source or Object form.
|
|
60
|
-
|
|
61
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
-
(except as stated in this section) patent license to make, have made,
|
|
65
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
66
|
-
where such license applies only to those patent claims licensable
|
|
67
|
-
by such Contributor that are necessarily infringed by their
|
|
68
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
69
|
-
with the Work to which such Contribution(s) was submitted.
|
|
70
|
-
|
|
71
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
72
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
73
|
-
modifications, and in Source or Object form, provided that You
|
|
74
|
-
meet the following conditions:
|
|
75
|
-
|
|
76
|
-
(a) You must give any other recipients of the Work or
|
|
77
|
-
Derivative Works a copy of this License; and
|
|
78
|
-
|
|
79
|
-
(b) You must cause any modified files to carry prominent notices
|
|
80
|
-
stating that You changed the files; and
|
|
81
|
-
|
|
82
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
83
|
-
that You distribute, all copyright, patent, trademark, and
|
|
84
|
-
attribution notices from the Source form of the Work; and
|
|
85
|
-
|
|
86
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
87
|
-
distribution, then any Derivative Works that You distribute must
|
|
88
|
-
include a readable copy of the attribution notices contained
|
|
89
|
-
within such NOTICE file.
|
|
90
|
-
|
|
91
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
92
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
93
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
94
|
-
this License, without any additional terms or conditions.
|
|
95
|
-
|
|
96
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
97
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
98
|
-
except as required for reasonable and customary use in describing the
|
|
99
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
100
|
-
|
|
101
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
102
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
103
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
104
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
105
|
-
implied, including, without limitation, any warranties or conditions
|
|
106
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
107
|
-
PARTICULAR PURPOSE.
|
|
108
|
-
|
|
109
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
110
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
111
|
-
shall any Contributor be liable to You for damages, including any
|
|
112
|
-
direct, indirect, special, incidental, or exemplary damages of any
|
|
113
|
-
character arising as a result of this License or out of the use or
|
|
114
|
-
inability to use the Work.
|
|
115
|
-
|
|
116
|
-
END OF TERMS AND CONDITIONS
|
|
117
|
-
|
|
118
|
-
Copyright (c) 2026 InfinityDB AI Contributors
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including
|
|
48
|
+
the original version of the Work and any modifications or additions
|
|
49
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
50
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
51
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
52
|
+
the copyright owner.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
(except as stated in this section) patent license to make, have made,
|
|
65
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
66
|
+
where such license applies only to those patent claims licensable
|
|
67
|
+
by such Contributor that are necessarily infringed by their
|
|
68
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
69
|
+
with the Work to which such Contribution(s) was submitted.
|
|
70
|
+
|
|
71
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
72
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
73
|
+
modifications, and in Source or Object form, provided that You
|
|
74
|
+
meet the following conditions:
|
|
75
|
+
|
|
76
|
+
(a) You must give any other recipients of the Work or
|
|
77
|
+
Derivative Works a copy of this License; and
|
|
78
|
+
|
|
79
|
+
(b) You must cause any modified files to carry prominent notices
|
|
80
|
+
stating that You changed the files; and
|
|
81
|
+
|
|
82
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
83
|
+
that You distribute, all copyright, patent, trademark, and
|
|
84
|
+
attribution notices from the Source form of the Work; and
|
|
85
|
+
|
|
86
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
87
|
+
distribution, then any Derivative Works that You distribute must
|
|
88
|
+
include a readable copy of the attribution notices contained
|
|
89
|
+
within such NOTICE file.
|
|
90
|
+
|
|
91
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
92
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
93
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
94
|
+
this License, without any additional terms or conditions.
|
|
95
|
+
|
|
96
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
97
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
98
|
+
except as required for reasonable and customary use in describing the
|
|
99
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
100
|
+
|
|
101
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
102
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
103
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
104
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
105
|
+
implied, including, without limitation, any warranties or conditions
|
|
106
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
107
|
+
PARTICULAR PURPOSE.
|
|
108
|
+
|
|
109
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
110
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
111
|
+
shall any Contributor be liable to You for damages, including any
|
|
112
|
+
direct, indirect, special, incidental, or exemplary damages of any
|
|
113
|
+
character arising as a result of this License or out of the use or
|
|
114
|
+
inability to use the Work.
|
|
115
|
+
|
|
116
|
+
END OF TERMS AND CONDITIONS
|
|
117
|
+
|
|
118
|
+
Copyright (c) 2026 InfinityDB AI Contributors
|
|
119
119
|
|
package/README.md
CHANGED
|
@@ -1,137 +1,186 @@
|
|
|
1
|
-
# InfinityDB
|
|
2
|
-
|
|
3
|
-
> High-Performance Neurosymbolic Agent Memory Engine for JavaScript and TypeScript.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/infinitydb)
|
|
6
|
-
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
|
-
[](https://www.typescriptlang.org/)
|
|
8
|
-
|
|
9
|
-
InfinityDB gives AI agents long-term neurosymbolic memory with deterministic recall,
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install infinitydb
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
yarn add infinitydb
|
|
21
|
-
# or
|
|
22
|
-
pnpm add infinitydb
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Quick Start
|
|
28
|
-
|
|
29
|
-
### 1. Ingestion and Causal Recall
|
|
30
|
-
|
|
31
|
-
```javascript
|
|
32
|
-
const { InfinityDB } = require("infinitydb");
|
|
33
|
-
// Or in TypeScript:
|
|
34
|
-
// import { InfinityDB } from "infinitydb";
|
|
35
|
-
|
|
36
|
-
const db = new InfinityDB();
|
|
37
|
-
|
|
38
|
-
// Ingest agent dialogue / user interactions (L0 Log -> L1 Atomic Facts -> L2 Episode Graph)
|
|
39
|
-
const logId = db.add(
|
|
40
|
-
"Sarah prefers TypeScript over JavaScript because of strict static typing. Her project budget is $15,000.",
|
|
41
|
-
"usr_sarah"
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Recall relevant memory with causal facts, policy checks, and proof chains
|
|
45
|
-
const memory = db.recall("what language does Sarah prefer?", { userId: "usr_sarah" });
|
|
46
|
-
|
|
47
|
-
console.log("Latency:", memory.latencyMs, "ms");
|
|
48
|
-
console.log("Recalled Facts:", memory.results);
|
|
49
|
-
console.log("Causal Graph:", memory.causalGraph);
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 2. Dynamic Persona & Automatic Conflict Resolution
|
|
53
|
-
|
|
54
|
-
```javascript
|
|
55
|
-
// Initial preference
|
|
56
|
-
db.add("I prefer TypeScript for backend APIs", "usr_sarah");
|
|
57
|
-
console.log(db.getPersona("usr_sarah"));
|
|
58
|
-
// => { preference: ["TypeScript for backend APIs"] }
|
|
59
|
-
|
|
60
|
-
// User changes their mind later:
|
|
61
|
-
db.add("I now prefer Rust for mission-critical core engines", "usr_sarah");
|
|
62
|
-
|
|
63
|
-
// Conflicting older preference is automatically reconciled
|
|
64
|
-
console.log(db.getPersona("usr_sarah"));
|
|
65
|
-
// => { preference: ["Rust for mission-critical core engines"] }
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### 3.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```javascript
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
1
|
+
# InfinityDB
|
|
2
|
+
|
|
3
|
+
> High-Performance Neurosymbolic Agent Memory Engine for JavaScript and TypeScript.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/infinitydb)
|
|
6
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
InfinityDB gives AI agents long-term neurosymbolic memory with deterministic recall, dynamic persona conflict resolution, and cryptographic SHA-256 audit proofs. Recall and write latency depend on dataset size, hardware, storage configuration, and workload.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install infinitydb
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
yarn add infinitydb
|
|
21
|
+
# or
|
|
22
|
+
pnpm add infinitydb
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### 1. Ingestion and Causal Recall
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
const { InfinityDB } = require("infinitydb");
|
|
33
|
+
// Or in TypeScript:
|
|
34
|
+
// import { InfinityDB } from "infinitydb";
|
|
35
|
+
|
|
36
|
+
const db = new InfinityDB();
|
|
37
|
+
|
|
38
|
+
// Ingest agent dialogue / user interactions (L0 Log -> L1 Atomic Facts -> L2 Episode Graph)
|
|
39
|
+
const logId = db.add(
|
|
40
|
+
"Sarah prefers TypeScript over JavaScript because of strict static typing. Her project budget is $15,000.",
|
|
41
|
+
"usr_sarah"
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Recall relevant memory with causal facts, policy checks, and proof chains
|
|
45
|
+
const memory = db.recall("what language does Sarah prefer?", { userId: "usr_sarah" });
|
|
46
|
+
|
|
47
|
+
console.log("Latency:", memory.latencyMs, "ms");
|
|
48
|
+
console.log("Recalled Facts:", memory.results);
|
|
49
|
+
console.log("Causal Graph:", memory.causalGraph);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Dynamic Persona & Automatic Conflict Resolution
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
// Initial preference
|
|
56
|
+
db.add("I prefer TypeScript for backend APIs", "usr_sarah");
|
|
57
|
+
console.log(db.getPersona("usr_sarah"));
|
|
58
|
+
// => { preference: ["TypeScript for backend APIs"] }
|
|
59
|
+
|
|
60
|
+
// User changes their mind later:
|
|
61
|
+
db.add("I now prefer Rust for mission-critical core engines", "usr_sarah");
|
|
62
|
+
|
|
63
|
+
// Conflicting older preference is automatically reconciled
|
|
64
|
+
console.log(db.getPersona("usr_sarah"));
|
|
65
|
+
// => { preference: ["Rust for mission-critical core engines"] }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Explicit temporal supersession and historical recall
|
|
69
|
+
|
|
70
|
+
When a user explicitly replaces a fact, preserve the original fact and its provenance while marking the newer fact as its successor:
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
const oldLog = db.add("I prefer Python for data work.", "usr_sarah");
|
|
74
|
+
const oldFact = Array.from(db.atoms.values()).find(a => a.sourceId === oldLog);
|
|
75
|
+
const cutoff = oldFact.ts + 0.001;
|
|
76
|
+
|
|
77
|
+
const newLog = db.add("I prefer Rust for systems work.", "usr_sarah");
|
|
78
|
+
const newFact = Array.from(db.atoms.values()).find(a => a.sourceId === newLog);
|
|
79
|
+
|
|
80
|
+
db.supersedeFact(oldFact.id, newFact.id, "usr_sarah");
|
|
81
|
+
|
|
82
|
+
// Current recall returns the active fact; historical recall can still see the old one.
|
|
83
|
+
db.recall("Python", { userId: "usr_sarah" }).results; // []
|
|
84
|
+
db.recall("Python", { userId: "usr_sarah", asOf: cutoff }).results;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Supersession is explicit; the SDK does not infer semantic contradictions. Both facts and their proof records remain stored. Relations are tenant-scoped and cycle-checked. SQLite mode persists relations across reopen.
|
|
88
|
+
|
|
89
|
+
### 4. Cryptographic Audit Proofs (SHA-256 Chain)
|
|
90
|
+
|
|
91
|
+
Every atomic fact is hashed and anchored into an immutable tamper-evident proof chain:
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
const atomId = memory.results[0].id;
|
|
95
|
+
const proof = db.getProof(atomId);
|
|
96
|
+
|
|
97
|
+
console.log(proof);
|
|
98
|
+
// {
|
|
99
|
+
// atomId: "ATOM_...",
|
|
100
|
+
// hash: "a4f8c2...",
|
|
101
|
+
// verified: true,
|
|
102
|
+
// timestamp: 1729100000000
|
|
103
|
+
// }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 5. Enterprise Policies & Guardrails
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
// Register a global policy or a tenant-scoped policy
|
|
110
|
+
db.addPolicy("Never log plaintext passwords or API keys", "security", 2.0);
|
|
111
|
+
db.addPolicy("Tenant-specific retention rule", "retention", 1.5, "usr_sarah");
|
|
112
|
+
|
|
113
|
+
const recall = db.recall("database credentials", { userId: "usr_sarah" });
|
|
114
|
+
console.log(recall.policies); // Global + usr_sarah policies only
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 6. Tenant data deletion
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
// Remove this tenant’s stored logs, facts, episodes, and persona state
|
|
121
|
+
const result = db.deleteUser("usr_sarah");
|
|
122
|
+
console.log(result); // Per-layer deletion counts
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
This API reports database deletion results only; it does not certify legal or regulatory compliance.
|
|
126
|
+
|
|
127
|
+
### 7. Backwards-Compatible Key-Value Store
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
db.put("session:123", "active");
|
|
131
|
+
const val = db.get("session:123");
|
|
132
|
+
db.delete("session:123");
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
### 8. Durable SQLite storage (Node.js)
|
|
137
|
+
|
|
138
|
+
Install the package dependencies, then provide a database path to enable durable storage:
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
const { InfinityDB } = require("infinitydb");
|
|
142
|
+
const db = new InfinityDB({ dbPath: "./data/infinitydb.sqlite" });
|
|
143
|
+
|
|
144
|
+
db.add("I prefer SQLite for durable memory.", "user_123");
|
|
145
|
+
console.log(db.recall("SQLite", { userId: "user_123" }).results);
|
|
146
|
+
|
|
147
|
+
// Close cleanly before process shutdown. Reopen with the same dbPath to recover state.
|
|
148
|
+
db.close();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
When `dbPath` is omitted, the SDK remains in-memory for backwards compatibility.
|
|
152
|
+
The SQLite-backed mode uses WAL, FULL synchronous commits, a busy timeout, and normalized
|
|
153
|
+
L0/L1/L2/L3/L4/L6 tables with transactional row upserts. Existing v1 JSON-snapshot databases
|
|
154
|
+
are migrated transactionally to schema v2 on first open. SDK instances refresh their view
|
|
155
|
+
from SQLite before public reads and mutations, and sequence allocation is serialized by a
|
|
156
|
+
SQLite write transaction. This is not yet a guarantee of serializable concurrent read-modify-write
|
|
157
|
+
operations across processes; use a single writer until that coordination layer is added.
|
|
158
|
+
Back up the database using SQLite's backup facilities.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Architecture (L0 – L6 Brain)
|
|
163
|
+
|
|
164
|
+
| Layer | Component | Function |
|
|
165
|
+
| :--- | :--- | :--- |
|
|
166
|
+
| **L0** | Raw Interaction Store | Append-only raw interaction logs |
|
|
167
|
+
| **L1** | Atomic Fact Extractor | Deterministic, zero-hallucination semantic extraction |
|
|
168
|
+
| **L2** | Episodic Graph | Causal edge tracking between related memory episodes |
|
|
169
|
+
| **L3** | Dynamic Persona | Identity state with automatic chronological conflict resolution |
|
|
170
|
+
| **L4** | Enterprise Policy Engine | Real-time policy and compliance injection |
|
|
171
|
+
| **L5** | Ebbinghaus Decay | Recency and frequency weighted memory decay |
|
|
172
|
+
| **L6** | SHA-256 Proof Chain | Cryptographically verifiable audit trail |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## TypeScript Support
|
|
177
|
+
|
|
178
|
+
InfinityDB includes full type definitions out of the box (`index.d.ts`). No `@types/infinitydb` required.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Links
|
|
183
|
+
|
|
184
|
+
- **Documentation & Benchmarks**: [https://github.com/infinitydb-ai/infinitydb](https://github.com/infinitydb-ai/infinitydb)
|
|
185
|
+
- **Python Package (PyPI)**: [`pip install infinitydb-ai`](https://pypi.org/project/infinitydb-ai/)
|
|
186
|
+
- **License**: Apache 2.0
|
package/index.d.ts
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
export interface MemoryResult {
|
|
2
|
-
id: string;
|
|
3
|
-
fact: string;
|
|
4
|
-
category: string;
|
|
5
|
-
sourceId: string;
|
|
6
|
-
score: number;
|
|
7
|
-
retention: number;
|
|
8
|
-
ts: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface RecallResponse {
|
|
12
|
-
results: MemoryResult[];
|
|
13
|
-
causalGraph: Array<{ cause: string; effect: string; relation: string }>;
|
|
14
|
-
policies: Array<{ id: string; rule: string; domain: string; priority: number }>;
|
|
15
|
-
latencyMs: number;
|
|
16
|
-
tokensSaved: string;
|
|
17
|
-
proofAvailable: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ProofResponse {
|
|
21
|
-
atomId: string;
|
|
22
|
-
hash: string;
|
|
23
|
-
sourceLogId: string;
|
|
24
|
-
rawSnippet: string;
|
|
25
|
-
charRange: [number, number];
|
|
26
|
-
verified: boolean;
|
|
27
|
-
timestamp: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class InfinityDB {
|
|
31
|
-
constructor(options?: Record<string, any>);
|
|
32
|
-
add(conversation: string, userId?: string, sessionId?: string | null, importance?: number): string;
|
|
33
|
-
recall(query: string, options?: { n?: number; userId?: string | null }): RecallResponse;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
1
|
+
export interface MemoryResult {
|
|
2
|
+
id: string;
|
|
3
|
+
fact: string;
|
|
4
|
+
category: string;
|
|
5
|
+
sourceId: string;
|
|
6
|
+
score: number;
|
|
7
|
+
retention: number;
|
|
8
|
+
ts: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RecallResponse {
|
|
12
|
+
results: MemoryResult[];
|
|
13
|
+
causalGraph: Array<{ cause: string; effect: string; relation: string }>;
|
|
14
|
+
policies: Array<{ id: string; rule: string; domain: string; priority: number }>;
|
|
15
|
+
latencyMs: number;
|
|
16
|
+
tokensSaved: string | null;
|
|
17
|
+
proofAvailable: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ProofResponse {
|
|
21
|
+
atomId: string;
|
|
22
|
+
hash: string;
|
|
23
|
+
sourceLogId: string;
|
|
24
|
+
rawSnippet: string;
|
|
25
|
+
charRange: [number, number];
|
|
26
|
+
verified: boolean;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class InfinityDB {
|
|
31
|
+
constructor(options?: { dbPath?: string } & Record<string, any>);
|
|
32
|
+
add(conversation: string, userId?: string, sessionId?: string | null, importance?: number): string;
|
|
33
|
+
recall(query: string, options?: { n?: number; userId?: string | null; asOf?: number }): RecallResponse;
|
|
34
|
+
supersedeFact(oldAtomId: string, newAtomId: string, userId: string): string;
|
|
35
|
+
getProof(atomId: string): ProofResponse | null;
|
|
36
|
+
getPersona(userId?: string): Record<string, string>;
|
|
37
|
+
addPolicy(rule: string, domain?: string, priority?: number, tenantId?: string | null): string;
|
|
38
|
+
exportGraph(userId?: string): string;
|
|
39
|
+
deleteUser(userId: string): Record<string, any>;
|
|
40
|
+
stats(): Record<string, any>;
|
|
41
|
+
close(): void;
|
|
42
|
+
put(key: string, content: string): { key: string; content: string; createdAt: string };
|
|
43
|
+
get(key: string): { key: string; content: string; createdAt: string } | null;
|
|
44
|
+
delete(key: string): boolean;
|
|
45
|
+
}
|