@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,13 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
export declare const DEFAULT_LOG_DIR: string;
|
|
3
|
+
export declare const DEFAULT_LOG_DB: string;
|
|
4
|
+
export interface CostStats {
|
|
5
|
+
total_calls: number;
|
|
6
|
+
total_memories_injected: number;
|
|
7
|
+
total_tokens: number;
|
|
8
|
+
total_estimated_cost_usd: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function getConn(dbPath?: string): Database;
|
|
11
|
+
export declare function initCostLog(dbPath?: string): void;
|
|
12
|
+
export declare function logCost(sessionId: string, memoryCount: number, tokenCount: number, estimatedCostUsd: number, model?: string, dbPath?: string): void;
|
|
13
|
+
export declare function getCostStats(sessionId?: string, dbPath?: string): CostStats;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { EmbeddingModel } from "fastembed";
|
|
2
|
+
import { type EmbeddingOutput } from "./runtime-options.js";
|
|
3
|
+
export type { EmbeddingOutput } from "./runtime-options.js";
|
|
4
|
+
export { cosineSimilarity } from "./vector-math.js";
|
|
5
|
+
export type Vector = Float32Array;
|
|
6
|
+
export type EmbeddingMatrix = Vector[];
|
|
7
|
+
export interface EmbeddingProvider {
|
|
8
|
+
embed(texts: readonly string[]): EmbeddingOutput | Promise<EmbeddingOutput>;
|
|
9
|
+
available?(): boolean | Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
export type StandardEmbeddingModel = Exclude<EmbeddingModel, EmbeddingModel.CUSTOM>;
|
|
12
|
+
export interface LocalEmbeddingModel {
|
|
13
|
+
embed(texts: string[], batchSize?: number): EmbeddingOutput;
|
|
14
|
+
queryEmbed?(query: string): Promise<number[]>;
|
|
15
|
+
}
|
|
16
|
+
export type LocalModelInitOptions = {
|
|
17
|
+
model: StandardEmbeddingModel;
|
|
18
|
+
cacheDir?: string;
|
|
19
|
+
showDownloadProgress?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type LocalModelInitializer = (options: LocalModelInitOptions) => Promise<LocalEmbeddingModel>;
|
|
22
|
+
/**
|
|
23
|
+
* Quarantine the exact ONNX file named by a "Protobuf parsing failed" init
|
|
24
|
+
* error. A truncated cached model blocks local embeddings forever: the
|
|
25
|
+
* downloader treats the existing file as complete, so every init re-parses
|
|
26
|
+
* the same broken bytes. The extracted path is error-message CONTENT, so it
|
|
27
|
+
* is only honored when it resolves inside the fastembed cache directory —
|
|
28
|
+
* never rename an arbitrary file a dependency happens to mention. Atomic
|
|
29
|
+
* rename; losing a concurrent-heal race (file already renamed/removed)
|
|
30
|
+
* still returns true because a retry is safe either way.
|
|
31
|
+
* @internal exported for tests
|
|
32
|
+
*/
|
|
33
|
+
export declare function quarantineCorruptModelFile(message: string, cacheDir?: string): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Recover from a partially-extracted fastembed model cache. An interrupted
|
|
36
|
+
* archive download/extraction leaves `<cacheDir>/<model>/` populated with
|
|
37
|
+
* sidecars and a truncated `model.onnx_data` but WITHOUT the graph file
|
|
38
|
+
* (`model.onnx` / `model_optimized.onnx`), so `FlagEmbedding.init` throws
|
|
39
|
+
* `Model file not found at .../model.onnx`. Upstream `retrieveModel`
|
|
40
|
+
* short-circuits on the existing model dir and never re-downloads, and
|
|
41
|
+
* `downloadFileFromGCS` reuses a leftover partial `<model>.tar.gz` as-is, so
|
|
42
|
+
* the cache is stuck broken forever: recall silently dies and the rebuild
|
|
43
|
+
* queue grows every session. Delete the incomplete model dir AND the leftover
|
|
44
|
+
* partial archive so the retry re-downloads from scratch. The model path is
|
|
45
|
+
* error-message CONTENT, so the dir is only removed when it is a direct child
|
|
46
|
+
* of the fastembed cache root — never touch a directory a dependency merely
|
|
47
|
+
* names. Returns true when a retry is worth attempting (the incomplete cache
|
|
48
|
+
* was cleared, or already gone from a concurrent heal).
|
|
49
|
+
* @internal exported for tests
|
|
50
|
+
*/
|
|
51
|
+
export declare function clearIncompleteModelCache(message: string, cacheDir?: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Shared local-model initializer: FlagEmbedding.init with BOTH cache heals.
|
|
54
|
+
* Missing sidecars (config/tokenizer/tokens map) re-fetch and retry; a
|
|
55
|
+
* corrupt model blob (Protobuf parse failure) quarantines the file and
|
|
56
|
+
* retries THROUGH the sidecar heal, so a cache that is broken in both ways
|
|
57
|
+
* still recovers in one pass. Also the initializer the embed worker uses in
|
|
58
|
+
* its subprocess; the in-process seam stays {@link setLocalModelInitializer}.
|
|
59
|
+
*/
|
|
60
|
+
export declare function defaultLocalModelInitializer(options: LocalModelInitOptions): Promise<LocalEmbeddingModel>;
|
|
61
|
+
export declare function embeddingsDisabled(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the embedding model name for the currently active runtime scope.
|
|
64
|
+
*
|
|
65
|
+
* Reads (in order): the active provider's `model` from `withMnemopiRuntimeOptions`,
|
|
66
|
+
* the `MNEMOPI_EMBEDDING_MODEL` env var, then the bundled fastembed default. Stored
|
|
67
|
+
* alongside each row in `memory_embeddings.model` so migrations can re-embed when
|
|
68
|
+
* the active model changes.
|
|
69
|
+
*/
|
|
70
|
+
export declare function currentEmbeddingModel(): string;
|
|
71
|
+
export declare function isApiModel(modelName: string): boolean;
|
|
72
|
+
export declare function embeddingDimFor(modelName: string): number;
|
|
73
|
+
export declare function setEmbeddingProviderForTests(provider: EmbeddingProvider | null | undefined): void;
|
|
74
|
+
export declare const setEmbeddingProvider: typeof setEmbeddingProviderForTests;
|
|
75
|
+
export declare function setLocalModelInitializerForTests(initializer: LocalModelInitializer | null | undefined): void;
|
|
76
|
+
/**
|
|
77
|
+
* Override the function used to construct the local fastembed model the next
|
|
78
|
+
* time `embed()` is called. Lets a host (e.g. the agent CLI) keep
|
|
79
|
+
* `onnxruntime-node` out of its own address space by routing every fastembed
|
|
80
|
+
* load + inference through a dedicated subprocess. Same wipe semantics as the
|
|
81
|
+
* `*ForTests` form: clears the cached model promise and the query cache so
|
|
82
|
+
* subsequent embeds run through the new initializer immediately.
|
|
83
|
+
*/
|
|
84
|
+
export declare const setLocalModelInitializer: typeof setLocalModelInitializerForTests;
|
|
85
|
+
export declare function resetEmbeddingProviderForTests(): void;
|
|
86
|
+
export declare const resetEmbeddingStateForTests: typeof resetEmbeddingProviderForTests;
|
|
87
|
+
export declare function available(): Promise<boolean>;
|
|
88
|
+
export declare function availableApi(): boolean;
|
|
89
|
+
export declare function embedQuery(text: string): Promise<Vector | null>;
|
|
90
|
+
export declare function embed(texts: readonly string[]): Promise<EmbeddingMatrix | null>;
|
|
91
|
+
export declare function getEmbeddingApiCallCountForTests(): number;
|
|
92
|
+
export declare const DEFAULT_MODEL: string;
|
|
93
|
+
export declare const EMBEDDING_DIM: number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const ENTITY_EXTRACTION_STOP_WORDS: ReadonlySet<string>;
|
|
2
|
+
/** Maximum raw text size for regex-only entity extraction. */
|
|
3
|
+
export declare const REGEX_EXTRACTION_MAX_INPUT_CHARS = 50000;
|
|
4
|
+
export declare function levenshteinDistance(s1: string, s2: string): number;
|
|
5
|
+
export declare function similarity(s1: string, s2: string): number;
|
|
6
|
+
export declare function extractEntitiesRegex(text: string): string[];
|
|
7
|
+
export type SimilarEntity = readonly [entity: string, score: number];
|
|
8
|
+
export declare function findSimilarEntities(entity: string, knownEntities: readonly string[], threshold?: number): SimilarEntity[];
|
|
9
|
+
export declare function entityExtractionPerformance(text: string, iterations?: number): number;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { type DatabasePath } from "../db.js";
|
|
3
|
+
export interface Gist {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly text: string;
|
|
6
|
+
readonly timestamp: string;
|
|
7
|
+
readonly participants: readonly string[];
|
|
8
|
+
readonly location: string | null;
|
|
9
|
+
readonly emotion: string | null;
|
|
10
|
+
readonly timeScope: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface Fact {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly subject: string;
|
|
15
|
+
readonly predicate: string;
|
|
16
|
+
readonly object: string;
|
|
17
|
+
readonly timestamp: string;
|
|
18
|
+
readonly confidence: number;
|
|
19
|
+
readonly temporalQualifier?: string | null;
|
|
20
|
+
}
|
|
21
|
+
export interface GraphEdge {
|
|
22
|
+
readonly source: string;
|
|
23
|
+
readonly target: string;
|
|
24
|
+
readonly edgeType: string;
|
|
25
|
+
readonly weight: number;
|
|
26
|
+
readonly timestamp: string;
|
|
27
|
+
}
|
|
28
|
+
export interface RelatedMemory {
|
|
29
|
+
readonly memoryId: string;
|
|
30
|
+
readonly edgeType: string;
|
|
31
|
+
readonly weight: number;
|
|
32
|
+
readonly depth: number;
|
|
33
|
+
}
|
|
34
|
+
export interface GraphStats {
|
|
35
|
+
readonly gists: number;
|
|
36
|
+
readonly facts: number;
|
|
37
|
+
readonly edges: number;
|
|
38
|
+
readonly totalNodes: number;
|
|
39
|
+
}
|
|
40
|
+
export interface IngestOptions {
|
|
41
|
+
readonly sessionId?: string;
|
|
42
|
+
readonly linkExisting?: boolean;
|
|
43
|
+
readonly minLinkScore?: number;
|
|
44
|
+
readonly extractEntities?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface IngestResult {
|
|
47
|
+
readonly memoryId: string;
|
|
48
|
+
readonly gist: Gist;
|
|
49
|
+
readonly facts: readonly Fact[];
|
|
50
|
+
readonly edges: readonly GraphEdge[];
|
|
51
|
+
}
|
|
52
|
+
export interface EpisodicGraphOptions {
|
|
53
|
+
readonly db?: Database;
|
|
54
|
+
readonly dbPath?: DatabasePath;
|
|
55
|
+
}
|
|
56
|
+
export declare class EpisodicGraph {
|
|
57
|
+
readonly db: Database;
|
|
58
|
+
readonly dbPath: DatabasePath;
|
|
59
|
+
readonly ownsConnection: boolean;
|
|
60
|
+
constructor(options?: EpisodicGraphOptions);
|
|
61
|
+
private initTables;
|
|
62
|
+
extractGist(content: string, memoryId: string): Gist;
|
|
63
|
+
extractFacts(content: string, memoryId: string): Fact[];
|
|
64
|
+
storeGist(gist: Gist, memoryId: string): void;
|
|
65
|
+
getGist(id: string): Gist | null;
|
|
66
|
+
storeFact(fact: Fact, memoryId: string, sessionId?: string): void;
|
|
67
|
+
getFact(id: string): Fact | null;
|
|
68
|
+
addEdge(edge: GraphEdge): void;
|
|
69
|
+
getEdges(source?: string | null): GraphEdge[];
|
|
70
|
+
findRelatedMemories(memoryId: string, depth?: number, edgeType?: string, minWeight?: number): RelatedMemory[];
|
|
71
|
+
findFactsBySubject(subject: string): Fact[];
|
|
72
|
+
findGistsByParticipant(participant: string): Gist[];
|
|
73
|
+
scoreMemoryLink(sourceMemoryId: string, targetMemoryId: string): number;
|
|
74
|
+
ingestMemory(content: string, memoryId: string, options?: IngestOptions): IngestResult;
|
|
75
|
+
getStats(): GraphStats;
|
|
76
|
+
close(): void;
|
|
77
|
+
private count;
|
|
78
|
+
private extractParticipants;
|
|
79
|
+
private extractTemporalScope;
|
|
80
|
+
private extractLocation;
|
|
81
|
+
private extractEmotion;
|
|
82
|
+
private createSummary;
|
|
83
|
+
private knownMemoryIds;
|
|
84
|
+
private memoryContent;
|
|
85
|
+
private entityOverlapScore;
|
|
86
|
+
private temporalContextScore;
|
|
87
|
+
private memoryFeatures;
|
|
88
|
+
private scoreFeatures;
|
|
89
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ApiKey, type FetchImpl } from "@linxiraos/pi-ai";
|
|
2
|
+
export declare const DEFAULT_EXTRACTION_MODEL: string;
|
|
3
|
+
export declare const OPENROUTER_BASE_URL: string;
|
|
4
|
+
export declare const FALLBACK_MODELS: readonly ["google/gemini-flash-latest"];
|
|
5
|
+
export interface ChatMessage {
|
|
6
|
+
role: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ExtractedFact {
|
|
10
|
+
subject?: string;
|
|
11
|
+
predicate?: string;
|
|
12
|
+
object?: string;
|
|
13
|
+
timestamp?: string;
|
|
14
|
+
source?: number;
|
|
15
|
+
confidence?: number;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface ExtractionClientOptions {
|
|
19
|
+
model?: string | null;
|
|
20
|
+
apiKey?: ApiKey | null;
|
|
21
|
+
baseUrl?: string | null;
|
|
22
|
+
fetch?: FetchImpl;
|
|
23
|
+
}
|
|
24
|
+
export declare class ExtractionClient {
|
|
25
|
+
model: string;
|
|
26
|
+
apiKey: ApiKey;
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
callCount: number;
|
|
29
|
+
private readonly fetchImpl;
|
|
30
|
+
constructor(opts?: ExtractionClientOptions);
|
|
31
|
+
chat(messages: readonly ChatMessage[], temperature?: number, maxTokens?: number): Promise<string>;
|
|
32
|
+
callApi(model: string, messages: readonly ChatMessage[], temperature: number, maxTokens: number, apiKey?: string): Promise<string>;
|
|
33
|
+
extractFacts(messages: readonly ChatMessage[]): Promise<ExtractedFact[]>;
|
|
34
|
+
xtractFacts(messages: readonly ChatMessage[]): Promise<ExtractedFact[]>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare const EXTRACTION_TIERS: readonly ["host", "remote", "local", "cloud", "wrapper"];
|
|
2
|
+
export type ExtractionTier = (typeof EXTRACTION_TIERS)[number];
|
|
3
|
+
export interface ErrorSample {
|
|
4
|
+
at: string;
|
|
5
|
+
type: string;
|
|
6
|
+
msg: string;
|
|
7
|
+
reason?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface TierStatsSnapshot {
|
|
10
|
+
attempts: number;
|
|
11
|
+
successes: number;
|
|
12
|
+
no_output: number;
|
|
13
|
+
failures: number;
|
|
14
|
+
error_samples: ErrorSample[];
|
|
15
|
+
}
|
|
16
|
+
export interface ExtractionStatsSnapshot {
|
|
17
|
+
created_at: string;
|
|
18
|
+
snapshot_at: string;
|
|
19
|
+
totals: {
|
|
20
|
+
calls: number;
|
|
21
|
+
successes: number;
|
|
22
|
+
failures: number;
|
|
23
|
+
empty: number;
|
|
24
|
+
success_rate: number;
|
|
25
|
+
};
|
|
26
|
+
by_tier: Record<ExtractionTier, TierStatsSnapshot>;
|
|
27
|
+
}
|
|
28
|
+
export declare function safeForLog(value: unknown): string;
|
|
29
|
+
export declare class ExtractionDiagnostics {
|
|
30
|
+
private tierStats;
|
|
31
|
+
private totalCalls;
|
|
32
|
+
private totalSuccesses;
|
|
33
|
+
private totalFailures;
|
|
34
|
+
private totalEmpty;
|
|
35
|
+
private createdAt;
|
|
36
|
+
private validateTier;
|
|
37
|
+
recordAttempt(tier: ExtractionTier): void;
|
|
38
|
+
recordSuccess(tier: ExtractionTier, _factCount?: number): void;
|
|
39
|
+
recordNoOutput(tier: ExtractionTier): void;
|
|
40
|
+
recordFailure(tier: ExtractionTier, exc?: unknown, reason?: string): void;
|
|
41
|
+
recordCall(opts: {
|
|
42
|
+
succeeded: boolean;
|
|
43
|
+
allEmpty?: boolean;
|
|
44
|
+
}): void;
|
|
45
|
+
successRate(): number;
|
|
46
|
+
snapshot(): ExtractionStatsSnapshot;
|
|
47
|
+
reset(): void;
|
|
48
|
+
}
|
|
49
|
+
export declare function getDiagnostics(): ExtractionDiagnostics;
|
|
50
|
+
export declare function getExtractionStats(): ExtractionStatsSnapshot;
|
|
51
|
+
export declare function resetExtractionStats(): void;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const EXTRACTION_SYSTEM_PROMPT = "You extract structured facts from conversation messages. For each message or group of related messages, identify:\n\n1. ENTITIES: People, projects, tools, versions, dates, numbers mentioned\n2. RELATIONSHIPS: How entities relate to each other (uses, created, set, changed, prefers)\n3. TEMPORAL ANCHORS: When something happened, deadlines, durations\n4. CONTRADICTIONS: When a fact was later changed or updated\n\nReturn ONLY a JSON array of fact objects. Each fact must have:\n- subject: the entity the fact is about (string)\n- predicate: the relationship or action (string)\n- object: the value or related entity (string)\n- timestamp: ISO timestamp when this was stated (string, from message context)\n- source: which message index this came from (integer, 0-based)\n- confidence: 0.0-1.0 how certain you are (float)\n\nRULES:\n- One fact per relationship. \"I use React 18.2 and Node.js 18\" = 2 facts.\n- Use lowercase for predicates: \"uses\", \"set\", \"changed\", \"created\", \"prefers\"\n- Include versions and numbers as objects when available\n- If a message states something changed, extract BOTH old and new facts\n- If unclear, use confidence < 0.8\n\nFormat: [{\"subject\": \"...\", \"predicate\": \"...\", \"object\": \"...\", \"timestamp\": \"...\", \"source\": 0, \"confidence\": 0.95}]\n";
|
|
2
|
+
export declare const EXTRACTION_USER_TEMPLATE = "Extract all structured facts from the following conversation messages. Return ONLY the JSON array, no other text.\n\nCONVERSATION:\n{conversation_text}\n\nFACTS:";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type RemoteLlmOptions } from "./local-llm.js";
|
|
2
|
+
export declare const EXTRACTION_PROMPT_TEMPLATE: string;
|
|
3
|
+
export declare function buildExtractionPrompt(text: string, detectedLang?: string): string;
|
|
4
|
+
/** Parsed knowledge-graph edge emitted by the extractor LLM. */
|
|
5
|
+
export interface ExtractedKgTriple {
|
|
6
|
+
subject: string;
|
|
7
|
+
predicate: string;
|
|
8
|
+
object: string;
|
|
9
|
+
}
|
|
10
|
+
/** Category-preserving extraction result used by background memory routing. */
|
|
11
|
+
export interface ExtractedFactCategories {
|
|
12
|
+
facts: string[];
|
|
13
|
+
instructions: string[];
|
|
14
|
+
preferences: string[];
|
|
15
|
+
timelines: string[];
|
|
16
|
+
kg: ExtractedKgTriple[];
|
|
17
|
+
}
|
|
18
|
+
/** Flatten extracted string categories for legacy fact callers. */
|
|
19
|
+
export declare function flattenExtractedFactCategories(extracted: ExtractedFactCategories): string[];
|
|
20
|
+
/** Count string facts plus KG triples in a category-preserving extraction result. */
|
|
21
|
+
export declare function countExtractedFactCategories(extracted: ExtractedFactCategories): number;
|
|
22
|
+
/** Parse extractor output without discarding MEMORIA categories or KG triples. */
|
|
23
|
+
export declare function parseExtractedFactCategories(rawOutput: string | null | undefined): ExtractedFactCategories;
|
|
24
|
+
/** Parse extractor output into the legacy flat string fact list. */
|
|
25
|
+
export declare function parseFacts(rawOutput: string | null | undefined): string[];
|
|
26
|
+
export declare function heuristicExtractFacts(text: string): string[];
|
|
27
|
+
/** Extract fact categories from text using configured, host, local, or remote LLMs. */
|
|
28
|
+
export declare function extractFactCategories(text: string | null | undefined, options?: RemoteLlmOptions): Promise<ExtractedFactCategories>;
|
|
29
|
+
/** Extract legacy flat fact strings from text. */
|
|
30
|
+
export declare function extractFacts(text: string | null | undefined, options?: RemoteLlmOptions): Promise<string[]>;
|
|
31
|
+
/** Safely extract category-preserving facts, swallowing best-effort failures. */
|
|
32
|
+
export declare function extractFactCategoriesSafe(text: string | null | undefined): Promise<ExtractedFactCategories>;
|
|
33
|
+
/** Safely extract legacy flat fact strings, swallowing best-effort failures. */
|
|
34
|
+
export declare function extractFactsSafe(text: string | null | undefined): Promise<string[]>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type RuntimeInstallSpec } from "@linxiraos/pi-utils";
|
|
2
|
+
import type * as Fastembed from "fastembed";
|
|
3
|
+
type FastembedModule = typeof Fastembed;
|
|
4
|
+
/** Runtime install inputs for the optional fastembed embedding stack. */
|
|
5
|
+
export interface FastembedRuntimeInstallPlan {
|
|
6
|
+
/** Cache directory key; changes when runtime resolution policy changes. */
|
|
7
|
+
versionKey: string;
|
|
8
|
+
/** Dependency graph written to the runtime cache package manifest. */
|
|
9
|
+
install: RuntimeInstallSpec;
|
|
10
|
+
}
|
|
11
|
+
/** Build the deterministic fastembed runtime install plan used by local embeddings. */
|
|
12
|
+
export declare function fastembedRuntimeInstallPlan(): FastembedRuntimeInstallPlan;
|
|
13
|
+
/** Inputs for selecting the Windows DLL directory paired with a fastembed installation. */
|
|
14
|
+
export interface WindowsFastembedRuntimeOptions {
|
|
15
|
+
/** Resolved fastembed package entry whose dependency graph owns the ORT binding. */
|
|
16
|
+
fastembedEntry: string;
|
|
17
|
+
/** Directory containing fastembed's manifest and nested dependency graph. */
|
|
18
|
+
fastembedPackageDir: string;
|
|
19
|
+
/** Native architecture to select; defaults to the current process architecture. */
|
|
20
|
+
arch?: string;
|
|
21
|
+
/** Environment receiving the DLL search path; defaults to the subprocess environment. */
|
|
22
|
+
env?: NodeJS.ProcessEnv;
|
|
23
|
+
}
|
|
24
|
+
/** The ORT module and DLL directory selected from fastembed's own dependency graph. */
|
|
25
|
+
export interface WindowsFastembedRuntime {
|
|
26
|
+
/** Resolved entry for fastembed's own ONNX Runtime dependency. */
|
|
27
|
+
ortEntry: string;
|
|
28
|
+
/** Package directory containing the selected ORT manifest and native assets. */
|
|
29
|
+
ortPackageDir: string;
|
|
30
|
+
/** Directory prepended to `PATH` so Windows finds the paired native DLL. */
|
|
31
|
+
dllDir: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Prepend the ORT DLL directory paired with fastembed before Bun loads its
|
|
35
|
+
* native binding. Compiled Windows binaries extract `.node` files to a
|
|
36
|
+
* temporary directory, so the default DLL search can otherwise select an
|
|
37
|
+
* unrelated `onnxruntime.dll` from the inherited system path.
|
|
38
|
+
*/
|
|
39
|
+
export declare function prepareWindowsFastembedRuntime({ fastembedEntry, fastembedPackageDir, arch, env, }: WindowsFastembedRuntimeOptions): Promise<WindowsFastembedRuntime>;
|
|
40
|
+
export declare function loadFastembed(): Promise<FastembedModule>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { configureRecallFeatures, type RecallFeatureFlags } from "../config.js";
|
|
2
|
+
export * from "./banks.js";
|
|
3
|
+
export * from "./beam/index.js";
|
|
4
|
+
export { defaultLocalModelInitializer, type LocalEmbeddingModel, type LocalModelInitializer, type LocalModelInitOptions, type StandardEmbeddingModel, setLocalModelInitializer, } from "./embeddings.js";
|
|
5
|
+
export * from "./memory.js";
|
|
6
|
+
export { addMemory, forget, get, getBank, getContext, getDefaultInstance, getStats, Mnemopi, query, recall, recallEnhanced, remember, resetDefaultInstanceForTests, resetMemoryForTests, resetModuleStateForTests, saveMemory, scratchpadClear, scratchpadRead, scratchpadWrite, search, setBank, sleep, sleepAllSessions, storeMemory, update, } from "./memory.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { FetchImpl } from "@linxiraos/pi-ai";
|
|
2
|
+
export interface CompleteOptions {
|
|
3
|
+
maxTokens?: number;
|
|
4
|
+
temperature?: number;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
provider?: string | null;
|
|
7
|
+
model?: string | null;
|
|
8
|
+
fetch?: FetchImpl;
|
|
9
|
+
}
|
|
10
|
+
export interface LlmBackend {
|
|
11
|
+
name?: string;
|
|
12
|
+
complete(prompt: string, opts?: CompleteOptions): string | null | Promise<string | null>;
|
|
13
|
+
}
|
|
14
|
+
export declare function setHostLlmBackend(backend: LlmBackend | null | undefined): void;
|
|
15
|
+
export declare function getHostLlmBackend(): LlmBackend | null;
|
|
16
|
+
export declare function resetHostLlmBackendForTests(): void;
|
|
17
|
+
export declare function callHostLlm(prompt: string, opts?: CompleteOptions): Promise<string | null>;
|
|
18
|
+
export declare class CallableLlmBackend implements LlmBackend {
|
|
19
|
+
name: string;
|
|
20
|
+
private readonly fn;
|
|
21
|
+
constructor(name: string, fn: (prompt: string, opts?: CompleteOptions) => string | null | Promise<string | null>);
|
|
22
|
+
complete(prompt: string, opts?: CompleteOptions): string | null | Promise<string | null>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type FetchImpl } from "@linxiraos/pi-ai";
|
|
2
|
+
import { type CompleteOptions } from "./llm-backends.js";
|
|
3
|
+
import { type MnemopiLlmCompleteOptions } from "./runtime-options.js";
|
|
4
|
+
export interface RemoteLlmOptions {
|
|
5
|
+
fetch?: FetchImpl;
|
|
6
|
+
}
|
|
7
|
+
export declare const DEFAULT_MODEL_REPO: string;
|
|
8
|
+
export declare const DEFAULT_MODEL_FILE: string;
|
|
9
|
+
export declare function buildPrompt(memories: readonly string[], source?: string): string;
|
|
10
|
+
export declare function callConfiguredCompletion(prompt: string, temperature: number, opts?: MnemopiLlmCompleteOptions): Promise<string | null>;
|
|
11
|
+
export declare function buildHostPrompt(memories: readonly string[], source?: string): string;
|
|
12
|
+
export declare function configuredLlmWillHandleCall(): boolean;
|
|
13
|
+
export declare function cleanOutput(text: string): string;
|
|
14
|
+
export declare function chunkMemoriesByBudget(memories: readonly string[], source?: string): string[][];
|
|
15
|
+
export declare function llmAvailable(): boolean;
|
|
16
|
+
export declare function callRemoteLlm(prompt: string, temperature?: number, options?: RemoteLlmOptions): Promise<string | null>;
|
|
17
|
+
export declare function localGgufAvailable(): false;
|
|
18
|
+
export declare function callLocalLlm(_prompt: string): Promise<string | null>;
|
|
19
|
+
export declare function summarizeMemories(memories: readonly string[], source?: string, options?: RemoteLlmOptions): Promise<string | null>;
|
|
20
|
+
export declare function complete(prompt: string, temperature?: number, options?: CompleteOptions): Promise<string | null>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import type { Api, ApiKey, Model } from "@linxiraos/pi-ai";
|
|
3
|
+
import type { MemoryInput, Metadata } from "../types.js";
|
|
4
|
+
import { BeamMemory } from "./beam/index.js";
|
|
5
|
+
import type { RecallEnhancedOptions, RecallOptions, RecallResult, SleepResult } from "./beam/types.js";
|
|
6
|
+
import { type MnemopiEmbeddingRuntimeOptions, type MnemopiLlmCompletion, type MnemopiLlmRuntimeOptions, type ResolvedMnemopiRuntimeOptions } from "./runtime-options.js";
|
|
7
|
+
export interface MnemopiOptions {
|
|
8
|
+
readonly db?: Database;
|
|
9
|
+
readonly dbPath?: string;
|
|
10
|
+
readonly db_path?: string;
|
|
11
|
+
readonly sessionId?: string;
|
|
12
|
+
readonly session_id?: string;
|
|
13
|
+
readonly bank?: string | null;
|
|
14
|
+
readonly authorId?: string | null;
|
|
15
|
+
readonly author_id?: string | null;
|
|
16
|
+
readonly authorType?: string | null;
|
|
17
|
+
readonly author_type?: string | null;
|
|
18
|
+
readonly channelId?: string | null;
|
|
19
|
+
readonly channel_id?: string | null;
|
|
20
|
+
readonly noEmbeddings?: boolean;
|
|
21
|
+
readonly embeddingModel?: string;
|
|
22
|
+
readonly embeddingApiUrl?: string;
|
|
23
|
+
readonly embeddingApiKey?: ApiKey;
|
|
24
|
+
readonly embeddings?: false | MnemopiEmbeddingRuntimeOptions;
|
|
25
|
+
readonly llmEnabled?: boolean;
|
|
26
|
+
readonly llmBaseUrl?: string;
|
|
27
|
+
readonly llmApiKey?: ApiKey;
|
|
28
|
+
readonly llmModel?: string | Model<Api>;
|
|
29
|
+
readonly llm?: false | MnemopiLlmRuntimeOptions | Model<Api> | MnemopiLlmCompletion;
|
|
30
|
+
readonly proactiveLinking?: boolean;
|
|
31
|
+
/** Escalate best-effort failure logs (embedding pipeline) from debug to warn. */
|
|
32
|
+
readonly debug?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* When `false`, skip the embedding-model reconcile (wipe-and-rebuild) on open.
|
|
35
|
+
* Read-only / ephemeral consumers (e.g. a stats snapshot) set this so an open
|
|
36
|
+
* never triggers a destructive migration whose background rebuild the process
|
|
37
|
+
* would exit before completing. Defaults to `true`.
|
|
38
|
+
*/
|
|
39
|
+
readonly reconcile?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface RememberInput extends MemoryInput {
|
|
42
|
+
readonly extract?: boolean;
|
|
43
|
+
readonly extractEntities?: boolean;
|
|
44
|
+
readonly extract_entities?: boolean;
|
|
45
|
+
readonly extractText?: string | null;
|
|
46
|
+
readonly extract_text?: string | null;
|
|
47
|
+
readonly embedText?: string | null;
|
|
48
|
+
readonly embed_text?: string | null;
|
|
49
|
+
readonly trustTier?: string | null;
|
|
50
|
+
readonly trust_tier?: string | null;
|
|
51
|
+
readonly memoryType?: string | null;
|
|
52
|
+
readonly memory_type?: string | null;
|
|
53
|
+
}
|
|
54
|
+
export interface RememberFacadeOptions {
|
|
55
|
+
readonly source?: string | null;
|
|
56
|
+
readonly importance?: number;
|
|
57
|
+
readonly metadata?: Metadata | null;
|
|
58
|
+
readonly validUntil?: string | Date | null;
|
|
59
|
+
readonly valid_until?: string | Date | null;
|
|
60
|
+
readonly scope?: string | null;
|
|
61
|
+
readonly extractEntities?: boolean;
|
|
62
|
+
readonly extract_entities?: boolean;
|
|
63
|
+
readonly extract?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Override the text passed to fact/entity extraction. When unset, the
|
|
66
|
+
* stored content is used. See {@link RememberOptions.extractText}.
|
|
67
|
+
*/
|
|
68
|
+
readonly extractText?: string | null;
|
|
69
|
+
readonly extract_text?: string | null;
|
|
70
|
+
/**
|
|
71
|
+
* Override the text passed to embeddings and FTS indexing. Stored content
|
|
72
|
+
* remains unchanged; when unset, embeddings and FTS use stored content.
|
|
73
|
+
*/
|
|
74
|
+
readonly embedText?: string | null;
|
|
75
|
+
readonly embed_text?: string | null;
|
|
76
|
+
readonly trustTier?: string | null;
|
|
77
|
+
readonly trust_tier?: string | null;
|
|
78
|
+
readonly timestamp?: string | Date | null;
|
|
79
|
+
readonly veracity?: string | null;
|
|
80
|
+
readonly memoryType?: string | null;
|
|
81
|
+
readonly memory_type?: string | null;
|
|
82
|
+
}
|
|
83
|
+
export interface RecallFacadeOptions extends Omit<RecallOptions, "temporalHalflife" | "vecWeight" | "ftsWeight" | "importanceWeight"> {
|
|
84
|
+
readonly from_date?: string | null;
|
|
85
|
+
readonly to_date?: string | null;
|
|
86
|
+
readonly source?: string | null;
|
|
87
|
+
readonly topic?: string | null;
|
|
88
|
+
readonly temporalWeight?: number;
|
|
89
|
+
readonly temporal_weight?: number;
|
|
90
|
+
readonly query_time?: string | Date | null;
|
|
91
|
+
readonly temporalHalflife?: number | null;
|
|
92
|
+
readonly temporal_halflife?: number | null;
|
|
93
|
+
readonly vecWeight?: number | null;
|
|
94
|
+
readonly vec_weight?: number | null;
|
|
95
|
+
readonly ftsWeight?: number | null;
|
|
96
|
+
readonly fts_weight?: number | null;
|
|
97
|
+
readonly importanceWeight?: number | null;
|
|
98
|
+
readonly importance_weight?: number | null;
|
|
99
|
+
}
|
|
100
|
+
export interface MemoryFacadeStats {
|
|
101
|
+
total_memories: number;
|
|
102
|
+
total_sessions: number;
|
|
103
|
+
sources: Record<string, number>;
|
|
104
|
+
last_memory: string | null;
|
|
105
|
+
database: string;
|
|
106
|
+
mode: "beam";
|
|
107
|
+
banks: string[];
|
|
108
|
+
beam: {
|
|
109
|
+
working_memory: unknown;
|
|
110
|
+
episodic_memory: unknown;
|
|
111
|
+
triples: {
|
|
112
|
+
total: number;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
type ModuleRememberOptions = RememberFacadeOptions & {
|
|
117
|
+
readonly bank?: string | null;
|
|
118
|
+
};
|
|
119
|
+
type ModuleRecallOptions = RecallFacadeOptions & {
|
|
120
|
+
readonly bank?: string | null;
|
|
121
|
+
};
|
|
122
|
+
type ModuleRecallEnhancedOptions = RecallFacadeOptions & RecallEnhancedOptions & {
|
|
123
|
+
readonly bank?: string | null;
|
|
124
|
+
};
|
|
125
|
+
export declare class Mnemopi {
|
|
126
|
+
#private;
|
|
127
|
+
readonly sessionId: string;
|
|
128
|
+
readonly bank: string;
|
|
129
|
+
readonly dbPath?: string;
|
|
130
|
+
readonly authorId: string | null;
|
|
131
|
+
readonly authorType: string | null;
|
|
132
|
+
readonly channelId: string;
|
|
133
|
+
readonly beam: BeamMemory;
|
|
134
|
+
readonly conn: Database;
|
|
135
|
+
readonly db: Database;
|
|
136
|
+
readonly runtimeOptions?: ResolvedMnemopiRuntimeOptions;
|
|
137
|
+
constructor(options?: MnemopiOptions);
|
|
138
|
+
close(): void;
|
|
139
|
+
flushExtractions(): Promise<void>;
|
|
140
|
+
remember(memory: string | RememberInput, options?: RememberFacadeOptions): string;
|
|
141
|
+
recall(query: string, topK?: number, options?: RecallFacadeOptions): Promise<RecallResult[]>;
|
|
142
|
+
recallEnhanced(query: string, topK?: number, options?: RecallFacadeOptions & RecallEnhancedOptions): Promise<RecallResult[]>;
|
|
143
|
+
getContext(limit?: number): unknown[];
|
|
144
|
+
getStats(authorId?: string | null, authorType?: string | null, channelId?: string | null): MemoryFacadeStats;
|
|
145
|
+
get(memoryId: string): unknown | null;
|
|
146
|
+
forget(memoryId: string): boolean;
|
|
147
|
+
update(memoryId: string, content?: string | null, importance?: number | null): boolean;
|
|
148
|
+
sleep(dryRun?: boolean): SleepResult;
|
|
149
|
+
sleepAllSessions(dryRun?: boolean): SleepResult;
|
|
150
|
+
scratchpadWrite(content: string): string;
|
|
151
|
+
scratchpadRead(): unknown[];
|
|
152
|
+
scratchpadClear(): void;
|
|
153
|
+
addMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
|
|
154
|
+
saveMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
|
|
155
|
+
storeMemory(memory: string | RememberInput, options?: RememberFacadeOptions): string;
|
|
156
|
+
search(query: string, topK?: number, options?: RecallFacadeOptions): Promise<RecallResult[]>;
|
|
157
|
+
query(query: string, topK?: number, options?: RecallFacadeOptions): Promise<RecallResult[]>;
|
|
158
|
+
consolidate(dryRun?: boolean): SleepResult;
|
|
159
|
+
}
|
|
160
|
+
export declare function setBank(bank: string): void;
|
|
161
|
+
export declare function getBank(): string;
|
|
162
|
+
export declare function getDefaultInstance(bank?: string | null): Mnemopi;
|
|
163
|
+
export declare function remember(content: string | RememberInput, options?: ModuleRememberOptions): string;
|
|
164
|
+
export declare function recall(query: string, topK?: number, options?: ModuleRecallOptions): Promise<RecallResult[]>;
|
|
165
|
+
export declare function recallEnhanced(query: string, topK?: number, options?: ModuleRecallEnhancedOptions): Promise<RecallResult[]>;
|
|
166
|
+
export declare function getContext(limit?: number, bank?: string | null): unknown[];
|
|
167
|
+
export declare function getStats(bank?: string | null): MemoryFacadeStats;
|
|
168
|
+
export declare function get(memoryId: string, bank?: string | null): unknown | null;
|
|
169
|
+
export declare function forget(memoryId: string, bank?: string | null): boolean;
|
|
170
|
+
export declare function update(memoryId: string, content?: string | null, importance?: number | null, bank?: string | null): boolean;
|
|
171
|
+
export declare function sleep(dryRun?: boolean, bank?: string | null): SleepResult;
|
|
172
|
+
export declare function sleepAllSessions(dryRun?: boolean, bank?: string | null): SleepResult;
|
|
173
|
+
export declare function flushExtractions(bank?: string | null): Promise<void>;
|
|
174
|
+
export declare function scratchpadWrite(content: string, bank?: string | null): string;
|
|
175
|
+
export declare function scratchpadRead(bank?: string | null): unknown[];
|
|
176
|
+
export declare function scratchpadClear(bank?: string | null): void;
|
|
177
|
+
export declare function addMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
|
|
178
|
+
export declare function saveMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
|
|
179
|
+
export declare function storeMemory(memory: string | RememberInput, options?: ModuleRememberOptions): string;
|
|
180
|
+
export declare function search(query: string, topK?: number, options?: ModuleRecallOptions): Promise<RecallResult[]>;
|
|
181
|
+
export declare function query(query: string, topK?: number, options?: ModuleRecallOptions): Promise<RecallResult[]>;
|
|
182
|
+
export declare function resetDefaultInstanceForTests(): void;
|
|
183
|
+
export declare function resetMemoryForTests(): void;
|
|
184
|
+
export declare function resetModuleStateForTests(): void;
|
|
185
|
+
export type { MemoryInput, MemoryStats } from "../types.js";
|
|
186
|
+
export default Mnemopi;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { type DatabasePath } from "../../db.js";
|
|
3
|
+
export declare const ANNOTATION_KINDS: readonly ["mentions", "fact", "occurred_on", "has_source"];
|
|
4
|
+
export type AnnotationKind = (typeof ANNOTATION_KINDS)[number];
|
|
5
|
+
export interface MigrationOptions {
|
|
6
|
+
readonly dbPath: DatabasePath;
|
|
7
|
+
readonly dryRun?: boolean;
|
|
8
|
+
readonly backup?: boolean;
|
|
9
|
+
readonly logFn?: (line: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface PendingConnection {
|
|
12
|
+
query<T = unknown>(sql: string): {
|
|
13
|
+
get(...params: unknown[]): T | null;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function hasPendingMigration(db: Database): boolean;
|
|
17
|
+
export declare function migrate(dbPathOrOptions: DatabasePath | MigrationOptions, dryRun?: boolean, backup?: boolean, logFn?: (line: string) => void): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./e6-triplestore-split.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface MmrResult {
|
|
2
|
+
readonly content?: string;
|
|
3
|
+
readonly score?: number;
|
|
4
|
+
readonly [key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export type SimilarityFn = (textA: string, textB: string) => number;
|
|
7
|
+
export declare function jaccardSimilarity(textA: string, textB: string): number;
|
|
8
|
+
export declare function mmrRerank<T extends MmrResult>(results: readonly T[], lambdaParam?: number, topK?: number, similarityFn?: SimilarityFn): T[];
|