@theokit/sdk-memory 0.6.1 → 0.6.3
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 +19 -0
- package/dist/index.cjs +42 -650
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -645
- package/dist/index.js.map +1 -1
- package/dist/internal/index/index-manager-dispatch.d.ts +1 -35
- package/dist/internal/index/index-manager-dispatch.d.ts.map +1 -1
- package/dist/internal/index/index-manager.d.ts +1 -130
- package/dist/internal/index/index-manager.d.ts.map +1 -1
- package/dist/internal/index/lance-index.d.ts +1 -91
- package/dist/internal/index/lance-index.d.ts.map +1 -1
- package/dist/internal/index/lance-memory-adapter.d.ts +16 -115
- package/dist/internal/index/lance-memory-adapter.d.ts.map +1 -1
- package/dist/internal/index/memory-index.d.ts +2 -2
- package/dist/internal/index/migrate-sqlite-to-lance.d.ts +1 -65
- package/dist/internal/index/migrate-sqlite-to-lance.d.ts.map +1 -1
- package/dist/internal/index/migration.d.ts +1 -35
- package/dist/internal/index/migration.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Dispatch helpers for `IndexManager.open`. Extracted to keep
|
|
3
|
-
* `index-manager.ts` under the G8 400-LoC budget (lancedb-backend-ship-v1-1).
|
|
4
|
-
*
|
|
5
|
-
* Iter 70 (Stage 3 source-move #27): hybrid copy from sdk-core's
|
|
6
|
-
* `internal/memory/index-manager-dispatch.ts`. sdk-core retains
|
|
7
|
-
* its copy for v1.x back-compat; sdk-memory ships the canonical
|
|
8
|
-
* copy that the future `index-manager.ts` move will compose with
|
|
9
|
-
* as a sibling. Dependency chain (all sibling, all moved):
|
|
10
|
-
* - `@theokit/sdk/errors` for `ConfigurationError` (public)
|
|
11
|
-
* - `./index-manager-contract.js` for `MemoryBackend` +
|
|
12
|
-
* `OpenIndexOptions` (moved iter 47)
|
|
13
|
-
* - `./lance-index.js` for `LanceIndex` (moved iter 68)
|
|
14
|
-
* - `./lance-memory-adapter.js` for `LanceMemoryAdapter` (moved iter 69)
|
|
15
|
-
* - `./memory-index.js` for `MemoryIndex` (moved iter 50)
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
import type { MemoryBackend, OpenIndexOptions } from "./index-manager-contract.js";
|
|
20
|
-
import type { MemoryIndex } from "./memory-index.js";
|
|
21
|
-
/** Valid backend identifiers — runtime guard against TS-narrowing escapes (EC-1). */
|
|
22
|
-
export declare const VALID_BACKENDS: readonly MemoryBackend[];
|
|
23
|
-
/**
|
|
24
|
-
* EC-1: runtime guard for `opts.backend`. TS union is compile-time only;
|
|
25
|
-
* consumers passing JS `as any` typos must hit a typed error, not silent
|
|
26
|
-
* SQLite fallback.
|
|
27
|
-
*/
|
|
28
|
-
export declare function assertValidBackend(backend: string): asserts backend is MemoryBackend;
|
|
29
|
-
/**
|
|
30
|
-
* Lance-path open. Throws `lance_requires_embedding` when no embedding
|
|
31
|
-
* runtime is provided (Lance is vector-only — no FTS fallback).
|
|
32
|
-
* Surfaces `lance_backend_unavailable` from LanceIndex.open when peer
|
|
33
|
-
* dep is absent.
|
|
34
|
-
*/
|
|
35
|
-
export declare function openLanceIndex(opts: OpenIndexOptions): Promise<MemoryIndex>;
|
|
1
|
+
export { assertValidBackend, openLanceIndex, VALID_BACKENDS, } from "@theokit/sdk/internal/memory-store";
|
|
36
2
|
//# sourceMappingURL=index-manager-dispatch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-manager-dispatch.d.ts","sourceRoot":"","sources":["../../../src/internal/index/index-manager-dispatch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index-manager-dispatch.d.ts","sourceRoot":"","sources":["../../../src/internal/index/index-manager-dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,cAAc,GACf,MAAM,oCAAoC,CAAC"}
|
|
@@ -1,131 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { type MemoryRoot } from "../store/markdown-store.js";
|
|
3
|
-
import { type MemoryIndex } from "./memory-index.js";
|
|
4
|
-
/**
|
|
5
|
-
* Memory index manager (ADR D2). FTS5-only at Phase 3; vector index lands in
|
|
6
|
-
* Phase 5.
|
|
7
|
-
*
|
|
8
|
-
* Lifecycle:
|
|
9
|
-
* const idx = await IndexManager.open({ cwd });
|
|
10
|
-
* await idx.sync();
|
|
11
|
-
* const hits = await idx.search("query");
|
|
12
|
-
* idx.close();
|
|
13
|
-
*
|
|
14
|
-
* Iter 72 (Stage 3 source-move #29): hybrid copy from sdk-core's
|
|
15
|
-
* `internal/memory/index-manager.ts`. sdk-core retains its copy for
|
|
16
|
-
* v1.x back-compat; sdk-memory ships the canonical orchestrator
|
|
17
|
-
* composing every prior Stage 3 move (sqlite-vec stack iter 47/49/50/53/55-57/62/65-67,
|
|
18
|
-
* lance stack iter 68-70, storage iter 56). The biggest move of the
|
|
19
|
-
* stage at 446 LOC — closes the index/ cluster.
|
|
20
|
-
*
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
interface MemorySearchHit {
|
|
24
|
-
readonly path: string;
|
|
25
|
-
readonly startLine: number;
|
|
26
|
-
readonly endLine: number;
|
|
27
|
-
readonly score: number;
|
|
28
|
-
readonly textScore: number;
|
|
29
|
-
readonly vectorScore?: number;
|
|
30
|
-
readonly snippet: string;
|
|
31
|
-
readonly source: "memory" | "sessions" | "wiki";
|
|
32
|
-
readonly citation: string;
|
|
33
|
-
}
|
|
34
|
-
interface IndexStatus {
|
|
35
|
-
backend: "fts-only" | "hybrid";
|
|
36
|
-
filesIndexed: number;
|
|
37
|
-
chunksIndexed: number;
|
|
38
|
-
lastSyncMs?: number;
|
|
39
|
-
}
|
|
40
|
-
interface SearchOptions {
|
|
41
|
-
maxResults?: number;
|
|
42
|
-
minScore?: number;
|
|
43
|
-
vectorWeight?: number;
|
|
44
|
-
textWeight?: number;
|
|
45
|
-
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
46
|
-
}
|
|
47
|
-
interface OpenIndexOptions {
|
|
48
|
-
cwd: string;
|
|
49
|
-
/**
|
|
50
|
-
* The memory root to index and to place the database under. Defaults to `<cwd>/.theokit/memory`.
|
|
51
|
-
*
|
|
52
|
-
* Optional here and required below: this is the entry point a caller reaches with a workspace in
|
|
53
|
-
* hand, while every path helper under it demands a resolved root (#463).
|
|
54
|
-
*/
|
|
55
|
-
memoryRoot?: MemoryRoot;
|
|
56
|
-
filePath?: string;
|
|
57
|
-
embedding?: EmbeddingRuntime;
|
|
58
|
-
backend?: "sqlite-vec" | "lance";
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The default memory index: SQLite for storage, FTS5 for text matching, and
|
|
62
|
-
* sqlite-vec for vectors when an embedding runtime is supplied.
|
|
63
|
-
*
|
|
64
|
-
* Open it with the static `open`, which is also the dispatch point for
|
|
65
|
-
* `backend: "lance"` — that overload returns a `LanceMemoryAdapter`, not an
|
|
66
|
-
* `IndexManager`, so hold the result as {@link MemoryIndex} unless you need this
|
|
67
|
-
* class specifically.
|
|
68
|
-
*
|
|
69
|
-
* Storage needs `better-sqlite3` unless the running Node exposes `node:sqlite`,
|
|
70
|
-
* and vectors additionally need `sqlite-vec`. Both are optional peer
|
|
71
|
-
* dependencies of this package. Without an embedding runtime the index opens
|
|
72
|
-
* text-only and reports `backend: "fts-only"`; no vector table is created and
|
|
73
|
-
* search degrades to BM25 rather than failing.
|
|
74
|
-
*
|
|
75
|
-
* `sync()` crawls the markdown corpus — `MEMORY.md`, `notes/`, `wiki/` and
|
|
76
|
-
* `sessions/` — skipping files whose content hash has not moved, and re-chunking
|
|
77
|
-
* the rest. Nothing is indexed until it runs.
|
|
78
|
-
*
|
|
79
|
-
* If the embedding provider, model or dimension differs from what the database
|
|
80
|
-
* recorded, opening drops the whole vector table so the next `sync()` re-embeds
|
|
81
|
-
* from scratch. Switching embedding models is therefore safe but not cheap.
|
|
82
|
-
*
|
|
83
|
-
* `search()` runs both halves and blends them per chunk, so a chunk found only
|
|
84
|
-
* by vector still appears with a text score of 0 and the other way round.
|
|
85
|
-
* `close()` releases the database handle; it is synchronous here, unlike the
|
|
86
|
-
* Lance adapter's, so a caller holding the {@link MemoryIndex} type must await
|
|
87
|
-
* it either way.
|
|
88
|
-
*/
|
|
89
|
-
export declare class IndexManager implements MemoryIndex {
|
|
90
|
-
private readonly memoryRoot;
|
|
91
|
-
private readonly db;
|
|
92
|
-
private readonly embedding;
|
|
93
|
-
private lastSyncMs;
|
|
94
|
-
private vectorReady;
|
|
95
|
-
private constructor();
|
|
96
|
-
/**
|
|
97
|
-
* Open a memory index. Dispatches to SQLite (default) or Lance (opt-in
|
|
98
|
-
* via `backend: "lance"`). See `openLanceIndex` for Lance-specific
|
|
99
|
-
* preconditions + typed errors.
|
|
100
|
-
*/
|
|
101
|
-
static open(opts: OpenIndexOptions & {
|
|
102
|
-
backend: "lance";
|
|
103
|
-
}): Promise<MemoryIndex>;
|
|
104
|
-
static open(opts: Omit<OpenIndexOptions, "backend"> | (OpenIndexOptions & {
|
|
105
|
-
backend?: "sqlite-vec";
|
|
106
|
-
})): Promise<IndexManager>;
|
|
107
|
-
/** Internal SQLite-path open. Renamed from previous public `open`. */
|
|
108
|
-
private static openSqliteInternal;
|
|
109
|
-
private initVectorBackend;
|
|
110
|
-
/** Walk the memory corpus + (re)index changed files. */
|
|
111
|
-
sync(): Promise<{
|
|
112
|
-
filesScanned: number;
|
|
113
|
-
filesUpdated: number;
|
|
114
|
-
chunksWritten: number;
|
|
115
|
-
chunksEmbedded: number;
|
|
116
|
-
}>;
|
|
117
|
-
search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
|
|
118
|
-
status(): IndexStatus;
|
|
119
|
-
private ftsSearch;
|
|
120
|
-
private vectorSearchById;
|
|
121
|
-
private combineHybridScores;
|
|
122
|
-
private mergeHits;
|
|
123
|
-
private fetchChunksByIds;
|
|
124
|
-
private loadFilesIndex;
|
|
125
|
-
private upsertFile;
|
|
126
|
-
private deleteChunksForFile;
|
|
127
|
-
private insertChunk;
|
|
128
|
-
close(): void;
|
|
129
|
-
}
|
|
130
|
-
export {};
|
|
1
|
+
export { IndexManager } from "@theokit/sdk/internal/memory-store";
|
|
131
2
|
//# sourceMappingURL=index-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-manager.d.ts","sourceRoot":"","sources":["../../../src/internal/index/index-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index-manager.d.ts","sourceRoot":"","sources":["../../../src/internal/index/index-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC"}
|
|
@@ -1,92 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { type MemoryRoot } from "../store/markdown-store.js";
|
|
3
|
-
/**
|
|
4
|
-
* One row of the Lance `facts` table, as it is stored. Field names are the
|
|
5
|
-
* on-disk column names, which is why `user_id` is snake_case here while the
|
|
6
|
-
* search result reports `userId`.
|
|
7
|
-
*
|
|
8
|
-
* `embedding` must be exactly as wide as the table was created with; the width
|
|
9
|
-
* is fixed by the embedding runtime on the first open and checked on every
|
|
10
|
-
* later one.
|
|
11
|
-
*/
|
|
12
|
-
export interface LanceFactRecord {
|
|
13
|
-
id: string;
|
|
14
|
-
text: string;
|
|
15
|
-
source: "memory" | "sessions" | "wiki";
|
|
16
|
-
embedding: ReadonlyArray<number>;
|
|
17
|
-
namespace: string;
|
|
18
|
-
scope: string;
|
|
19
|
-
user_id: string;
|
|
20
|
-
timestamp: number;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Options for `LanceIndex.open`. The embedding runtime is required, not
|
|
24
|
-
* optional: Lance here is vector-only, so there is no text-search fallback to
|
|
25
|
-
* open without one.
|
|
26
|
-
*/
|
|
27
|
-
export interface OpenLanceOptions {
|
|
28
|
-
cwd: string;
|
|
29
|
-
/** The resolved memory root. Defaults to `<cwd>/.theokit/memory` (#463). */
|
|
30
|
-
memoryRoot?: MemoryRoot;
|
|
31
|
-
embedding: EmbeddingRuntime;
|
|
32
|
-
/** Override storage location. Default: `<cwd>/.theokit/memory/lance/`. */
|
|
33
|
-
storagePath?: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Filters for `LanceIndex.search`. `namespace` is required and `scope` is
|
|
37
|
-
* optional; both are applied as a SQL predicate inside Lance. `sources` is
|
|
38
|
-
* applied in this process, after the rows come back, so it narrows the result
|
|
39
|
-
* without narrowing what `limit` counted.
|
|
40
|
-
*/
|
|
41
|
-
export interface LanceSearchOptions {
|
|
42
|
-
namespace: string;
|
|
43
|
-
scope?: string;
|
|
44
|
-
limit?: number;
|
|
45
|
-
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* One Lance search result. `score` is a similarity in `(0, 1]` derived from
|
|
49
|
-
* Lance's distance as `1 / (1 + distance)`, so higher is better — the opposite
|
|
50
|
-
* direction from the raw distance Lance returns.
|
|
51
|
-
*/
|
|
52
|
-
export interface LanceSearchHit {
|
|
53
|
-
id: string;
|
|
54
|
-
text: string;
|
|
55
|
-
source: "memory" | "sessions" | "wiki";
|
|
56
|
-
namespace: string;
|
|
57
|
-
scope: string;
|
|
58
|
-
userId: string;
|
|
59
|
-
score: number;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Lance-backed memory index. Public API mirrors the SQLite one logically:
|
|
63
|
-
* `addFacts`, `search`, `countFacts`, `removeFacts`, `close`.
|
|
64
|
-
*
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
export declare class LanceIndex {
|
|
68
|
-
private readonly table;
|
|
69
|
-
private readonly embedding;
|
|
70
|
-
private readonly embeddingDim;
|
|
71
|
-
private constructor();
|
|
72
|
-
static open(opts: OpenLanceOptions): Promise<LanceIndex>;
|
|
73
|
-
addFacts(facts: ReadonlyArray<Omit<LanceFactRecord, "embedding">>): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Search facts by semantic similarity. EC-1: filters use Lance's
|
|
76
|
-
* SQL string predicate with `'` → `''` escape — bind parameters are
|
|
77
|
-
* not supported by Lance 0.30.
|
|
78
|
-
*/
|
|
79
|
-
search(query: string, opts: LanceSearchOptions): Promise<LanceSearchHit[]>;
|
|
80
|
-
countFacts(namespace: string): Promise<number>;
|
|
81
|
-
removeFacts(ids: ReadonlyArray<string>): Promise<void>;
|
|
82
|
-
close(): Promise<void>;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Test helper for {@link LanceIndex}: indicates whether the Lance module
|
|
86
|
-
* is loadable in the current environment. Allows tests to gracefully skip
|
|
87
|
-
* when the optional dep is absent.
|
|
88
|
-
*
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
91
|
-
export declare function isLanceAvailable(): boolean;
|
|
1
|
+
export { isLanceAvailable, type LanceFactRecord, LanceIndex, type LanceSearchHit, type LanceSearchOptions, type OpenLanceOptions, } from "@theokit/sdk/internal/memory-store";
|
|
92
2
|
//# sourceMappingURL=lance-index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lance-index.d.ts","sourceRoot":"","sources":["../../../src/internal/index/lance-index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lance-index.d.ts","sourceRoot":"","sources":["../../../src/internal/index/lance-index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,eAAe,EACpB,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,oCAAoC,CAAC"}
|
|
@@ -1,124 +1,25 @@
|
|
|
1
|
+
import { type LanceIndex, LanceMemoryAdapter as SharedLanceMemoryAdapter } from "@theokit/sdk/internal/memory-store";
|
|
1
2
|
/**
|
|
2
|
-
* `
|
|
3
|
-
*
|
|
4
|
-
* `IndexManager.open({ backend: "lance" })` get a drop-in replacement
|
|
5
|
-
* for the SQLite-backed `IndexManager`.
|
|
3
|
+
* Presents a `LanceIndex` as a `MemoryIndex`, so a consumer written against the SQLite index runs
|
|
4
|
+
* unchanged on `backend: "lance"`.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* `sync`, `search`, `status` and `close` are the SDK's adapter, inherited rather than copied
|
|
7
|
+
* (#1068), so they behave the same whether or not this package is installed: `sync()` walks
|
|
8
|
+
* nothing and says so with `supported: false`, `search()` blends Lance's vector score with a
|
|
9
|
+
* term-overlap text score through the caller's `vectorWeight` / `textWeight`, and `status()`
|
|
10
|
+
* reports zero counts with `countsExact: false`. It always queries the `default` namespace.
|
|
8
11
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* - `search()` performs vector-only retrieval. `MemorySearchHit.textScore`
|
|
14
|
-
* is 0 on every hit (no FTS5 layer); `vectorScore === score`.
|
|
15
|
-
* - `status()` always reports `backend: "hybrid"` — embedding is required
|
|
16
|
-
* at open, so there is no text-only Lance index. Both counts are 0: the
|
|
17
|
-
* Lance row count is only available asynchronously and `status()` is
|
|
18
|
-
* synchronous, so callers needing a real count call
|
|
19
|
-
* `unwrap().countFacts()`. Lance does not track file provenance per row,
|
|
20
|
-
* so `filesIndexed` has nothing to report either way.
|
|
12
|
+
* The one member this class adds is {@link LanceMemoryAdapter.unwrap}. The SDK's adapter
|
|
13
|
+
* deliberately has no such member; this package published one, so it stays here. An index opened
|
|
14
|
+
* with `IndexManager.open({ backend: "lance" })` is the SDK's adapter and does not have it: to
|
|
15
|
+
* write facts, open a `LanceIndex` and either use it directly or wrap it with this class.
|
|
21
16
|
*
|
|
22
|
-
*
|
|
23
|
-
* D43). v1.4.0 of `@theokit/sdk`.
|
|
24
|
-
*
|
|
25
|
-
* Iter 69 (Stage 3 source-move #26): hybrid copy from sdk-core's
|
|
26
|
-
* `internal/memory/lance-memory-adapter.ts`. sdk-core retains its
|
|
27
|
-
* copy for v1.x Lance back-compat; sdk-memory ships the canonical
|
|
28
|
-
* copy that the future `index-manager-dispatch.ts` move will compose
|
|
29
|
-
* with as a sibling. Dependency chain (all sibling, all moved):
|
|
30
|
-
* - `IndexStatus`, `MemorySearchHit`, `SearchOptions` from
|
|
31
|
-
* `./index-manager-contract.js` (moved iter 47)
|
|
32
|
-
* - `LanceIndex` from `./lance-index.js` (moved iter 68)
|
|
33
|
-
* - `MemoryIndex`, `parseSearchOptions`, `SyncResult` from
|
|
34
|
-
* `./memory-index.js` (moved iter 50)
|
|
35
|
-
*
|
|
36
|
-
* @internal
|
|
37
|
-
*/
|
|
38
|
-
import type { IndexStatus, MemorySearchHit, SearchOptions } from "./index-manager-contract.js";
|
|
39
|
-
import { type MemoryIndex, type SyncResult } from "./memory-index.js";
|
|
40
|
-
/**
|
|
41
|
-
* **Iter 69 rollup-plugin-dts workaround** (mirrors iter 48/53/55/66/67 pattern).
|
|
42
|
-
* Importing `LanceIndex` from sibling `./lance-index.js` fails dts
|
|
43
|
-
* emit with `"LanceIndex" is not exported by "src/internal/lance-index.ts"`
|
|
44
|
-
* because rollup-dts treeshakes the class when it has no public
|
|
45
|
-
* type reaching it transitively — even though the barrel `export *`
|
|
46
|
-
* makes it publicly callable. Same class as iter 66/67's MemoryDb.
|
|
47
|
-
*
|
|
48
|
-
* Fix: inline a structural mirror of the minimal LanceIndex surface
|
|
49
|
-
* the adapter actually uses (search + close + identity for unwrap()
|
|
50
|
-
* via `inner === actual LanceIndex`). The mirror is purely a TYPE —
|
|
51
|
-
* the runtime continues to receive the real LanceIndex instance
|
|
52
|
-
* unchanged. When a future move surfaces LanceIndex through a
|
|
53
|
-
* different publicly-reachable path, this mirror MUST be deleted +
|
|
54
|
-
* the canonical type import restored.
|
|
55
|
-
*
|
|
56
|
-
* @internal
|
|
57
|
-
*/
|
|
58
|
-
interface LanceIndex {
|
|
59
|
-
addFacts(facts: ReadonlyArray<{
|
|
60
|
-
id: string;
|
|
61
|
-
text: string;
|
|
62
|
-
source: "memory" | "sessions" | "wiki";
|
|
63
|
-
namespace: string;
|
|
64
|
-
scope: string;
|
|
65
|
-
user_id: string;
|
|
66
|
-
timestamp: number;
|
|
67
|
-
}>): Promise<void>;
|
|
68
|
-
search(query: string, opts: {
|
|
69
|
-
namespace: string;
|
|
70
|
-
scope?: string;
|
|
71
|
-
limit?: number;
|
|
72
|
-
sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
|
|
73
|
-
}): Promise<ReadonlyArray<{
|
|
74
|
-
id: string;
|
|
75
|
-
text: string;
|
|
76
|
-
source: "memory" | "sessions" | "wiki";
|
|
77
|
-
namespace: string;
|
|
78
|
-
scope: string;
|
|
79
|
-
userId: string;
|
|
80
|
-
score: number;
|
|
81
|
-
}>>;
|
|
82
|
-
countFacts(namespace: string): Promise<number>;
|
|
83
|
-
removeFacts(ids: ReadonlyArray<string>): Promise<void>;
|
|
84
|
-
close(): Promise<void>;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Presents a `LanceIndex` as a {@link MemoryIndex}, so a consumer written
|
|
88
|
-
* against the SQLite index runs unchanged on `backend: "lance"`.
|
|
89
|
-
*
|
|
90
|
-
* Choose it when the corpus is large enough that SQLite plus sqlite-vec is the
|
|
91
|
-
* bottleneck and you are willing to feed the index yourself. Stay on the SQLite
|
|
92
|
-
* default when you want the markdown corpus crawled for you, or text matching on
|
|
93
|
-
* exact terms: this adapter's `sync()` does nothing and its `search()` is
|
|
94
|
-
* vector-only, so a query that would have matched by keyword now has to match by
|
|
95
|
-
* meaning.
|
|
96
|
-
*
|
|
97
|
-
* Requires `@lancedb/lancedb`, an optional peer dependency. It is loaded when
|
|
98
|
-
* the index is opened, not here.
|
|
99
|
-
*
|
|
100
|
-
* Two behaviours are worth knowing before switching. Facts only enter the index
|
|
101
|
-
* through `unwrap().addFacts(...)` — nothing else writes to it. And `search()`
|
|
102
|
-
* always queries the `default` namespace, because `SearchOptions` has no
|
|
103
|
-
* namespace field to pass through, so a multi-tenant caller must open one index
|
|
104
|
-
* per tenant rather than relying on the filter.
|
|
17
|
+
* Requires `@lancedb/lancedb`, an optional peer dependency, loaded when the index is opened.
|
|
105
18
|
*/
|
|
106
|
-
export declare class LanceMemoryAdapter
|
|
107
|
-
private
|
|
19
|
+
export declare class LanceMemoryAdapter extends SharedLanceMemoryAdapter {
|
|
20
|
+
#private;
|
|
108
21
|
constructor(inner: LanceIndex);
|
|
109
|
-
/**
|
|
110
|
-
* No-op for Lance — see file header. Returns zero counts so callers'
|
|
111
|
-
* existing logging (`filesScanned: X`) does not break.
|
|
112
|
-
*/
|
|
113
|
-
sync(): Promise<SyncResult>;
|
|
114
|
-
search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
|
|
115
|
-
status(): IndexStatus;
|
|
116
|
-
close(): Promise<void>;
|
|
117
|
-
/**
|
|
118
|
-
* Escape hatch for advanced callers (migration tool, benchmark script)
|
|
119
|
-
* that need direct access to addFacts/countFacts/removeFacts.
|
|
120
|
-
*/
|
|
22
|
+
/** The wrapped `LanceIndex`, for `addFacts`, `countFacts` and `removeFacts`. */
|
|
121
23
|
unwrap(): LanceIndex;
|
|
122
24
|
}
|
|
123
|
-
export {};
|
|
124
25
|
//# sourceMappingURL=lance-memory-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lance-memory-adapter.d.ts","sourceRoot":"","sources":["../../../src/internal/index/lance-memory-adapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"lance-memory-adapter.d.ts","sourceRoot":"","sources":["../../../src/internal/index/lance-memory-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,kBAAkB,IAAI,wBAAwB,EAC/C,MAAM,oCAAoC,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,kBAAmB,SAAQ,wBAAwB;;gBAGlD,KAAK,EAAE,UAAU;IAK7B,gFAAgF;IAChF,MAAM,IAAI,UAAU;CAGrB"}
|
|
@@ -62,8 +62,8 @@ export interface MemoryIndex {
|
|
|
62
62
|
sync(): Promise<SyncResult>;
|
|
63
63
|
/**
|
|
64
64
|
* Semantic + textual search over the indexed corpus. Both backends
|
|
65
|
-
* return the same `MemorySearchHit[]` shape
|
|
66
|
-
*
|
|
65
|
+
* return the same `MemorySearchHit[]` shape. Lance has no FTS5 layer, so its
|
|
66
|
+
* `textScore` is the share of the query's terms found in the hit's text.
|
|
67
67
|
*/
|
|
68
68
|
search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
|
|
69
69
|
/** Snapshot of the index health (backend type + counts). */
|
|
@@ -1,66 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Migrate Memory.index from SQLite to LanceDB (ADR D44).
|
|
3
|
-
*
|
|
4
|
-
* EC-3 MUST FIX: validation uses NFC unicode normalization on both sides.
|
|
5
|
-
*
|
|
6
|
-
* Iter 71 (Stage 3 source-move #28): hybrid copy from sdk-core's
|
|
7
|
-
* `internal/memory/migrate-sqlite-to-lance.ts`. sdk-core retains its
|
|
8
|
-
* copy for v1.x migration back-compat; sdk-memory ships the canonical
|
|
9
|
-
* copy.
|
|
10
|
-
*
|
|
11
|
-
* Dependency chain (all resolved):
|
|
12
|
-
* - `@theokit/sdk/errors` for `ConfigurationError` (public)
|
|
13
|
-
* - sibling `./memory-types.js` for `redactSecrets` (moved iter 52)
|
|
14
|
-
* - sibling `./index-db.js` for `defaultIndexPath` + `openMemoryDb` (moved iter 65)
|
|
15
|
-
* - sibling `./lance-index.js` for `LanceIndex` + `lanceStoragePath` (moved iter 68)
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export interface MigrateOptions {
|
|
20
|
-
cwd: string;
|
|
21
|
-
/**
|
|
22
|
-
* Absolute path (or `~/`-prefixed) of the memory root to migrate, when the agent that wrote it
|
|
23
|
-
* set `memory.directory`. Defaults to `<cwd>/.theokit/memory` (#463).
|
|
24
|
-
*/
|
|
25
|
-
directory?: string;
|
|
26
|
-
dryRun?: boolean;
|
|
27
|
-
batchSize?: number;
|
|
28
|
-
/** Inject for tests; defaults to console.log. */
|
|
29
|
-
logger?: (msg: string) => void;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Outcome of {@link migrateSqliteToLance}.
|
|
33
|
-
*
|
|
34
|
-
* Read `committed` first: it is `false` for a dry run and for a failed
|
|
35
|
-
* validation, and only `true` when the staging directory was promoted to
|
|
36
|
-
* `lance/`. `validated` reports whether the counts matched and the sampled facts
|
|
37
|
-
* compared equal; `sampleComparisons` holds up to ten of those comparisons so a
|
|
38
|
-
* failure can be inspected rather than merely counted.
|
|
39
|
-
*
|
|
40
|
-
* The SQLite database is left in place either way — this migration copies, it
|
|
41
|
-
* does not move.
|
|
42
|
-
*/
|
|
43
|
-
export interface MigrateResult {
|
|
44
|
-
countSqlite: number;
|
|
45
|
-
countLance: number;
|
|
46
|
-
/** Set when validation succeeded (or dryRun); false on validation failure. */
|
|
47
|
-
validated: boolean;
|
|
48
|
-
/** Per-fact compare results (size = sample count, up to 10). */
|
|
49
|
-
sampleComparisons: ReadonlyArray<{
|
|
50
|
-
id: string;
|
|
51
|
-
match: boolean;
|
|
52
|
-
}>;
|
|
53
|
-
/** Lance storage location (final, after migration). */
|
|
54
|
-
lancePath: string;
|
|
55
|
-
/** Was the migration committed (false for dry-run). */
|
|
56
|
-
committed: boolean;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Run the migration. Writes Lance to `<cwd>/.theokit/memory/lance-new/`
|
|
60
|
-
* first, validates round-trip, then renames to `lance/` on success.
|
|
61
|
-
* SQLite db is preserved (CLI prompts user to delete).
|
|
62
|
-
*
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
export declare function migrateSqliteToLance(opts: MigrateOptions): Promise<MigrateResult>;
|
|
1
|
+
export { type MigrateOptions, type MigrateResult, migrateSqliteToLance, } from "@theokit/sdk/internal/memory-store";
|
|
66
2
|
//# sourceMappingURL=migrate-sqlite-to-lance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-sqlite-to-lance.d.ts","sourceRoot":"","sources":["../../../src/internal/index/migrate-sqlite-to-lance.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate-sqlite-to-lance.d.ts","sourceRoot":"","sources":["../../../src/internal/index/migrate-sqlite-to-lance.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,oBAAoB,GACrB,MAAM,oCAAoC,CAAC"}
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Outcome of {@link migrateLegacyJson}. `reason` is present on every non-migrated
|
|
4
|
-
* result and says which guard stopped it: `already-migrated` (this key was
|
|
5
|
-
* attempted earlier in this process), `no-legacy-json` (nothing to migrate, or
|
|
6
|
-
* the file could not be read or parsed), `markdown-exists` (both files present,
|
|
7
|
-
* so neither was touched), `readonly-fs` (the write failed).
|
|
8
|
-
*/
|
|
9
|
-
export interface MigrationResult {
|
|
10
|
-
migrated: boolean;
|
|
11
|
-
factCount: number;
|
|
12
|
-
reason?: "already-migrated" | "no-legacy-json" | "markdown-exists" | "readonly-fs";
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Move facts from the pre-markdown JSON store into `MEMORY.md`, once.
|
|
16
|
-
*
|
|
17
|
-
* It runs only when the legacy file exists and `MEMORY.md` does not. When both
|
|
18
|
-
* exist it stops and leaves both alone — merging would need a conflict rule
|
|
19
|
-
* nobody has picked, and losing hand-written notes is worse than skipping. On
|
|
20
|
-
* success each fact is appended as a `## Facts` bullet and the JSON file is
|
|
21
|
-
* deleted.
|
|
22
|
-
*
|
|
23
|
-
* Guarded by a per-process set keyed on cwd, namespace, scope and user id, so
|
|
24
|
-
* the second call for the same key returns `already-migrated` without touching
|
|
25
|
-
* disk — including after a genuine failure. That set is per module instance, so
|
|
26
|
-
* a process that loads both this package's copy and the one inside
|
|
27
|
-
* `@theokit/sdk` has two independent sets.
|
|
28
|
-
*
|
|
29
|
-
* Never throws: a JSON file that cannot be read or parsed reports
|
|
30
|
-
* `no-legacy-json`, and a failed write reports `readonly-fs` after a warning on
|
|
31
|
-
* stderr.
|
|
32
|
-
*/
|
|
33
|
-
export declare function migrateLegacyJson(cwd: string, config: MemoryConfig): Promise<MigrationResult>;
|
|
34
|
-
/** Test-only — reset the in-process migration flag map. */
|
|
35
|
-
export declare function resetMigrationStateForTests(): void;
|
|
1
|
+
export { type MigrationResult, migrateLegacyJson, resetMigrationStateForTests, } from "@theokit/sdk/internal/memory-store";
|
|
36
2
|
//# sourceMappingURL=migration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/internal/index/migration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/internal/index/migration.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,eAAe,EACpB,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,oCAAoC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theokit/sdk-memory",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Memory subsystem for @theokit/sdk — MemoryProvider impls (markdown file store today; LanceDB + embeddings + circuit breaker next iters). Consumes the kernel-facing port from sdk-core.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/usetheokit/theokit-sdk#readme",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"better-sqlite3": "^12.0.0",
|
|
42
42
|
"sqlite-vec": ">=0.1.0",
|
|
43
43
|
"@lancedb/lancedb": ">=0.20.0",
|
|
44
|
-
"@theokit/sdk": "^5.
|
|
44
|
+
"@theokit/sdk": "^5.23.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependenciesMeta": {
|
|
47
47
|
"better-sqlite3": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@types/better-sqlite3": "^7.6.13",
|
|
62
62
|
"better-sqlite3": "^12.10.0",
|
|
63
63
|
"sqlite-vec": "^0.1.6",
|
|
64
|
-
"@theokit/sdk": "5.
|
|
64
|
+
"@theokit/sdk": "5.23.0"
|
|
65
65
|
},
|
|
66
66
|
"publishConfig": {
|
|
67
67
|
"provenance": true,
|