peon-mem 1.0.5 → 1.0.6
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.
|
@@ -40,4 +40,4 @@ export declare class EmbeddingStore {
|
|
|
40
40
|
/** Serialize a vector as base64 of its float32 bytes — ~4x smaller + faster to parse than JSON float64. */
|
|
41
41
|
export declare function encodeVector(vector: EmbeddingVector): string;
|
|
42
42
|
/** Decode a base64 float32 vector back to number[]; null on malformed/misaligned input. */
|
|
43
|
-
export declare function decodeVector(b64: string):
|
|
43
|
+
export declare function decodeVector(b64: string): Float32Array | null;
|
package/dist/embedding-store.js
CHANGED
|
@@ -140,7 +140,10 @@ export function decodeVector(b64) {
|
|
|
140
140
|
const buf = Buffer.from(b64, "base64");
|
|
141
141
|
if (buf.byteLength === 0 || buf.byteLength % 4 !== 0)
|
|
142
142
|
return null;
|
|
143
|
-
|
|
143
|
+
// Return the Float32Array itself rather than Array.from(...): a number[] stores every
|
|
144
|
+
// dimension as a double, doubling memory and copying 28k vectors on every cold load.
|
|
145
|
+
// slice() so the vector owns its bytes instead of pinning Node's shared Buffer pool.
|
|
146
|
+
return new Float32Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
|
|
144
147
|
}
|
|
145
148
|
catch {
|
|
146
149
|
return null;
|
package/dist/embeddings.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { PeonConfig } from "./config.js";
|
|
|
15
15
|
*
|
|
16
16
|
* - "off" mode: no embeddings; retrieval stays purely lexical.
|
|
17
17
|
*/
|
|
18
|
-
export type EmbeddingVector = number[];
|
|
18
|
+
export type EmbeddingVector = number[] | Float32Array;
|
|
19
19
|
export declare const LOCAL_EMBEDDING_DIM = 256;
|
|
20
20
|
export declare const LOCAL_EMBEDDING_MODEL = "peon-local-trigram-v1";
|
|
21
21
|
export interface EmbeddingClient {
|
package/dist/embeddings.js
CHANGED
|
@@ -28,7 +28,10 @@ export function l2normalize(vector) {
|
|
|
28
28
|
norm = Math.sqrt(norm);
|
|
29
29
|
if (norm === 0)
|
|
30
30
|
return vector.slice();
|
|
31
|
-
|
|
31
|
+
const out = new Float32Array(vector.length);
|
|
32
|
+
for (let i = 0; i < vector.length; i += 1)
|
|
33
|
+
out[i] = vector[i] / norm;
|
|
34
|
+
return out;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Deterministic local embedding: hashed character trigrams folded into a fixed
|
|
@@ -96,7 +99,8 @@ function b64decode(b64) {
|
|
|
96
99
|
const buf = Buffer.from(b64, "base64");
|
|
97
100
|
if (buf.byteLength === 0 || buf.byteLength % 4 !== 0)
|
|
98
101
|
return null;
|
|
99
|
-
|
|
102
|
+
// slice() to own the bytes: a view onto buf.buffer would pin Node's shared Buffer pool.
|
|
103
|
+
return new Float32Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
|
|
100
104
|
}
|
|
101
105
|
catch {
|
|
102
106
|
return null;
|
package/dist/memory-store.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PeonConfig } from "./config.js";
|
|
2
|
-
import { type EmbeddingClient } from "./embeddings.js";
|
|
2
|
+
import { type EmbeddingClient, type EmbeddingVector } from "./embeddings.js";
|
|
3
3
|
import type { MemoryQualityReport } from "./quality.js";
|
|
4
4
|
import { type MemoryPatch } from "./memory-mutations.js";
|
|
5
5
|
import { type BrainAction, type Summarizer } from "./brain.js";
|
|
@@ -134,7 +134,7 @@ export declare class PeonMemoryStore {
|
|
|
134
134
|
*/
|
|
135
135
|
rankRecordsReadonly(query: string | undefined, options?: {
|
|
136
136
|
limit?: number;
|
|
137
|
-
queryVector?:
|
|
137
|
+
queryVector?: EmbeddingVector;
|
|
138
138
|
}): Promise<RankedMemoryRecord[]>;
|
|
139
139
|
private buildSemanticInput;
|
|
140
140
|
writeQualityReport(report: MemoryQualityReport): Promise<void>;
|