@tangleai/memory 0.21.1 → 0.25.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/CHANGELOG.md +48 -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 +2 -2
- package/src/contradiction.js +3 -2
- package/src/crystallize.d.ts +2 -2
- package/src/crystallize.js +3 -2
- package/src/index.d.ts +3 -1
- package/src/index.js +2 -1
- package/src/novelty.d.ts +1 -1
- package/src/novelty.js +2 -1
- 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.js +3 -2
|
@@ -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.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
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
26
|
import { sameIdentity } from '@tangleai/context/ledger';
|
|
26
27
|
/**
|
|
@@ -29,8 +30,8 @@ import { sameIdentity } from '@tangleai/context/ledger';
|
|
|
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;
|