@hviana/sema 0.1.3 → 0.1.5
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/dist/example/demo.js +25 -25
- package/dist/example/train_base.d.ts +21 -19
- package/dist/example/train_base.js +1952 -1684
- package/dist/src/alphabet.d.ts +3 -3
- package/dist/src/alphabet.js +27 -24
- package/dist/src/alu/src/alu.d.ts +194 -169
- package/dist/src/alu/src/alu.js +414 -374
- package/dist/src/alu/src/expr.d.ts +43 -36
- package/dist/src/alu/src/expr.js +278 -252
- package/dist/src/alu/src/index.d.ts +98 -9
- package/dist/src/alu/src/index.js +63 -9
- package/dist/src/alu/src/kernel-arith.d.ts +5 -1
- package/dist/src/alu/src/kernel-arith.js +285 -195
- package/dist/src/alu/src/kernel-bits.d.ts +5 -1
- package/dist/src/alu/src/kernel-bits.js +115 -81
- package/dist/src/alu/src/kernel-logic.js +63 -33
- package/dist/src/alu/src/kernel-nd.js +195 -155
- package/dist/src/alu/src/kernel-numeric.d.ts +80 -16
- package/dist/src/alu/src/kernel-numeric.js +331 -259
- package/dist/src/alu/src/operation.d.ts +132 -112
- package/dist/src/alu/src/operation.js +163 -149
- package/dist/src/alu/src/parser.d.ts +175 -168
- package/dist/src/alu/src/parser.js +421 -382
- package/dist/src/alu/src/resonance.d.ts +25 -16
- package/dist/src/alu/src/resonance.js +56 -49
- package/dist/src/alu/src/text.d.ts +7 -3
- package/dist/src/alu/src/text.js +37 -31
- package/dist/src/alu/src/value.d.ts +14 -14
- package/dist/src/alu/src/value.js +160 -150
- package/dist/src/alu/test/alu.test.js +656 -543
- package/dist/src/bytes.d.ts +5 -1
- package/dist/src/bytes.js +40 -33
- package/dist/src/config.d.ts +102 -102
- package/dist/src/config.js +83 -83
- package/dist/src/derive/src/deduction.d.ts +62 -60
- package/dist/src/derive/src/deduction.js +109 -103
- package/dist/src/derive/src/index.d.ts +7 -1
- package/dist/src/derive/src/priority-queue.d.ts +8 -8
- package/dist/src/derive/src/priority-queue.js +61 -57
- package/dist/src/derive/src/rewrite.d.ts +18 -15
- package/dist/src/derive/src/rewrite.js +67 -59
- package/dist/src/derive/src/trie.d.ts +56 -56
- package/dist/src/derive/src/trie.js +179 -175
- package/dist/src/derive/test/derive.test.js +100 -96
- package/dist/src/extension.d.ts +16 -13
- package/dist/src/geometry.d.ts +42 -17
- package/dist/src/geometry.js +266 -235
- package/dist/src/index.d.ts +17 -2
- package/dist/src/index.js +7 -1
- package/dist/src/ingest-cache.d.ts +30 -25
- package/dist/src/ingest-cache.js +127 -108
- package/dist/src/mind/articulation.d.ts +5 -1
- package/dist/src/mind/articulation.js +112 -77
- package/dist/src/mind/attention.d.ts +108 -40
- package/dist/src/mind/attention.js +871 -749
- package/dist/src/mind/canonical.d.ts +19 -4
- package/dist/src/mind/canonical.js +31 -27
- package/dist/src/mind/graph-search.d.ts +225 -201
- package/dist/src/mind/graph-search.js +821 -742
- package/dist/src/mind/index.d.ts +10 -2
- package/dist/src/mind/junction.d.ts +58 -31
- package/dist/src/mind/junction.js +237 -172
- package/dist/src/mind/learning.d.ts +52 -16
- package/dist/src/mind/learning.js +165 -143
- package/dist/src/mind/match.d.ts +69 -20
- package/dist/src/mind/match.js +318 -259
- package/dist/src/mind/mechanisms/alu.js +16 -16
- package/dist/src/mind/mechanisms/cast.d.ts +13 -9
- package/dist/src/mind/mechanisms/cast.js +456 -363
- package/dist/src/mind/mechanisms/confluence.d.ts +12 -8
- package/dist/src/mind/mechanisms/confluence.js +183 -152
- package/dist/src/mind/mechanisms/cover.d.ts +8 -2
- package/dist/src/mind/mechanisms/cover.js +210 -148
- package/dist/src/mind/mechanisms/extraction.d.ts +34 -8
- package/dist/src/mind/mechanisms/extraction.js +288 -234
- package/dist/src/mind/mechanisms/recall.d.ts +10 -6
- package/dist/src/mind/mechanisms/recall.js +185 -126
- package/dist/src/mind/mind.d.ts +154 -129
- package/dist/src/mind/mind.js +288 -258
- package/dist/src/mind/pipeline-mechanism.d.ts +124 -112
- package/dist/src/mind/pipeline-mechanism.js +172 -161
- package/dist/src/mind/pipeline.d.ts +14 -4
- package/dist/src/mind/pipeline.js +189 -125
- package/dist/src/mind/primitives.d.ts +32 -8
- package/dist/src/mind/primitives.js +117 -99
- package/dist/src/mind/rationale.d.ts +98 -86
- package/dist/src/mind/rationale.js +121 -113
- package/dist/src/mind/reasoning.d.ts +13 -2
- package/dist/src/mind/reasoning.js +166 -129
- package/dist/src/mind/recognition.d.ts +4 -1
- package/dist/src/mind/recognition.js +208 -183
- package/dist/src/mind/resonance.d.ts +22 -5
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +25 -6
- package/dist/src/mind/trace.js +58 -50
- package/dist/src/mind/traverse.d.ts +58 -16
- package/dist/src/mind/traverse.js +357 -304
- package/dist/src/mind/types.d.ts +127 -120
- package/dist/src/mind/types.js +69 -60
- package/dist/src/rabitq-hnsw/src/database.d.ts +179 -177
- package/dist/src/rabitq-hnsw/src/database.js +359 -342
- package/dist/src/rabitq-hnsw/src/heap.d.ts +12 -12
- package/dist/src/rabitq-hnsw/src/heap.js +80 -75
- package/dist/src/rabitq-hnsw/src/hnsw.d.ts +103 -103
- package/dist/src/rabitq-hnsw/src/hnsw.js +454 -428
- package/dist/src/rabitq-hnsw/src/index.d.ts +6 -1
- package/dist/src/rabitq-hnsw/src/prng.d.ts +10 -10
- package/dist/src/rabitq-hnsw/src/prng.js +27 -25
- package/dist/src/rabitq-hnsw/src/rabitq.d.ts +69 -69
- package/dist/src/rabitq-hnsw/src/rabitq.js +262 -246
- package/dist/src/rabitq-hnsw/src/store.d.ts +132 -132
- package/dist/src/rabitq-hnsw/src/store.js +843 -752
- package/dist/src/rabitq-hnsw/test/hnsw.test.js +1054 -805
- package/dist/src/sema.d.ts +35 -0
- package/dist/src/sema.js +77 -0
- package/dist/src/store-sqlite.d.ts +166 -144
- package/dist/src/store-sqlite.js +660 -578
- package/dist/src/store.d.ts +630 -593
- package/dist/src/store.js +1581 -1440
- package/dist/src/vec.d.ts +9 -5
- package/dist/src/vec.js +73 -61
- package/package.json +2 -2
- package/src/sema.ts +102 -0
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export { VectorDatabase } from "./database.js";
|
|
2
|
-
export type {
|
|
2
|
+
export type {
|
|
3
|
+
DatabaseOptions,
|
|
4
|
+
ExternalId,
|
|
5
|
+
QueryResult,
|
|
6
|
+
StorageStats,
|
|
7
|
+
} from "./database.js";
|
|
3
8
|
export { HnswIndex } from "./hnsw.js";
|
|
4
9
|
export type { HnswParams, KnnHit } from "./hnsw.js";
|
|
5
10
|
export { RaBitQuantizer } from "./rabitq.js";
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
* regenerated after (de)serialization without storing large matrices.
|
|
7
7
|
*/
|
|
8
8
|
export declare class Prng {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
private state;
|
|
10
|
+
constructor(seed: number);
|
|
11
|
+
/** Uniform float in [0, 1). */
|
|
12
|
+
next(): number;
|
|
13
|
+
/** Uniform integer in [0, n). */
|
|
14
|
+
int(n: number): number;
|
|
15
|
+
/** Current internal state (one uint32), for persisting/resuming the stream. */
|
|
16
|
+
snapshot(): number;
|
|
17
|
+
/** Resume the stream from a previously snapshotted state. */
|
|
18
|
+
restore(state: number): void;
|
|
19
19
|
}
|
|
@@ -6,31 +6,33 @@
|
|
|
6
6
|
* regenerated after (de)serialization without storing large matrices.
|
|
7
7
|
*/
|
|
8
8
|
export class Prng {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
state;
|
|
10
|
+
constructor(seed) {
|
|
11
|
+
this.state = seed >>> 0;
|
|
12
|
+
if (this.state === 0) {
|
|
13
|
+
this.state = 0x9e3779b9;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
}
|
|
16
|
+
/** Uniform float in [0, 1). */
|
|
17
|
+
next() {
|
|
18
|
+
let t = (this.state = (this.state + 0x6d2b79f5) | 0);
|
|
19
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
20
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
21
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
22
|
+
}
|
|
23
|
+
/** Uniform integer in [0, n). */
|
|
24
|
+
int(n) {
|
|
25
|
+
return (this.next() * n) | 0;
|
|
26
|
+
}
|
|
27
|
+
/** Current internal state (one uint32), for persisting/resuming the stream. */
|
|
28
|
+
snapshot() {
|
|
29
|
+
return this.state >>> 0;
|
|
30
|
+
}
|
|
31
|
+
/** Resume the stream from a previously snapshotted state. */
|
|
32
|
+
restore(state) {
|
|
33
|
+
this.state = state >>> 0;
|
|
34
|
+
if (this.state === 0) {
|
|
35
|
+
this.state = 0x9e3779b9;
|
|
35
36
|
}
|
|
37
|
+
}
|
|
36
38
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export interface QueryContext {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
vmin: number;
|
|
3
|
+
delta: number;
|
|
4
|
+
sumQInt: number;
|
|
5
|
+
/**
|
|
6
|
+
* Per-query lookup table of length nbytes*256. `qlut[p*256 + b]` is the sum of
|
|
7
|
+
* the quantised query values at the (up to 8) coordinates whose code bits are
|
|
8
|
+
* set in byte value `b` at code-byte position `p`. The query/code inner product
|
|
9
|
+
* for a stored code is then sum over its bytes of qlut[p*256 + codeByte_p].
|
|
10
|
+
*/
|
|
11
|
+
qlut: Uint8Array | Uint16Array;
|
|
12
|
+
/** number of bytes per code (paddedDim / 8). */
|
|
13
|
+
nbytes: number;
|
|
14
|
+
/** true when the (centered) query has zero norm. */
|
|
15
|
+
zero: boolean;
|
|
16
16
|
}
|
|
17
17
|
export interface RaBitQOptions {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
queryBits?: number;
|
|
19
|
+
rounds?: number;
|
|
20
|
+
seed?: number;
|
|
21
|
+
centroid?: ArrayLike<number>;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* 1-bit RaBitQ quantizer (cosine) -- the ONLY representation of a vector kept by
|
|
@@ -41,55 +41,55 @@ export interface RaBitQOptions {
|
|
|
41
41
|
* Theoretical Error Bound for Approximate Nearest Neighbor Search", SIGMOD 2024.
|
|
42
42
|
*/
|
|
43
43
|
export declare class RaBitQuantizer {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
44
|
+
readonly dim: number;
|
|
45
|
+
readonly paddedDim: number;
|
|
46
|
+
readonly codeWords: number;
|
|
47
|
+
readonly queryBits: number;
|
|
48
|
+
readonly rounds: number;
|
|
49
|
+
readonly seed: number;
|
|
50
|
+
readonly centroid: Float64Array;
|
|
51
|
+
private readonly sqrtD;
|
|
52
|
+
private readonly maxQInt;
|
|
53
|
+
private readonly signs;
|
|
54
|
+
private readonly scratch;
|
|
55
|
+
/** Fixed cosine inner-product scale (= 1 / E[L1] of a rotated unit vector). */
|
|
56
|
+
readonly cosFactor: number;
|
|
57
|
+
private readonly nbytes;
|
|
58
|
+
/** coordinate index sitting at byte position p, bit k -> bitCoord[p*8 + k]. */
|
|
59
|
+
private readonly bitCoord;
|
|
60
|
+
/** true when the largest possible LUT entry overflows a Uint8. */
|
|
61
|
+
private readonly lutWide;
|
|
62
|
+
constructor(dim: number, opts?: RaBitQOptions);
|
|
63
|
+
/** In-place fast Walsh-Hadamard transform; `a.length` must be a power of two. */
|
|
64
|
+
private fwht;
|
|
65
|
+
/** Apply the orthogonal rotation in place (a.length === paddedDim). */
|
|
66
|
+
private rotate;
|
|
67
|
+
/** Encode a raw vector into its 1-bit sign code (the whole representation). */
|
|
68
|
+
encode(vec: ArrayLike<number>): Uint32Array;
|
|
69
|
+
/** Pre-process a full-precision query into the structure consumed by `estimate`. */
|
|
70
|
+
prepareQuery(vec: ArrayLike<number>): QueryContext;
|
|
71
|
+
/**
|
|
72
|
+
* Estimate the cosine distance (1 - cosine) between a stored code and a
|
|
73
|
+
* full-precision query, reading the code's bytes against the query's byte LUT.
|
|
74
|
+
* The code's set-bit count is tallied in the same byte scan, so nothing beyond
|
|
75
|
+
* the code itself is needed.
|
|
76
|
+
*
|
|
77
|
+
* `codeBytes` is a Uint8 view of the packed code buffer and `byteOffset` is the
|
|
78
|
+
* code's start byte (id * paddedDim/8).
|
|
79
|
+
*/
|
|
80
|
+
estimate(codeBytes: Uint8Array, byteOffset: number, q: QueryContext): number;
|
|
81
|
+
/**
|
|
82
|
+
* Cosine distance (1 - cosine, in [0, 2]) between two packed codes, computed
|
|
83
|
+
* directly from the BLOB bytes via their sign-bit Hamming distance — no word
|
|
84
|
+
* reinterpretation, so it is endianness-agnostic. Identical codes score 0.
|
|
85
|
+
*
|
|
86
|
+
* This is the distance used to build the graph (code vs code) and to answer a
|
|
87
|
+
* query given an already-quantized code. It is coarser than `estimate`, where
|
|
88
|
+
* one side is full precision.
|
|
89
|
+
*/
|
|
90
|
+
codeDistanceBytes(a: Uint8Array, b: Uint8Array): number;
|
|
91
|
+
/** Pack a code (codeWords 32-bit words) into its little-endian BLOB bytes. */
|
|
92
|
+
codeToBytes(code: ArrayLike<number>): Uint8Array;
|
|
93
|
+
/** Reinterpret a code BLOB as a copy of codeWords 32-bit words. */
|
|
94
|
+
bytesToCode(bytes: Uint8Array): Uint32Array;
|
|
95
95
|
}
|