@tangleai/memory 0.20.1 → 0.24.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 +72 -0
- package/README.md +64 -3
- package/package.json +13 -6
- package/schemas/policy.contract.json +256 -0
- package/schemas/policy.schema.json +110 -0
- package/src/contradiction.d.ts +4 -4
- package/src/contradiction.js +5 -4
- package/src/crystallize.d.ts +2 -2
- package/src/crystallize.js +4 -3
- package/src/index.d.ts +3 -1
- package/src/index.js +2 -1
- package/src/ingest.d.ts +1 -1
- package/src/ingest.js +1 -1
- package/src/novelty.d.ts +1 -1
- package/src/novelty.js +3 -2
- package/src/outcome.d.ts +3 -1
- package/src/outcome.js +10 -3
- package/src/policy.d.ts +13 -0
- package/src/policy.gen.d.ts +64 -0
- package/src/policy.gen.js +695 -0
- package/src/policy.js +13 -0
- package/src/policy.types.d.ts +36 -0
- package/src/policy.types.js +3 -0
- package/src/retrieval.d.ts +1 -1
- package/src/retrieval.js +5 -4
- package/src/store.d.ts +1 -1
- package/src/store.js +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface PolicyContradiction {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
threshold: number;
|
|
4
|
+
/**
|
|
5
|
+
* Schema constraints this type cannot express: type="integer", minimum=0
|
|
6
|
+
*/
|
|
7
|
+
maxPairs: number;
|
|
8
|
+
}
|
|
9
|
+
export interface PolicyRetrieval {
|
|
10
|
+
/**
|
|
11
|
+
* Schema constraints this type cannot express: type="integer", minimum=0
|
|
12
|
+
*/
|
|
13
|
+
k: number;
|
|
14
|
+
minScore: number;
|
|
15
|
+
}
|
|
16
|
+
export interface PolicyEmbedding {
|
|
17
|
+
model: string;
|
|
18
|
+
/**
|
|
19
|
+
* Schema constraints this type cannot express: type="integer", minimum=0
|
|
20
|
+
*/
|
|
21
|
+
dims: number;
|
|
22
|
+
tier: "keyless";
|
|
23
|
+
}
|
|
24
|
+
export interface Policy {
|
|
25
|
+
novelty: {
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
threshold: number;
|
|
28
|
+
};
|
|
29
|
+
contradiction: PolicyContradiction;
|
|
30
|
+
crystallization: {
|
|
31
|
+
enabled: boolean;
|
|
32
|
+
threshold: number;
|
|
33
|
+
};
|
|
34
|
+
retrieval: PolicyRetrieval;
|
|
35
|
+
embedding: PolicyEmbedding;
|
|
36
|
+
}
|
package/src/retrieval.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Embedding-ranked retrieval over memory units.
|
|
3
3
|
*
|
|
4
4
|
* This is Tangle's ranker over its OWN store of full units, beside the
|
|
5
|
-
* @
|
|
5
|
+
* @tangleai/context ledger's `recall({ near })` (which ranks the mirrored
|
|
6
6
|
* ledger records the same way, through the same kernels). Superseded
|
|
7
7
|
* records never surface — they exist for audit, not for recall. Records
|
|
8
8
|
* without embeddings never surface either, which is a real bias (see
|
package/src/retrieval.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Embedding-ranked retrieval over memory units.
|
|
3
3
|
*
|
|
4
4
|
* This is Tangle's ranker over its OWN store of full units, beside the
|
|
5
|
-
* @
|
|
5
|
+
* @tangleai/context ledger's `recall({ near })` (which ranks the mirrored
|
|
6
6
|
* ledger records the same way, through the same kernels). Superseded
|
|
7
7
|
* records never surface — they exist for audit, not for recall. Records
|
|
8
8
|
* without embeddings never surface either, which is a real bias (see
|
|
@@ -21,16 +21,17 @@
|
|
|
21
21
|
* The metric is `cosineSimilarity` from `@jarenjs/core/vector`: the one
|
|
22
22
|
* the suite ranks by, higher-is-better, 0 for a malformed pair.
|
|
23
23
|
*/
|
|
24
|
+
import { DEFAULT_MEMORY_POLICY } from "./policy.js";
|
|
24
25
|
import { cosineSimilarity } from '@jarenjs/core/vector';
|
|
25
|
-
import { sameIdentity } from '@
|
|
26
|
+
import { sameIdentity } from '@tangleai/context/ledger';
|
|
26
27
|
/**
|
|
27
28
|
* Rank the live, comparably-embedded units against a query vector and
|
|
28
29
|
* report what could not be ranked. `queryEmbedding` may be the
|
|
29
30
|
* `Float32Array` an embedder answers or the `number[]` a record stores.
|
|
30
31
|
*/
|
|
31
32
|
export function recallByEmbedding(units, queryEmbedding, options = {}) {
|
|
32
|
-
const k = options.k ??
|
|
33
|
-
const minScore = options.minScore ??
|
|
33
|
+
const k = options.k ?? DEFAULT_MEMORY_POLICY.retrieval.k;
|
|
34
|
+
const minScore = options.minScore ?? DEFAULT_MEMORY_POLICY.retrieval.minScore;
|
|
34
35
|
const identity = options.identity;
|
|
35
36
|
const scored = [];
|
|
36
37
|
let skipped = 0;
|
package/src/store.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The memory store seam and its default in-memory implementation.
|
|
3
3
|
*
|
|
4
4
|
* The contract is four async methods — `get`, `put`, `delete`, `list` —
|
|
5
|
-
* the same injection shape as the @
|
|
5
|
+
* the same injection shape as the @tangleai/context ledger's storage seam, one
|
|
6
6
|
* level up: this store holds validated memory UNITS, not raw strings.
|
|
7
7
|
* A host backs it with SQLite, OPFS, a graph database, whatever; the
|
|
8
8
|
* policies in this package only ever see the contract.
|
package/src/store.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The memory store seam and its default in-memory implementation.
|
|
3
3
|
*
|
|
4
4
|
* The contract is four async methods — `get`, `put`, `delete`, `list` —
|
|
5
|
-
* the same injection shape as the @
|
|
5
|
+
* the same injection shape as the @tangleai/context ledger's storage seam, one
|
|
6
6
|
* level up: this store holds validated memory UNITS, not raw strings.
|
|
7
7
|
* A host backs it with SQLite, OPFS, a graph database, whatever; the
|
|
8
8
|
* policies in this package only ever see the contract.
|