@linxiraos/pi-mnemopi 1.0.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 +248 -0
- package/README.md +108 -0
- package/dist/types/cli.d.ts +35 -0
- package/dist/types/config.d.ts +108 -0
- package/dist/types/core/aaak.d.ts +55 -0
- package/dist/types/core/annotations.d.ts +75 -0
- package/dist/types/core/banks.d.ts +33 -0
- package/dist/types/core/beam/consolidate.d.ts +38 -0
- package/dist/types/core/beam/helpers.d.ts +69 -0
- package/dist/types/core/beam/index.d.ts +59 -0
- package/dist/types/core/beam/recall.d.ts +52 -0
- package/dist/types/core/beam/schema.d.ts +2 -0
- package/dist/types/core/beam/store.d.ts +57 -0
- package/dist/types/core/beam/types.d.ts +268 -0
- package/dist/types/core/binary-vectors.d.ts +54 -0
- package/dist/types/core/chat-normalize.d.ts +13 -0
- package/dist/types/core/content-sanitizer.d.ts +18 -0
- package/dist/types/core/cost-log.d.ts +13 -0
- package/dist/types/core/embeddings.d.ts +93 -0
- package/dist/types/core/entities.d.ts +9 -0
- package/dist/types/core/episodic-graph.d.ts +89 -0
- package/dist/types/core/extraction/client.d.ts +35 -0
- package/dist/types/core/extraction/diagnostics.d.ts +51 -0
- package/dist/types/core/extraction/prompts.d.ts +2 -0
- package/dist/types/core/extraction.d.ts +34 -0
- package/dist/types/core/fastembed-model-cache.d.ts +2 -0
- package/dist/types/core/fastembed-runtime.d.ts +41 -0
- package/dist/types/core/index.d.ts +6 -0
- package/dist/types/core/llm-backends.d.ts +23 -0
- package/dist/types/core/local-llm.d.ts +20 -0
- package/dist/types/core/memory.d.ts +186 -0
- package/dist/types/core/migrations/e6-triplestore-split.d.ts +17 -0
- package/dist/types/core/migrations/index.d.ts +1 -0
- package/dist/types/core/mmr.d.ts +8 -0
- package/dist/types/core/orchestrator.d.ts +20 -0
- package/dist/types/core/patterns.d.ts +61 -0
- package/dist/types/core/plugins.d.ts +109 -0
- package/dist/types/core/polyphonic-recall.d.ts +66 -0
- package/dist/types/core/query-cache.d.ts +45 -0
- package/dist/types/core/query-intent.d.ts +20 -0
- package/dist/types/core/recall-diagnostics.d.ts +48 -0
- package/dist/types/core/runtime-options.d.ts +76 -0
- package/dist/types/core/shmr.d.ts +62 -0
- package/dist/types/core/streaming.d.ts +136 -0
- package/dist/types/core/synonyms.d.ts +46 -0
- package/dist/types/core/temporal-parser.d.ts +16 -0
- package/dist/types/core/token-counter.d.ts +8 -0
- package/dist/types/core/triples.d.ts +63 -0
- package/dist/types/core/typed-memory.d.ts +39 -0
- package/dist/types/core/vector-index.d.ts +16 -0
- package/dist/types/core/vector-math.d.ts +1 -0
- package/dist/types/core/veracity-consolidation.d.ts +60 -0
- package/dist/types/core/weibull.d.ts +96 -0
- package/dist/types/db.d.ts +18 -0
- package/dist/types/diagnose.d.ts +24 -0
- package/dist/types/dr/index.d.ts +1 -0
- package/dist/types/dr/recovery.d.ts +68 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/mcp-server.d.ts +40 -0
- package/dist/types/mcp-tools.d.ts +484 -0
- package/dist/types/migrations/e6-triplestore-split.d.ts +1 -0
- package/dist/types/migrations/index.d.ts +1 -0
- package/dist/types/types.d.ts +145 -0
- package/dist/types/util/datetime.d.ts +8 -0
- package/dist/types/util/env.d.ts +10 -0
- package/dist/types/util/ids.d.ts +3 -0
- package/dist/types/util/lru.d.ts +12 -0
- package/dist/types/util/regex.d.ts +11 -0
- package/package.json +108 -0
- package/src/cli.ts +398 -0
- package/src/config.ts +373 -0
- package/src/core/aaak.ts +142 -0
- package/src/core/annotations.ts +456 -0
- package/src/core/banks.ts +133 -0
- package/src/core/beam/consolidate.ts +1132 -0
- package/src/core/beam/helpers.ts +831 -0
- package/src/core/beam/index.ts +358 -0
- package/src/core/beam/recall.ts +1225 -0
- package/src/core/beam/schema.ts +426 -0
- package/src/core/beam/store.ts +1083 -0
- package/src/core/beam/types.ts +303 -0
- package/src/core/binary-vectors.ts +317 -0
- package/src/core/chat-normalize.ts +160 -0
- package/src/core/content-sanitizer.ts +136 -0
- package/src/core/cost-log.ts +101 -0
- package/src/core/embeddings.ts +624 -0
- package/src/core/entities.ts +263 -0
- package/src/core/episodic-graph.ts +708 -0
- package/src/core/extraction/client.ts +187 -0
- package/src/core/extraction/diagnostics.ts +193 -0
- package/src/core/extraction/prompts.ts +31 -0
- package/src/core/extraction.ts +491 -0
- package/src/core/fastembed-model-cache.ts +39 -0
- package/src/core/fastembed-runtime.ts +172 -0
- package/src/core/index.ts +39 -0
- package/src/core/llm-backends.ts +54 -0
- package/src/core/local-llm.ts +475 -0
- package/src/core/memory.ts +680 -0
- package/src/core/migrations/e6-triplestore-split.ts +211 -0
- package/src/core/migrations/index.ts +1 -0
- package/src/core/mmr.ts +101 -0
- package/src/core/orchestrator.ts +62 -0
- package/src/core/patterns.ts +484 -0
- package/src/core/plugins.ts +375 -0
- package/src/core/polyphonic-recall.ts +563 -0
- package/src/core/query-cache.ts +351 -0
- package/src/core/query-intent.ts +139 -0
- package/src/core/recall-diagnostics.ts +157 -0
- package/src/core/runtime-options.ts +130 -0
- package/src/core/shmr.ts +567 -0
- package/src/core/streaming.ts +419 -0
- package/src/core/synonyms.ts +197 -0
- package/src/core/temporal-parser.ts +363 -0
- package/src/core/token-counter.ts +30 -0
- package/src/core/triples.ts +452 -0
- package/src/core/typed-memory.ts +407 -0
- package/src/core/vector-index.ts +83 -0
- package/src/core/vector-math.ts +23 -0
- package/src/core/veracity-consolidation.ts +477 -0
- package/src/core/weibull.ts +124 -0
- package/src/db.ts +186 -0
- package/src/diagnose.ts +174 -0
- package/src/dr/index.ts +1 -0
- package/src/dr/recovery.ts +405 -0
- package/src/index.ts +33 -0
- package/src/mcp-server.ts +155 -0
- package/src/mcp-tools.ts +970 -0
- package/src/migrations/e6-triplestore-split.ts +1 -0
- package/src/migrations/index.ts +1 -0
- package/src/types.ts +157 -0
- package/src/util/datetime.ts +69 -0
- package/src/util/env.ts +65 -0
- package/src/util/ids.ts +19 -0
- package/src/util/lru.ts +48 -0
- package/src/util/regex.ts +165 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const DEFAULT_DATA_DIR: string;
|
|
2
|
+
export declare const BANKS_DIR: string;
|
|
3
|
+
export declare class ValueError extends Error {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
export interface BankStats {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly exists: boolean;
|
|
9
|
+
readonly db_path: string;
|
|
10
|
+
readonly dbSizeBytes: number;
|
|
11
|
+
readonly db_size_bytes: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class BankManager {
|
|
14
|
+
readonly dataDir: string;
|
|
15
|
+
readonly banksDir: string;
|
|
16
|
+
constructor(dataDir?: string);
|
|
17
|
+
createBank(name: string): string;
|
|
18
|
+
deleteBank(name: string, force?: boolean): boolean;
|
|
19
|
+
listBanks(): string[];
|
|
20
|
+
bankExists(name: string): boolean;
|
|
21
|
+
getBankDbPath(name: string): string;
|
|
22
|
+
renameBank(oldName: string, newName: string): string;
|
|
23
|
+
getBankStats(name: string): BankStats;
|
|
24
|
+
private validateName;
|
|
25
|
+
}
|
|
26
|
+
export declare function createBank(name: string, dataDir?: string): string;
|
|
27
|
+
export declare function deleteBank(name: string, dataDir?: string, force?: boolean): boolean;
|
|
28
|
+
export declare function listBanks(dataDir?: string): string[];
|
|
29
|
+
export declare function bankExists(name: string, dataDir?: string): boolean;
|
|
30
|
+
export declare function bankDbPath(name?: string, dataDir?: string): string;
|
|
31
|
+
export declare function setBank(bank: string): void;
|
|
32
|
+
export declare function getBank(): string;
|
|
33
|
+
export declare function resetBankForTests(): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ExtractedFactCategories } from "../extraction.js";
|
|
2
|
+
import type { BeamMemoryState, BeamStats, JsonValue, MemoriaRetrieveResult, Metadata, SleepResult } from "./types.js";
|
|
3
|
+
type Row = Record<string, unknown>;
|
|
4
|
+
type FactCounts = {
|
|
5
|
+
metric: number;
|
|
6
|
+
date: number;
|
|
7
|
+
version: number;
|
|
8
|
+
entity: number;
|
|
9
|
+
sequence: number;
|
|
10
|
+
timeline: number;
|
|
11
|
+
negation: number;
|
|
12
|
+
decision: number;
|
|
13
|
+
};
|
|
14
|
+
type ConsolidateOptions = {
|
|
15
|
+
metadata?: Metadata | null;
|
|
16
|
+
validUntil?: string | null;
|
|
17
|
+
scope?: string;
|
|
18
|
+
veracity?: string | null;
|
|
19
|
+
};
|
|
20
|
+
export declare function consolidateToEpisodic(beam: BeamMemoryState, summary: string, sourceWmIds: readonly string[], source?: string, importance?: number, options?: ConsolidateOptions): string;
|
|
21
|
+
export declare function detectLanguage(_beam: BeamMemoryState, text: string): string;
|
|
22
|
+
type StoreFactStringOptions = {
|
|
23
|
+
routeHeuristicCategories?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare function storeFactStrings(beam: BeamMemoryState, facts: readonly string[], messageIdx?: number, sourceMemoryId?: string | null, importance?: number, options?: StoreFactStringOptions): number;
|
|
26
|
+
/** Store category-preserving LLM extraction output in MEMORIA and KG tables. */
|
|
27
|
+
export declare function storeExtractedFactCategories(beam: BeamMemoryState, extracted: ExtractedFactCategories, messageIdx?: number, sourceMemoryId?: string | null, importance?: number): number;
|
|
28
|
+
export declare function extractAndStoreFacts(beam: BeamMemoryState, content: string, messageIdx?: number, sourceMemoryId?: string | null): FactCounts;
|
|
29
|
+
export declare function memoriaRetrieve(beam: BeamMemoryState, query: string, ability?: string | null, topK?: number): MemoriaRetrieveResult;
|
|
30
|
+
export declare function getEpisodicStats(beam: BeamMemoryState, authorId?: string | null, authorType?: string | null, channelId?: string | null): BeamStats;
|
|
31
|
+
export declare function getMemoriaStats(beam: BeamMemoryState): BeamStats;
|
|
32
|
+
export declare function degradeEpisodic(beam: BeamMemoryState, dryRun?: boolean): Record<string, JsonValue>;
|
|
33
|
+
export declare function getContaminated(beam: BeamMemoryState, limit?: number, minImportance?: number): Row[];
|
|
34
|
+
export declare function health(beam: BeamMemoryState, staleThresholdHours?: number): Record<string, JsonValue | Record<string, JsonValue>>;
|
|
35
|
+
export declare function sleep(beam: BeamMemoryState, dryRun?: boolean): SleepResult;
|
|
36
|
+
export declare function sleepAllSessions(beam: BeamMemoryState, dryRun?: boolean): SleepResult;
|
|
37
|
+
export declare function getConsolidationLog(beam: BeamMemoryState, limit?: number): Row[];
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { sha256Hex16 } from "../../util/ids.js";
|
|
3
|
+
import { cjkFtsTerms, containsSpacelessCjk, ftsQueryTerms, recallTokens } from "../../util/regex.js";
|
|
4
|
+
import type { BeamMemoryState, Metadata } from "./types.js";
|
|
5
|
+
export type Vector = number[];
|
|
6
|
+
export type HybridWeights = readonly [vecWeight: number, ftsWeight: number, importanceWeight: number];
|
|
7
|
+
export interface VectorDistanceResult {
|
|
8
|
+
rowid: number;
|
|
9
|
+
distance: number;
|
|
10
|
+
}
|
|
11
|
+
export interface WorkingVectorResult {
|
|
12
|
+
id: string;
|
|
13
|
+
sim: number;
|
|
14
|
+
}
|
|
15
|
+
export interface FtsRankResult {
|
|
16
|
+
rowid: number;
|
|
17
|
+
rank: number;
|
|
18
|
+
}
|
|
19
|
+
export interface WorkingFtsRankResult {
|
|
20
|
+
id: string;
|
|
21
|
+
rank: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function generateId(content: string, now?: Date): string;
|
|
24
|
+
export declare function generateStableId(content: string, source?: string): string;
|
|
25
|
+
export declare function normalizeWeights(vecWeight: number | null | undefined, ftsWeight: number | null | undefined, importanceWeight: number | null | undefined): HybridWeights;
|
|
26
|
+
export declare function normalizeImportance(importance: number | null | undefined, fallback?: number): number;
|
|
27
|
+
export declare function normalizeDateUtc(dt: Date): Date;
|
|
28
|
+
export declare function parseIsoDateTimeUtc(value: string): Date;
|
|
29
|
+
export declare function parseQueryTime(queryTime?: string | Date | null): Date;
|
|
30
|
+
export declare function parseTimestampFast(ts: string | null | undefined, beam?: Pick<BeamMemoryState, "caches"> | null): Date | null;
|
|
31
|
+
export declare function recencyDecay(timestamp: string | null | undefined, halflifeHours?: number, now?: Date): number;
|
|
32
|
+
export declare function temporalBoost(memoryTimestamp: string | null | undefined, queryTime: Date | string, halflifeHours?: number, beam?: Pick<BeamMemoryState, "caches"> | null): number;
|
|
33
|
+
export declare function lexicalRelevance(queryTokens: readonly string[], content: string, queryLower?: string): number;
|
|
34
|
+
export declare function strictFactMatches(query: string, factText: string): boolean;
|
|
35
|
+
export declare function buildFtsQuery(query: string): string;
|
|
36
|
+
export declare function cjkLikeSearch(db: Database, query: string, k?: number, working?: boolean): Array<FtsRankResult | WorkingFtsRankResult>;
|
|
37
|
+
export declare function ftsSearch(db: Database, query: string, k?: number): FtsRankResult[];
|
|
38
|
+
export declare function ftsSearchWorking(db: Database, query: string, k?: number): WorkingFtsRankResult[];
|
|
39
|
+
export declare function encodeVector(embedding: readonly number[]): string;
|
|
40
|
+
export declare function decodeVector(value: string | null | undefined): Vector | null;
|
|
41
|
+
export declare function vecAvailable(db: Database): boolean;
|
|
42
|
+
export declare function effectiveVecType(db: Database): "float32" | "int8" | "bit";
|
|
43
|
+
export declare function vecInsert(db: Database, rowid: number, embedding: readonly number[]): void;
|
|
44
|
+
export declare function vecSearch(db: Database, embedding: readonly number[], k?: number): VectorDistanceResult[];
|
|
45
|
+
export declare function inMemoryVecSearch(db: Database, queryEmbedding: readonly number[], k?: number): VectorDistanceResult[];
|
|
46
|
+
export declare function workingMemoryVecSearch(db: Database, queryEmbedding: readonly number[], k?: number, now?: Date): WorkingVectorResult[];
|
|
47
|
+
export declare function normalizeMetadata(input: unknown): Metadata;
|
|
48
|
+
export declare function metadataJson(input: unknown): string;
|
|
49
|
+
export declare function detectLanguage(text: string): string;
|
|
50
|
+
export declare function memoryRowMetadata(row: unknown): Metadata;
|
|
51
|
+
export { cosineSimilarity, hammingDistance, informationTheoreticScore, maximallyInformativeBinarization, quantizeInt8, } from "../binary-vectors.js";
|
|
52
|
+
export { cjkFtsTerms, containsSpacelessCjk, ftsQueryTerms, recallTokens, sha256Hex16 };
|
|
53
|
+
/** Identifies one freshly stored memory whose embedding still needs to be derived. */
|
|
54
|
+
export interface EmbedItem {
|
|
55
|
+
readonly memoryId: string;
|
|
56
|
+
readonly content: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Schedule background embedding generation for one or more freshly stored memories.
|
|
60
|
+
*
|
|
61
|
+
* Mirrors the `scheduleFactExtraction` pattern in `beam/store.ts`: `remember()`,
|
|
62
|
+
* `rememberBatch()`, and `consolidateToEpisodic()` are synchronous, but `embed()` is
|
|
63
|
+
* async (it may hit an HTTP provider), so the task is fired-and-forgotten and tracked
|
|
64
|
+
* on `beam.pendingExtractions` so tests and graceful shutdown can drain it via
|
|
65
|
+
* `flushExtractions()`. The active runtime options (provider, model, API URL/key) are
|
|
66
|
+
* captured here and re-entered inside the task because the `AsyncLocalStorage` scope
|
|
67
|
+
* set by `Mnemopi.#withRuntimeOptions` has already exited by the time the task runs.
|
|
68
|
+
*/
|
|
69
|
+
export declare function scheduleEmbedding(beam: BeamMemoryState, items: readonly EmbedItem[]): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import type { BeamCaches, BeamConfig, BeamEvent, BeamMemoryOptions, BeamMemoryState, BeamStats, ImportStats, MemoriaRetrieveResult, Metadata, RecallEnhancedOptions, RecallOptions, RecallResult, RememberBatchItem, RememberBatchOptions, RememberOptions, SleepResult } from "./types.js";
|
|
3
|
+
export { initBeam } from "./schema.js";
|
|
4
|
+
export type * from "./types.js";
|
|
5
|
+
export declare class BeamMemory implements BeamMemoryState {
|
|
6
|
+
#private;
|
|
7
|
+
readonly db: Database;
|
|
8
|
+
readonly dbPath?: string;
|
|
9
|
+
readonly sessionId: string;
|
|
10
|
+
readonly authorId: string | null;
|
|
11
|
+
readonly authorType: string | null;
|
|
12
|
+
readonly channelId: string;
|
|
13
|
+
readonly useCloud: boolean;
|
|
14
|
+
readonly eventEmitter?: (event: BeamEvent) => void;
|
|
15
|
+
readonly pluginManager: BeamMemoryState["pluginManager"];
|
|
16
|
+
readonly annotations: BeamMemoryState["annotations"];
|
|
17
|
+
readonly triples: BeamMemoryState["triples"];
|
|
18
|
+
readonly episodicGraph: unknown | null;
|
|
19
|
+
readonly veracityConsolidator: unknown | null;
|
|
20
|
+
readonly caches: BeamCaches;
|
|
21
|
+
readonly config: BeamConfig;
|
|
22
|
+
readonly pendingExtractions: Set<Promise<void>>;
|
|
23
|
+
constructor(options?: BeamMemoryOptions);
|
|
24
|
+
constructor(sessionId?: string, dbPath?: string, authorId?: string | null, authorType?: string | null, channelId?: string | null, useCloud?: boolean, eventEmitter?: (event: BeamEvent) => void);
|
|
25
|
+
close(): void;
|
|
26
|
+
flushExtractions(): Promise<void>;
|
|
27
|
+
remember(content: string, options?: RememberOptions): string;
|
|
28
|
+
rememberBatch(items: readonly RememberBatchItem[], options?: RememberBatchOptions): string[];
|
|
29
|
+
getContext(limit?: number): unknown[];
|
|
30
|
+
invalidate(memoryId: string, replacementId?: string | null): boolean;
|
|
31
|
+
getWorkingStats(authorId?: string | null, authorType?: string | null, channelId?: string | null): BeamStats;
|
|
32
|
+
getGlobalWorkingStats(): BeamStats;
|
|
33
|
+
updateWorking(memoryId: string, content?: string | null, importance?: number | null): boolean;
|
|
34
|
+
get(memoryId: string): unknown | null;
|
|
35
|
+
forgetWorking(memoryId: string): boolean;
|
|
36
|
+
consolidateToEpisodic(summary: string, sourceWmIds: readonly string[], source?: string, importance?: number): string;
|
|
37
|
+
detectLanguage(text: string): string;
|
|
38
|
+
extractAndStoreFacts(content: string, messageIdx?: number, sourceMemoryId?: string | null): Record<string, unknown>;
|
|
39
|
+
memoriaRetrieve(query: string, ability?: string | null, topK?: number): MemoriaRetrieveResult;
|
|
40
|
+
recall(query: string, topK?: number, options?: RecallOptions): Promise<RecallResult[]>;
|
|
41
|
+
recallEnhanced(query: string, topK?: number, options?: RecallEnhancedOptions): Promise<RecallResult[]>;
|
|
42
|
+
formatContext(results: readonly RecallResult[], format?: string): string;
|
|
43
|
+
factRecall(query: string, topK?: number): RecallResult[];
|
|
44
|
+
getEpisodicStats(authorId?: string | null, authorType?: string | null, channelId?: string | null): BeamStats;
|
|
45
|
+
getMemoriaStats(): BeamStats;
|
|
46
|
+
scratchpadWrite(content: string): string;
|
|
47
|
+
scratchpadRead(): unknown[];
|
|
48
|
+
scratchpadClear(): void;
|
|
49
|
+
degradeEpisodic(dryRun?: boolean): Record<string, unknown>;
|
|
50
|
+
getContaminated(limit?: number, minImportance?: number): unknown[];
|
|
51
|
+
health(staleThresholdHours?: number): Record<string, unknown>;
|
|
52
|
+
sleep(dryRun?: boolean): SleepResult;
|
|
53
|
+
sleepAllSessions(dryRun?: boolean): SleepResult;
|
|
54
|
+
getConsolidationLog(limit?: number): unknown[];
|
|
55
|
+
exportToDict(): Record<string, unknown>;
|
|
56
|
+
importFromDict(data: Record<string, unknown>, force?: boolean): ImportStats;
|
|
57
|
+
protected emitEvent(type: string, data?: Omit<BeamEvent, "type" | "sessionId" | "timestamp">): void;
|
|
58
|
+
protected metadataJson(metadata: Metadata | null | undefined): string | null;
|
|
59
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BeamMemoryState, RecallEnhancedOptions, RecallOptions, RecallResult } from "./types.js";
|
|
2
|
+
type RecallOptionsInternal = RecallOptions & {
|
|
3
|
+
source?: string | null;
|
|
4
|
+
topic?: string | null;
|
|
5
|
+
veracity?: string | null;
|
|
6
|
+
memoryType?: string | null;
|
|
7
|
+
temporalWeight?: number;
|
|
8
|
+
temporalHalflife?: number;
|
|
9
|
+
vecWeight?: number;
|
|
10
|
+
ftsWeight?: number;
|
|
11
|
+
importanceWeight?: number;
|
|
12
|
+
queryEmbedding?: readonly number[] | null;
|
|
13
|
+
useSynonyms?: boolean;
|
|
14
|
+
useIntent?: boolean;
|
|
15
|
+
useMmr?: boolean;
|
|
16
|
+
mmrLambda?: number;
|
|
17
|
+
ignoreSessionScope?: boolean;
|
|
18
|
+
currentSensitive?: boolean;
|
|
19
|
+
updateRecallCounts?: boolean;
|
|
20
|
+
};
|
|
21
|
+
type FactRecallResult = RecallResult & {
|
|
22
|
+
fact_id?: string;
|
|
23
|
+
subject?: string;
|
|
24
|
+
predicate?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Default per-result content preview cap enforced by {@link recall}. Content
|
|
28
|
+
* longer than this is clipped and the last character replaced with `…` so
|
|
29
|
+
* callers see the truncation; the full row remains reachable via
|
|
30
|
+
* `Mnemopi.get()` (and, in the coding-agent, `memory://<id>`). Overridable per
|
|
31
|
+
* call via {@link RecallOptions.contentPreviewChars}.
|
|
32
|
+
*/
|
|
33
|
+
export declare const RECALL_CONTENT_PREVIEW_CHARS = 500;
|
|
34
|
+
/**
|
|
35
|
+
* Clip `content` to at most `limit` characters, replacing the tail with `…`
|
|
36
|
+
* when truncated so agents can distinguish a preview from a full row. Returns
|
|
37
|
+
* the original string (and `truncated: false`) when the limit is 0/negative or
|
|
38
|
+
* the content already fits. The single `…` occupies one character of the cap,
|
|
39
|
+
* so a 500-char cap yields at most 499 real characters plus the marker.
|
|
40
|
+
*/
|
|
41
|
+
export declare function clipRecallContent(content: string, limit?: number): {
|
|
42
|
+
content: string;
|
|
43
|
+
truncated: boolean;
|
|
44
|
+
fullLength: number;
|
|
45
|
+
};
|
|
46
|
+
export declare function parseQueryTime(value: RecallOptionsInternal["queryTime"]): Date;
|
|
47
|
+
export declare function temporalBoost(timestamp: unknown, queryTime: Date, halfLifeHours: number): number;
|
|
48
|
+
export declare function recall(beam: BeamMemoryState, query: string, topK?: number, options?: RecallOptionsInternal): Promise<RecallResult[]>;
|
|
49
|
+
export declare function recallEnhanced(beam: BeamMemoryState, query: string, topK?: number, options?: RecallEnhancedOptions & RecallOptionsInternal): Promise<RecallResult[]>;
|
|
50
|
+
export declare function formatContext(beam: BeamMemoryState, results: readonly RecallResult[], format?: string): string;
|
|
51
|
+
export declare function factRecall(beam: BeamMemoryState, query: string, topK?: number): FactRecallResult[];
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { BeamMemoryState, BeamStats, ImportStats, RememberBatchItem, RememberBatchOptions, RememberOptions } from "./types.js";
|
|
2
|
+
type Row = Record<string, unknown>;
|
|
3
|
+
type StoreRememberOptions = RememberOptions & {
|
|
4
|
+
memoryId?: string;
|
|
5
|
+
memory_id?: string;
|
|
6
|
+
validUntil?: string | null;
|
|
7
|
+
valid_until?: string | null;
|
|
8
|
+
authorId?: string | null;
|
|
9
|
+
author_id?: string | null;
|
|
10
|
+
authorType?: string | null;
|
|
11
|
+
author_type?: string | null;
|
|
12
|
+
extractEntities?: boolean;
|
|
13
|
+
extract_entities?: boolean;
|
|
14
|
+
extract_text?: string;
|
|
15
|
+
embed_text?: string;
|
|
16
|
+
channelId?: string | null;
|
|
17
|
+
channel_id?: string | null;
|
|
18
|
+
};
|
|
19
|
+
type StoreRememberBatchOptions = RememberBatchOptions & {
|
|
20
|
+
forceVeracity?: boolean;
|
|
21
|
+
force_veracity?: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Reconcile stored embeddings against the active embedding model at store open.
|
|
25
|
+
*
|
|
26
|
+
* Every `memory_embeddings` row is stamped with the model that produced it (see
|
|
27
|
+
* `runEmbedding` in `helpers.ts`). When the configured embedding model changes,
|
|
28
|
+
* its vector dimension changes too, so the previously-stored vectors are no
|
|
29
|
+
* longer comparable. On a mismatch we wipe every stored vector — the
|
|
30
|
+
* `memory_embeddings` table, the `episodic_memory.binary_vector` column, and the
|
|
31
|
+
* sqlite-vec `vec_episodes` index — then enqueue all live memories for
|
|
32
|
+
* background re-embedding under the new model via `scheduleEmbedding`.
|
|
33
|
+
*
|
|
34
|
+
* Runs once per store open; a fresh store (no embeddings) or an already-current
|
|
35
|
+
* store is a no-op. The destructive wipe is skipped whenever it could not be
|
|
36
|
+
* rebuilt — embeddings disabled via the runtime option OR the
|
|
37
|
+
* `MNEMOPI_NO_EMBEDDINGS` env, or an unresolved (empty) active model — so a
|
|
38
|
+
* stale-but-valid corpus is never destroyed without a replacement. MUST run
|
|
39
|
+
* inside the active runtime-options scope so `currentEmbeddingModel()` /
|
|
40
|
+
* `embeddingsDisabled()` reflect the per-instance configuration.
|
|
41
|
+
*/
|
|
42
|
+
export declare function reconcileEmbeddingModel(beam: BeamMemoryState): void;
|
|
43
|
+
export declare function remember(beam: BeamMemoryState, content: string, options?: StoreRememberOptions): string;
|
|
44
|
+
export declare function rememberBatch(beam: BeamMemoryState, items: readonly RememberBatchItem[], options?: StoreRememberBatchOptions): string[];
|
|
45
|
+
export declare function getContext(beam: BeamMemoryState, limit?: number): Row[];
|
|
46
|
+
export declare function invalidate(beam: BeamMemoryState, memoryId: string, replacementId?: string | null): boolean;
|
|
47
|
+
export declare function getWorkingStats(beam: BeamMemoryState, authorId?: string | null, authorType?: string | null, channelId?: string | null): BeamStats;
|
|
48
|
+
export declare function getGlobalWorkingStats(beam: BeamMemoryState): BeamStats;
|
|
49
|
+
export declare function updateWorking(beam: BeamMemoryState, memoryId: string, content?: string | null, importance?: number | null): boolean;
|
|
50
|
+
export declare function get(beam: BeamMemoryState, memoryId: string): Row | null;
|
|
51
|
+
export declare function forgetWorking(beam: BeamMemoryState, memoryId: string): boolean;
|
|
52
|
+
export declare function scratchpadWrite(beam: BeamMemoryState, content: string): string;
|
|
53
|
+
export declare function scratchpadRead(beam: BeamMemoryState): Row[];
|
|
54
|
+
export declare function scratchpadClear(beam: BeamMemoryState): void;
|
|
55
|
+
export declare function exportToDict(beam: BeamMemoryState): Record<string, unknown>;
|
|
56
|
+
export declare function importFromDict(beam: BeamMemoryState, data: Record<string, unknown>, force?: boolean): ImportStats;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
3
|
+
export type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
export type Metadata = Record<string, JsonValue>;
|
|
7
|
+
export type MemoryScope = "global" | "session" | "channel" | string;
|
|
8
|
+
export type TrustTier = "STATED" | "OBSERVED" | "INFERRED" | "SYSTEM" | string;
|
|
9
|
+
export type Veracity = "unknown" | "likely_true" | "true" | "false" | "stated" | "inferred" | "tool" | "imported" | "contested" | string;
|
|
10
|
+
export interface BeamPluginManager {
|
|
11
|
+
emit?(event: BeamEvent): void | Promise<void>;
|
|
12
|
+
close?(): void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface AnnotationStoreLike {
|
|
15
|
+
add?(memoryId: string, kind: string, value: string, options?: AnnotationWriteOptions): unknown;
|
|
16
|
+
addMany?(memoryId: string, kind: string, values: readonly string[], options?: AnnotationWriteOptions): unknown;
|
|
17
|
+
queryByMemory?(memoryId: string, kind?: string): unknown;
|
|
18
|
+
queryByKind?(kind: string, value?: string): unknown;
|
|
19
|
+
getDistinctValues?(kind: string): string[];
|
|
20
|
+
}
|
|
21
|
+
export interface TripleStoreLike {
|
|
22
|
+
add?(subject: string, predicate: string, object: string, options?: TripleWriteOptions): unknown;
|
|
23
|
+
query?(subject?: string, predicate?: string, asOf?: string): unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface BeamCaches {
|
|
26
|
+
timestampParse: Map<string, Date>;
|
|
27
|
+
polyphonicEngine?: unknown;
|
|
28
|
+
extractionClient?: unknown;
|
|
29
|
+
extractionBuffer: unknown[];
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
export interface BeamConfig {
|
|
33
|
+
workingMemoryLimit: number;
|
|
34
|
+
workingMemoryTtlHours: number;
|
|
35
|
+
recencyHalflifeHours: number;
|
|
36
|
+
vecWeight: number;
|
|
37
|
+
ftsWeight: number;
|
|
38
|
+
importanceWeight: number;
|
|
39
|
+
useCloud: boolean;
|
|
40
|
+
localLlmEnabled: boolean;
|
|
41
|
+
maxEpisodeChars: number;
|
|
42
|
+
proactiveLinking?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface BeamMemoryOptions {
|
|
45
|
+
sessionId?: string;
|
|
46
|
+
dbPath?: string;
|
|
47
|
+
authorId?: string | null;
|
|
48
|
+
authorType?: string | null;
|
|
49
|
+
channelId?: string | null;
|
|
50
|
+
useCloud?: boolean;
|
|
51
|
+
proactiveLinking?: boolean;
|
|
52
|
+
eventEmitter?: (event: BeamEvent) => void;
|
|
53
|
+
pluginManager?: BeamPluginManager | null;
|
|
54
|
+
annotations?: AnnotationStoreLike | null;
|
|
55
|
+
triples?: TripleStoreLike | null;
|
|
56
|
+
config?: Partial<BeamConfig>;
|
|
57
|
+
}
|
|
58
|
+
export interface BeamMemoryState {
|
|
59
|
+
db: Database;
|
|
60
|
+
dbPath?: string;
|
|
61
|
+
sessionId: string;
|
|
62
|
+
authorId: string | null;
|
|
63
|
+
authorType: string | null;
|
|
64
|
+
channelId: string;
|
|
65
|
+
useCloud: boolean;
|
|
66
|
+
eventEmitter?: (event: BeamEvent) => void;
|
|
67
|
+
pluginManager: BeamPluginManager | null;
|
|
68
|
+
annotations: AnnotationStoreLike | null;
|
|
69
|
+
triples: TripleStoreLike | null;
|
|
70
|
+
episodicGraph: unknown | null;
|
|
71
|
+
veracityConsolidator: unknown | null;
|
|
72
|
+
caches: BeamCaches;
|
|
73
|
+
config: BeamConfig;
|
|
74
|
+
/** Tracks in-flight background fact-extraction tasks scheduled by `remember(..., { extract: true })`. */
|
|
75
|
+
pendingExtractions?: Set<Promise<void>>;
|
|
76
|
+
}
|
|
77
|
+
export interface AnnotationWriteOptions {
|
|
78
|
+
source?: string;
|
|
79
|
+
confidence?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface TripleWriteOptions {
|
|
82
|
+
validFrom?: string;
|
|
83
|
+
source?: string;
|
|
84
|
+
confidence?: number;
|
|
85
|
+
}
|
|
86
|
+
export interface BeamEvent {
|
|
87
|
+
type: string;
|
|
88
|
+
memoryId?: string;
|
|
89
|
+
content?: string;
|
|
90
|
+
source?: string;
|
|
91
|
+
importance?: number;
|
|
92
|
+
sessionId: string;
|
|
93
|
+
timestamp: string;
|
|
94
|
+
metadata?: Metadata;
|
|
95
|
+
}
|
|
96
|
+
export interface RememberOptions {
|
|
97
|
+
source?: string;
|
|
98
|
+
importance?: number;
|
|
99
|
+
metadata?: Metadata | null;
|
|
100
|
+
extract?: boolean;
|
|
101
|
+
extractEntities?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Override the text passed to fact and graph extraction. When unset
|
|
104
|
+
* (default) extraction runs over the stored `content`. Use this when the
|
|
105
|
+
* stored memory is a multi-author transcript but only a subset (e.g. the
|
|
106
|
+
* user-authored turns) should drive deterministic fact extraction — see
|
|
107
|
+
* coding-agent issue #3372 where assistant prose was being mis-attributed
|
|
108
|
+
* as user `Instruction:` memories.
|
|
109
|
+
*/
|
|
110
|
+
extractText?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Override the text passed to embeddings and FTS indexing. Stored `content`
|
|
113
|
+
* remains unchanged; when unset, embeddings and FTS use `content`.
|
|
114
|
+
*/
|
|
115
|
+
embedText?: string;
|
|
116
|
+
veracity?: Veracity;
|
|
117
|
+
memoryType?: string;
|
|
118
|
+
scope?: MemoryScope;
|
|
119
|
+
trustTier?: TrustTier;
|
|
120
|
+
timestamp?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface RememberBatchOptions {
|
|
123
|
+
extract?: boolean;
|
|
124
|
+
extractEntities?: boolean;
|
|
125
|
+
veracity?: Veracity;
|
|
126
|
+
memoryType?: string;
|
|
127
|
+
scope?: MemoryScope;
|
|
128
|
+
trustTier?: TrustTier;
|
|
129
|
+
}
|
|
130
|
+
export interface RememberBatchItem extends RememberOptions {
|
|
131
|
+
content: string;
|
|
132
|
+
}
|
|
133
|
+
export interface RecallOptions {
|
|
134
|
+
fromDate?: string | null;
|
|
135
|
+
toDate?: string | null;
|
|
136
|
+
authorId?: string | null;
|
|
137
|
+
authorType?: string | null;
|
|
138
|
+
channelId?: string | null;
|
|
139
|
+
includeWorking?: boolean;
|
|
140
|
+
queryTime?: string | Date | null;
|
|
141
|
+
temporalWeight?: number;
|
|
142
|
+
temporalHalflife?: number;
|
|
143
|
+
vecWeight?: number;
|
|
144
|
+
ftsWeight?: number;
|
|
145
|
+
importanceWeight?: number;
|
|
146
|
+
queryEmbedding?: readonly number[] | null;
|
|
147
|
+
useSynonyms?: boolean;
|
|
148
|
+
useIntent?: boolean;
|
|
149
|
+
useMmr?: boolean;
|
|
150
|
+
mmrLambda?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Maximum characters of `content` returned per {@link RecallResult}. When the
|
|
153
|
+
* stored content exceeds this, the preview is clipped and the trailing
|
|
154
|
+
* character is replaced with `…` so callers can see it was truncated. The
|
|
155
|
+
* full row is always reachable via {@link BeamMemoryState.get}. `0` or a
|
|
156
|
+
* negative value disables clipping. Defaults to
|
|
157
|
+
* {@link RECALL_CONTENT_PREVIEW_CHARS} (500).
|
|
158
|
+
*/
|
|
159
|
+
contentPreviewChars?: number;
|
|
160
|
+
}
|
|
161
|
+
export interface RecallEnhancedOptions extends RecallOptions {
|
|
162
|
+
useCache?: boolean;
|
|
163
|
+
includeFacts?: boolean;
|
|
164
|
+
}
|
|
165
|
+
export interface MemoryRow {
|
|
166
|
+
id: string;
|
|
167
|
+
content: string;
|
|
168
|
+
source: string | null;
|
|
169
|
+
timestamp: string | null;
|
|
170
|
+
session_id: string;
|
|
171
|
+
importance: number;
|
|
172
|
+
metadata_json: string | null;
|
|
173
|
+
veracity: Veracity;
|
|
174
|
+
memory_type?: string | null;
|
|
175
|
+
recall_count?: number;
|
|
176
|
+
last_recalled?: string | null;
|
|
177
|
+
valid_until?: string | null;
|
|
178
|
+
superseded_by?: string | null;
|
|
179
|
+
scope?: MemoryScope;
|
|
180
|
+
author_id?: string | null;
|
|
181
|
+
author_type?: string | null;
|
|
182
|
+
channel_id?: string | null;
|
|
183
|
+
trust_tier?: TrustTier;
|
|
184
|
+
validator?: string | null;
|
|
185
|
+
validated_at?: string | null;
|
|
186
|
+
validation_count?: number;
|
|
187
|
+
event_date?: string | null;
|
|
188
|
+
event_date_precision?: string | null;
|
|
189
|
+
temporal_tags?: string | null;
|
|
190
|
+
corrected_by?: number | null;
|
|
191
|
+
created_at: string;
|
|
192
|
+
}
|
|
193
|
+
export interface WorkingMemoryRow extends MemoryRow {
|
|
194
|
+
consolidated_at?: string | null;
|
|
195
|
+
}
|
|
196
|
+
export interface EpisodicMemoryRow extends MemoryRow {
|
|
197
|
+
rowid: number;
|
|
198
|
+
summary_of: string;
|
|
199
|
+
tier: number;
|
|
200
|
+
degraded_at?: string | null;
|
|
201
|
+
binary_vector?: Uint8Array | null;
|
|
202
|
+
}
|
|
203
|
+
export type RecallTierLabel = "working" | "episodic" | "fact" | string;
|
|
204
|
+
export interface RecallVoiceScores {
|
|
205
|
+
vec?: number;
|
|
206
|
+
fts?: number;
|
|
207
|
+
keyword?: number;
|
|
208
|
+
importance?: number;
|
|
209
|
+
recency_decay?: number;
|
|
210
|
+
temporal?: number;
|
|
211
|
+
[key: string]: number | undefined;
|
|
212
|
+
}
|
|
213
|
+
type RecallRowFields = Omit<Partial<EpisodicMemoryRow>, "tier"> & Partial<WorkingMemoryRow>;
|
|
214
|
+
export type RecallResult = RecallRowFields & {
|
|
215
|
+
[key: string]: unknown;
|
|
216
|
+
id: string;
|
|
217
|
+
content: string;
|
|
218
|
+
/**
|
|
219
|
+
* True when {@link content} is a clipped preview of the stored row. The
|
|
220
|
+
* clip is capped at {@link RecallOptions.contentPreviewChars} (default 500)
|
|
221
|
+
* and the last character is replaced with `…`. Fetch the full row via
|
|
222
|
+
* `memory://<id>` (mnemopi backend) or the `Mnemopi.get(id)` API.
|
|
223
|
+
*/
|
|
224
|
+
truncated?: boolean;
|
|
225
|
+
/** Original character count of `content` before {@link truncated} clipping. */
|
|
226
|
+
full_length?: number;
|
|
227
|
+
score?: number;
|
|
228
|
+
distance?: number;
|
|
229
|
+
rank?: number;
|
|
230
|
+
tier?: RecallTierLabel;
|
|
231
|
+
tier_label?: RecallTierLabel;
|
|
232
|
+
degradation_tier?: number;
|
|
233
|
+
keyword_score?: number;
|
|
234
|
+
dense_score?: number;
|
|
235
|
+
fts_score?: number;
|
|
236
|
+
importance_score?: number;
|
|
237
|
+
recency_score?: number;
|
|
238
|
+
temporal_score?: number;
|
|
239
|
+
explanation?: string;
|
|
240
|
+
voice_scores?: RecallVoiceScores;
|
|
241
|
+
metadata?: Metadata;
|
|
242
|
+
};
|
|
243
|
+
export interface BeamStats {
|
|
244
|
+
count: number;
|
|
245
|
+
by_source?: Record<string, number>;
|
|
246
|
+
by_session?: Record<string, number>;
|
|
247
|
+
oldest?: string | null;
|
|
248
|
+
newest?: string | null;
|
|
249
|
+
[key: string]: JsonValue | Record<string, number> | undefined;
|
|
250
|
+
}
|
|
251
|
+
export interface MemoriaRetrieveResult {
|
|
252
|
+
ability: string;
|
|
253
|
+
query: string;
|
|
254
|
+
results: unknown[];
|
|
255
|
+
}
|
|
256
|
+
export interface SleepResult {
|
|
257
|
+
dry_run: boolean;
|
|
258
|
+
sessions?: Record<string, unknown>;
|
|
259
|
+
items_consolidated?: number;
|
|
260
|
+
[key: string]: unknown;
|
|
261
|
+
}
|
|
262
|
+
export interface ImportStats {
|
|
263
|
+
working_memory: Record<string, number>;
|
|
264
|
+
episodic_memory: Record<string, number>;
|
|
265
|
+
scratchpad: Record<string, number>;
|
|
266
|
+
consolidation_log: Record<string, number>;
|
|
267
|
+
}
|
|
268
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { type VecType } from "../config.js";
|
|
3
|
+
import { type DatabasePath } from "../db.js";
|
|
4
|
+
export { cosineSimilarity } from "./vector-math.js";
|
|
5
|
+
export declare const BITS_PER_BYTE = 8;
|
|
6
|
+
export declare const EMBEDDING_DIM: number;
|
|
7
|
+
export declare const BYTES_PER_VECTOR: number;
|
|
8
|
+
export interface BinaryVectorSearchResult {
|
|
9
|
+
memory_id: string;
|
|
10
|
+
distance: number;
|
|
11
|
+
score: number;
|
|
12
|
+
}
|
|
13
|
+
export interface BinaryVectorStats {
|
|
14
|
+
total_vectors: number;
|
|
15
|
+
avg_bytes_per_vector: number;
|
|
16
|
+
max_bytes: number;
|
|
17
|
+
min_bytes: number;
|
|
18
|
+
compression_ratio: number;
|
|
19
|
+
theoretical_size_mb: number;
|
|
20
|
+
}
|
|
21
|
+
export interface BinaryVectorStoreOptions {
|
|
22
|
+
dbPath?: DatabasePath;
|
|
23
|
+
tableName?: string;
|
|
24
|
+
conn?: Database;
|
|
25
|
+
}
|
|
26
|
+
export declare function getVecType(env?: NodeJS.ProcessEnv): VecType;
|
|
27
|
+
export declare const VEC_TYPE: VecType;
|
|
28
|
+
export declare function quantizeInt8(embedding: readonly number[]): Int8Array;
|
|
29
|
+
export declare function maximallyInformativeBinarization(embedding: readonly number[]): Uint8Array;
|
|
30
|
+
export declare function hammingDistance(binaryA: Uint8Array | ArrayBuffer, binaryB: Uint8Array | ArrayBuffer): number;
|
|
31
|
+
export declare function informationTheoreticScore(distance: number, dim?: number): number;
|
|
32
|
+
export declare class BinaryVectorStore {
|
|
33
|
+
readonly conn: Database;
|
|
34
|
+
readonly dbPath: DatabasePath;
|
|
35
|
+
readonly tableName: string;
|
|
36
|
+
private readonly ownsConnection;
|
|
37
|
+
constructor(options?: BinaryVectorStoreOptions);
|
|
38
|
+
private initTable;
|
|
39
|
+
static maximallyInformativeBinarization(embedding: readonly number[]): Uint8Array;
|
|
40
|
+
static hammingDistance(binaryA: Uint8Array | ArrayBuffer, binaryB: Uint8Array | ArrayBuffer): number;
|
|
41
|
+
static informationTheoreticScore(distance: number, dim?: number): number;
|
|
42
|
+
storeVector(memoryId: string, embedding: readonly number[]): void;
|
|
43
|
+
search(queryEmbedding: readonly number[], topK?: number): BinaryVectorSearchResult[];
|
|
44
|
+
searchBatch(queryEmbeddings: readonly (readonly number[])[], topK?: number): BinaryVectorSearchResult[][];
|
|
45
|
+
deleteVector(memoryId: string): void;
|
|
46
|
+
getStats(): BinaryVectorStats;
|
|
47
|
+
close(): void;
|
|
48
|
+
}
|
|
49
|
+
export declare class FastBinarySearch {
|
|
50
|
+
private readonly memoryIds;
|
|
51
|
+
private readonly vectors;
|
|
52
|
+
constructor(binaryVectors: ReadonlyMap<string, Uint8Array | ArrayBuffer> | Record<string, Uint8Array | ArrayBuffer>);
|
|
53
|
+
search(queryBinary: Uint8Array | ArrayBuffer, topK?: number): BinaryVectorSearchResult[];
|
|
54
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type ExtractionRate = {
|
|
2
|
+
total: number;
|
|
3
|
+
survived: number;
|
|
4
|
+
dropped: number;
|
|
5
|
+
rate: number;
|
|
6
|
+
dropped_samples: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare function normalizeChat(text: string, options?: {
|
|
9
|
+
add_implicit_subjects?: boolean;
|
|
10
|
+
}): string | null;
|
|
11
|
+
export declare function normalizeBatch(messages: string[]): (string | null)[];
|
|
12
|
+
export declare function extractionRate(messages: string[]): ExtractionRate;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const SIZE_HARD_CAP = 1000000;
|
|
2
|
+
export declare const SIZE_BASE64_CHECK = 100000;
|
|
3
|
+
export declare const ENTROPY_THRESHOLD = 5;
|
|
4
|
+
export interface BlobMetadata {
|
|
5
|
+
blob_ref?: string;
|
|
6
|
+
original_size?: number;
|
|
7
|
+
mime?: string;
|
|
8
|
+
extraction_reason?: "data_uri" | "size_cap" | "high_entropy";
|
|
9
|
+
entropy?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function blobRoot(env?: NodeJS.ProcessEnv): string;
|
|
12
|
+
export declare function computeSha256(data: Uint8Array | string): string;
|
|
13
|
+
export declare function isDataUri(content: string): boolean;
|
|
14
|
+
export declare function parseDataUri(content: string): [mimeType: string, raw: Buffer] | null;
|
|
15
|
+
export declare function shannonEntropy(text: string): number;
|
|
16
|
+
export declare function looksLikeBase64Blob(content: string): boolean;
|
|
17
|
+
export declare function storeBlob(rawBytes: Uint8Array): string;
|
|
18
|
+
export declare function sanitizeContent(content: string): [sanitizedContent: string, blobMetadata: BlobMetadata];
|