@fgv/ts-agent-memory-sqlite-vec 5.1.0-50 → 5.1.0-52
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/README.md +49 -1
- package/dist/packlets/sqlite-vec-index/connection.js +54 -0
- package/dist/packlets/sqlite-vec-index/connection.js.map +1 -0
- package/dist/packlets/sqlite-vec-index/model.js.map +1 -1
- package/dist/packlets/sqlite-vec-index/sqliteVecFragmentIndex.js +162 -8
- package/dist/packlets/sqlite-vec-index/sqliteVecFragmentIndex.js.map +1 -1
- package/dist/packlets/sqlite-vec-index/sqliteVecVectorIndex.js +115 -4
- package/dist/packlets/sqlite-vec-index/sqliteVecVectorIndex.js.map +1 -1
- package/dist/ts-agent-memory-sqlite-vec.d.ts +258 -10
- package/lib/packlets/sqlite-vec-index/connection.d.ts +42 -0
- package/lib/packlets/sqlite-vec-index/connection.d.ts.map +1 -0
- package/lib/packlets/sqlite-vec-index/connection.js +91 -0
- package/lib/packlets/sqlite-vec-index/connection.js.map +1 -0
- package/lib/packlets/sqlite-vec-index/model.d.ts +92 -0
- package/lib/packlets/sqlite-vec-index/model.d.ts.map +1 -1
- package/lib/packlets/sqlite-vec-index/model.js.map +1 -1
- package/lib/packlets/sqlite-vec-index/sqliteVecFragmentIndex.d.ts +89 -8
- package/lib/packlets/sqlite-vec-index/sqliteVecFragmentIndex.d.ts.map +1 -1
- package/lib/packlets/sqlite-vec-index/sqliteVecFragmentIndex.js +162 -8
- package/lib/packlets/sqlite-vec-index/sqliteVecFragmentIndex.js.map +1 -1
- package/lib/packlets/sqlite-vec-index/sqliteVecVectorIndex.d.ts +78 -5
- package/lib/packlets/sqlite-vec-index/sqliteVecVectorIndex.d.ts.map +1 -1
- package/lib/packlets/sqlite-vec-index/sqliteVecVectorIndex.js +115 -4
- package/lib/packlets/sqlite-vec-index/sqliteVecVectorIndex.js.map +1 -1
- package/package.json +7 -7
|
@@ -3,6 +3,7 @@ import { DetailedResult } from '@fgv/ts-utils';
|
|
|
3
3
|
import { FragmentEmbedder } from '@fgv/ts-agent-memory';
|
|
4
4
|
import { IEdgeTarget } from '@fgv/ts-agent-memory';
|
|
5
5
|
import { IEmbeddedFragment } from '@fgv/ts-agent-memory';
|
|
6
|
+
import { IFragmentQueryOptions } from '@fgv/ts-agent-memory';
|
|
6
7
|
import { IFragmentVectorIndex } from '@fgv/ts-agent-memory';
|
|
7
8
|
import { IFragmentVectorRebuildReport } from '@fgv/ts-agent-memory';
|
|
8
9
|
import { IMemoryRecordSource } from '@fgv/ts-agent-memory';
|
|
@@ -37,6 +38,47 @@ export declare interface ISqliteVecFragmentIndexCreateParams {
|
|
|
37
38
|
readonly tableName?: string;
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* An index plus the connection {@link SqliteVecFragmentIndex.open} opened for it.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export declare interface ISqliteVecFragmentIndexHandle {
|
|
47
|
+
/** The index, ready to use. */
|
|
48
|
+
readonly index: SqliteVecFragmentIndex;
|
|
49
|
+
/**
|
|
50
|
+
* Closes the connection **this `open` call created**. Idempotent — a second
|
|
51
|
+
* `close` succeeds rather than failing. See
|
|
52
|
+
* {@link ISqliteVecVectorIndexHandle.close} for why the disposer lives here
|
|
53
|
+
* rather than on the index class.
|
|
54
|
+
*/
|
|
55
|
+
close(): Result<true>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Parameters for {@link SqliteVecFragmentIndex.open}.
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export declare interface ISqliteVecFragmentIndexOpenParams {
|
|
63
|
+
/**
|
|
64
|
+
* Filesystem path to the database file, opened by this package rather than by
|
|
65
|
+
* the consumer. Created if it does not exist, exactly as `better-sqlite3` would.
|
|
66
|
+
* `':memory:'` is accepted and yields an owned ephemeral connection.
|
|
67
|
+
*
|
|
68
|
+
* **Two `open` calls on one path produce two independent connections, not a
|
|
69
|
+
* shared one** — see {@link ISqliteVecVectorIndexOpenParams.path}. To put a
|
|
70
|
+
* fragment index and a record index on one connection, open it yourself and pass
|
|
71
|
+
* it to both `create` methods.
|
|
72
|
+
*/
|
|
73
|
+
readonly path: string;
|
|
74
|
+
/**
|
|
75
|
+
* Name of the `vec0` virtual table that holds the fragment embeddings. Must be a
|
|
76
|
+
* simple SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to
|
|
77
|
+
* `'memory_fragments'`.
|
|
78
|
+
*/
|
|
79
|
+
readonly tableName?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
40
82
|
/**
|
|
41
83
|
* Parameters for {@link SqliteVecVectorIndex.create}.
|
|
42
84
|
* @public
|
|
@@ -61,6 +103,58 @@ export declare interface ISqliteVecVectorIndexCreateParams {
|
|
|
61
103
|
readonly tableName?: string;
|
|
62
104
|
}
|
|
63
105
|
|
|
106
|
+
/**
|
|
107
|
+
* An index plus the connection {@link SqliteVecVectorIndex.open} opened for it.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export declare interface ISqliteVecVectorIndexHandle {
|
|
112
|
+
/** The index, ready to use. */
|
|
113
|
+
readonly index: SqliteVecVectorIndex;
|
|
114
|
+
/**
|
|
115
|
+
* Closes the connection **this `open` call created**. Idempotent — a second
|
|
116
|
+
* `close` succeeds rather than failing.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* The disposer travels on this handle rather than on the index class because an
|
|
120
|
+
* index built by `create` holds a connection the **consumer** owns, and must stay
|
|
121
|
+
* incapable of closing it. A `close()` method meaningful on some instances and
|
|
122
|
+
* forbidden on others would be a lie in the type; here, only the caller that
|
|
123
|
+
* caused the connection to exist is handed the means to end it.
|
|
124
|
+
*
|
|
125
|
+
* The index is unusable afterwards — every operation on it will fail against a
|
|
126
|
+
* closed connection.
|
|
127
|
+
*/
|
|
128
|
+
close(): Result<true>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Parameters for {@link SqliteVecVectorIndex.open}.
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export declare interface ISqliteVecVectorIndexOpenParams {
|
|
136
|
+
/**
|
|
137
|
+
* Filesystem path to the database file, opened by this package rather than by
|
|
138
|
+
* the consumer. Created if it does not exist, exactly as `better-sqlite3` would.
|
|
139
|
+
* `':memory:'` is accepted and yields an owned ephemeral connection.
|
|
140
|
+
*
|
|
141
|
+
* **Two `open` calls on one path produce two independent connections, not a
|
|
142
|
+
* shared one.** That is legal in SQLite and has a different locking story than
|
|
143
|
+
* the single-connection case — writes contend, and a reader can see a
|
|
144
|
+
* `SQLITE_BUSY`. To put a record index and a fragment index on one connection
|
|
145
|
+
* (the intended shared-handle case), open the connection yourself and pass it to
|
|
146
|
+
* both `create` methods.
|
|
147
|
+
*/
|
|
148
|
+
readonly path: string;
|
|
149
|
+
/**
|
|
150
|
+
* Name of the `vec0` virtual table that holds the embeddings. Must be a simple
|
|
151
|
+
* SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to `'memory_vectors'`.
|
|
152
|
+
* Supply a distinct name to hold more than one independent index in a single
|
|
153
|
+
* database file.
|
|
154
|
+
*/
|
|
155
|
+
readonly tableName?: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
64
158
|
/**
|
|
65
159
|
* A persistent, `sqlite-vec`-backed `IFragmentVectorIndex` (from
|
|
66
160
|
* `@fgv/ts-agent-memory`) — the fragment-granular sibling of
|
|
@@ -100,9 +194,13 @@ export declare interface ISqliteVecVectorIndexCreateParams {
|
|
|
100
194
|
* cosine (`score = 1 - cosineDistance`), byte-identical to the in-memory index.
|
|
101
195
|
* Large-N ANN indexing is explicitly out of scope, same regime as the record index.
|
|
102
196
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
197
|
+
* **Connection ownership depends on which factory you use.** With
|
|
198
|
+
* {@link SqliteVecFragmentIndex.create} the `Database` is consumer-owned
|
|
199
|
+
* (bring-your-own): this index loads the `sqlite-vec` extension onto it and
|
|
200
|
+
* reads/writes the table, but never opens or closes the connection — and that is
|
|
201
|
+
* the seam for backing this index and a record index with one connection. With
|
|
202
|
+
* {@link SqliteVecFragmentIndex.open} this package opens the file itself and hands
|
|
203
|
+
* back a handle carrying the disposer for the connection it created.
|
|
106
204
|
* @public
|
|
107
205
|
*/
|
|
108
206
|
export declare class SqliteVecFragmentIndex implements IFragmentVectorIndex {
|
|
@@ -112,10 +210,29 @@ export declare class SqliteVecFragmentIndex implements IFragmentVectorIndex {
|
|
|
112
210
|
private _dimension;
|
|
113
211
|
/** Prepared statements; created once the table exists (established or recovered). */
|
|
114
212
|
private _stmts;
|
|
213
|
+
/**
|
|
214
|
+
* Set by {@link SqliteVecFragmentIndex.release}. Distinct from `_stmts === undefined`,
|
|
215
|
+
* which means *no dimension established yet* — see the remarks on `release`.
|
|
216
|
+
*/
|
|
217
|
+
private _released;
|
|
115
218
|
private constructor();
|
|
116
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* The number of records that currently have at least one stored fragment. Zero
|
|
221
|
+
* before the first add.
|
|
222
|
+
*
|
|
223
|
+
* @remarks
|
|
224
|
+
* **Throws on a released index**, where every other member returns a `Failure` —
|
|
225
|
+
* `IFragmentVectorIndex` declares this a synchronous `number`, so there is no
|
|
226
|
+
* `Result` to fail into, and answering `0` would be a confident lie
|
|
227
|
+
* indistinguishable from an empty index. Same reasoning as
|
|
228
|
+
* {@link SqliteVecFragmentIndex.fragmentCount} and `SqliteVecVectorIndex.size`.
|
|
229
|
+
*/
|
|
117
230
|
get recordCount(): number;
|
|
118
|
-
/**
|
|
231
|
+
/**
|
|
232
|
+
* The total number of fragments currently held across all records. Zero before
|
|
233
|
+
* the first add. **Throws on a released index** — see
|
|
234
|
+
* {@link SqliteVecFragmentIndex.recordCount}.
|
|
235
|
+
*/
|
|
119
236
|
get fragmentCount(): number;
|
|
120
237
|
/**
|
|
121
238
|
* Family-convention factory. Loads the `sqlite-vec` extension onto the supplied
|
|
@@ -131,6 +248,64 @@ export declare class SqliteVecFragmentIndex implements IFragmentVectorIndex {
|
|
|
131
248
|
* drop-and-re-index — `vec0` cannot be altered in place).
|
|
132
249
|
*/
|
|
133
250
|
static create(params: ISqliteVecFragmentIndexCreateParams): Promise<Result<SqliteVecFragmentIndex>>;
|
|
251
|
+
/**
|
|
252
|
+
* Path-based factory. Opens the database file itself and returns the index
|
|
253
|
+
* together with a disposer for the connection it created.
|
|
254
|
+
*
|
|
255
|
+
* @remarks
|
|
256
|
+
* The fragment-granular sibling of {@link SqliteVecVectorIndex.open}, and present
|
|
257
|
+
* for the same reason: a consumer doing sub-document retrieval only would
|
|
258
|
+
* otherwise still value-import `better-sqlite3` and hand-roll a `captureResult`
|
|
259
|
+
* around a constructor that throws.
|
|
260
|
+
*
|
|
261
|
+
* **Use `create` instead when one connection must back both a fragment index and
|
|
262
|
+
* a record index** — the intended shared-handle case. Two `open` calls on one path
|
|
263
|
+
* give two independent connections, not a shared one.
|
|
264
|
+
*
|
|
265
|
+
* If initialization fails after the file is opened, the connection is closed
|
|
266
|
+
* before returning, so a failed `open` does not leak the descriptor it created.
|
|
267
|
+
* Should that close *itself* fail — the connection is then genuinely leaked — the
|
|
268
|
+
* returned message says so rather than hiding it. That includes the
|
|
269
|
+
* auxiliary-column mismatch failure, which is reported by `create` only after the
|
|
270
|
+
* file is open.
|
|
271
|
+
*
|
|
272
|
+
* @param params - See {@link ISqliteVecFragmentIndexOpenParams}.
|
|
273
|
+
* @returns `Success` with a {@link ISqliteVecFragmentIndexHandle}, or `Failure` if
|
|
274
|
+
* the driver could not be loaded, the file could not be opened, the table name is
|
|
275
|
+
* not a simple identifier, the extension fails to load, or the existing table was
|
|
276
|
+
* written by a version with a different auxiliary-column set.
|
|
277
|
+
*/
|
|
278
|
+
static open(params: ISqliteVecFragmentIndexOpenParams): Promise<Result<ISqliteVecFragmentIndexHandle>>;
|
|
279
|
+
/**
|
|
280
|
+
* Drops this index's prepared statements and marks it unusable. Does **not**
|
|
281
|
+
* touch the connection.
|
|
282
|
+
*
|
|
283
|
+
* @remarks
|
|
284
|
+
* The fragment-lane counterpart of `SqliteVecVectorIndex.release`, and it
|
|
285
|
+
* matters here for the same reason plus one more: a shared-connection
|
|
286
|
+
* deployment — the case `create({ database })` exists for — holds a record index
|
|
287
|
+
* *and* a fragment index over one connection, so it carries two instances of the
|
|
288
|
+
* statement-lifetime shape rather than one. Both must be released.
|
|
289
|
+
*
|
|
290
|
+
* `better-sqlite3` exposes no public `finalize()`, so dropping the last
|
|
291
|
+
* reference does not finalize a statement — it makes it collectable *earlier*,
|
|
292
|
+
* while the environment is alive, rather than surviving to process teardown.
|
|
293
|
+
* That narrows the window in which `Statement::~Statement()` runs against a
|
|
294
|
+
* torn-down environment; it is not a proof against it.
|
|
295
|
+
*
|
|
296
|
+
* **Call this before closing a connection you own.**
|
|
297
|
+
* {@link SqliteVecFragmentIndex.open}'s handle does it for you.
|
|
298
|
+
*
|
|
299
|
+
* Idempotent. After it, every member fails (or, for the two counts, throws)
|
|
300
|
+
* rather than answering.
|
|
301
|
+
*/
|
|
302
|
+
release(): void;
|
|
303
|
+
/**
|
|
304
|
+
* Throw if this index has been released. The members that call it and cannot
|
|
305
|
+
* return a `Result` are the two counts; the rest convert the throw via
|
|
306
|
+
* `captureResult`.
|
|
307
|
+
*/
|
|
308
|
+
private _assertUsable;
|
|
134
309
|
/** {@inheritDoc IFragmentVectorIndex.addFragments} */
|
|
135
310
|
addFragments(target: IEdgeTarget, fragments: ReadonlyArray<IEmbeddedFragment>): Promise<Result<number>>;
|
|
136
311
|
/** {@inheritDoc IFragmentVectorIndex.remove} */
|
|
@@ -149,7 +324,7 @@ export declare class SqliteVecFragmentIndex implements IFragmentVectorIndex {
|
|
|
149
324
|
*/
|
|
150
325
|
private _clear;
|
|
151
326
|
/** {@inheritDoc IFragmentVectorIndex.query} */
|
|
152
|
-
query(vector: Float32Array, topK: number,
|
|
327
|
+
query(vector: Float32Array, topK: number, options?: IFragmentQueryOptions): Promise<Result<ReadonlyArray<IVectorQueryHit>>>;
|
|
153
328
|
/**
|
|
154
329
|
* Create the fragment `vec0` virtual table with the established dimension. The
|
|
155
330
|
* auxiliary columns must stay in sync with `AUXILIARY_COLUMNS`, which
|
|
@@ -248,9 +423,13 @@ export declare class SqliteVecFragmentIndex implements IFragmentVectorIndex {
|
|
|
248
423
|
* durable, appropriate for the same "thousands of records" regime the in-memory
|
|
249
424
|
* index targets. Large-N ANN indexing is explicitly out of scope — see the README.
|
|
250
425
|
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
426
|
+
* **Connection ownership depends on which factory you use.** With
|
|
427
|
+
* {@link SqliteVecVectorIndex.create} the `Database` is consumer-owned
|
|
428
|
+
* (bring-your-own): this index loads the `sqlite-vec` extension onto it and
|
|
429
|
+
* reads/writes the table, but never opens or closes the connection — and that is
|
|
430
|
+
* the seam for backing a record index and a fragment index with one connection.
|
|
431
|
+
* With {@link SqliteVecVectorIndex.open} this package opens the file itself and
|
|
432
|
+
* hands back a handle carrying the disposer for the connection it created.
|
|
254
433
|
* @public
|
|
255
434
|
*/
|
|
256
435
|
export declare class SqliteVecVectorIndex implements IVectorIndex {
|
|
@@ -260,8 +439,23 @@ export declare class SqliteVecVectorIndex implements IVectorIndex {
|
|
|
260
439
|
private _dimension;
|
|
261
440
|
/** Prepared statements; created once the table exists (established or recovered). */
|
|
262
441
|
private _stmts;
|
|
442
|
+
/**
|
|
443
|
+
* Set by {@link SqliteVecVectorIndex.release}. Distinct from `_stmts === undefined`,
|
|
444
|
+
* which means *no dimension established yet* — see the remarks on `release`.
|
|
445
|
+
*/
|
|
446
|
+
private _released;
|
|
263
447
|
private constructor();
|
|
264
|
-
/**
|
|
448
|
+
/**
|
|
449
|
+
* The number of vectors currently held. Zero before the first `add`.
|
|
450
|
+
*
|
|
451
|
+
* @remarks
|
|
452
|
+
* **Throws on a released index**, where every other member returns a `Failure` —
|
|
453
|
+
* because `IVectorIndex` declares this a synchronous `number` and there is no
|
|
454
|
+
* `Result` to fail into. Throwing preserves the behaviour a released index had
|
|
455
|
+
* before it had an explicit released state (the underlying statement threw
|
|
456
|
+
* against the closed connection); the alternative, answering `0`, would be a
|
|
457
|
+
* confident lie indistinguishable from an empty index.
|
|
458
|
+
*/
|
|
265
459
|
get size(): number;
|
|
266
460
|
/**
|
|
267
461
|
* Family-convention factory. Loads the `sqlite-vec` extension onto the supplied
|
|
@@ -274,6 +468,60 @@ export declare class SqliteVecVectorIndex implements IVectorIndex {
|
|
|
274
468
|
* simple identifier or the extension fails to load.
|
|
275
469
|
*/
|
|
276
470
|
static create(params: ISqliteVecVectorIndexCreateParams): Promise<Result<SqliteVecVectorIndex>>;
|
|
471
|
+
/**
|
|
472
|
+
* Path-based factory. Opens the database file itself and returns the index
|
|
473
|
+
* together with a disposer for the connection it created.
|
|
474
|
+
*
|
|
475
|
+
* @remarks
|
|
476
|
+
* The convenience over {@link SqliteVecVectorIndex.create} is that the consumer
|
|
477
|
+
* neither value-imports `better-sqlite3` nor re-establishes `Result` discipline
|
|
478
|
+
* around a constructor that throws — this is the one place the package leaked its
|
|
479
|
+
* own dependency into consumer source.
|
|
480
|
+
*
|
|
481
|
+
* **Use `create` instead when one connection must back more than one index** (a
|
|
482
|
+
* record index and a fragment index in the same file, the intended shared-handle
|
|
483
|
+
* case). Two `open` calls on one path give two independent connections, not a
|
|
484
|
+
* shared one.
|
|
485
|
+
*
|
|
486
|
+
* If initialization fails after the file is opened, the connection is closed
|
|
487
|
+
* before returning, so a failed `open` does not leak the descriptor it created.
|
|
488
|
+
* Should that close *itself* fail — the connection is then genuinely leaked — the
|
|
489
|
+
* returned message says so rather than hiding it.
|
|
490
|
+
*
|
|
491
|
+
* @param params - See {@link ISqliteVecVectorIndexOpenParams}.
|
|
492
|
+
* @returns `Success` with a {@link ISqliteVecVectorIndexHandle}, or `Failure` if
|
|
493
|
+
* the driver could not be loaded, the file could not be opened, the table name is
|
|
494
|
+
* not a simple identifier, or the extension fails to load.
|
|
495
|
+
*/
|
|
496
|
+
static open(params: ISqliteVecVectorIndexOpenParams): Promise<Result<ISqliteVecVectorIndexHandle>>;
|
|
497
|
+
/**
|
|
498
|
+
* Drops this index's prepared statements and marks it unusable. Does **not**
|
|
499
|
+
* touch the connection.
|
|
500
|
+
*
|
|
501
|
+
* @remarks
|
|
502
|
+
* `better-sqlite3` exposes no public `finalize()`, so releasing the last
|
|
503
|
+
* reference to a `Statement` does not finalize it — it makes it collectable
|
|
504
|
+
* *earlier*, while the environment is alive, rather than surviving to process
|
|
505
|
+
* teardown. That narrows the window in which `Statement::~Statement()` runs
|
|
506
|
+
* against a torn-down environment; it is not a proof against it.
|
|
507
|
+
*
|
|
508
|
+
* **Call this before closing a connection you own.** {@link
|
|
509
|
+
* SqliteVecVectorIndex.open}'s handle does it for you. A `create()`-made index
|
|
510
|
+
* holds a connection it does not own and stays structurally incapable of
|
|
511
|
+
* closing it — this method drops only what the index itself allocated, which is
|
|
512
|
+
* why it is safe to expose there.
|
|
513
|
+
*
|
|
514
|
+
* Idempotent. After it, every member fails (or, for `size`, throws) rather than
|
|
515
|
+
* answering: a released index is deliberately distinguishable from one that has
|
|
516
|
+
* simply never had an `add`, whose `_stmts` are also absent but which answers
|
|
517
|
+
* `size === 0` truthfully.
|
|
518
|
+
*/
|
|
519
|
+
release(): void;
|
|
520
|
+
/**
|
|
521
|
+
* Throw if this index has been released. The one member that calls it and cannot
|
|
522
|
+
* return a `Result` is `size`; the rest convert the throw via `captureResult`.
|
|
523
|
+
*/
|
|
524
|
+
private _assertUsable;
|
|
277
525
|
/** {@inheritDoc IVectorIndex.add} */
|
|
278
526
|
add(target: IEdgeTarget, vector: Float32Array): Promise<Result<string>>;
|
|
279
527
|
/** {@inheritDoc IVectorIndex.has} */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type BetterSqlite3 from 'better-sqlite3';
|
|
2
|
+
import { Result } from '@fgv/ts-utils';
|
|
3
|
+
/**
|
|
4
|
+
* Opens a `better-sqlite3` connection this package owns.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* **The value import of `better-sqlite3` lives here, and it is deliberately
|
|
8
|
+
* lazy.** Every other module in this package imports the driver as `import type`
|
|
9
|
+
* only, so merely importing `@fgv/ts-agent-memory-sqlite-vec` has never loaded the
|
|
10
|
+
* native binding — a property the path-based factories must not cost consumers who
|
|
11
|
+
* only ever call `create()`. A static import would move the native load (and its
|
|
12
|
+
* failure mode) to package-load time for everyone. The dynamic `import()` keeps it
|
|
13
|
+
* at the one call that actually needs a connection.
|
|
14
|
+
*
|
|
15
|
+
* Taking this import is the entire point of the path-based factories: it is the
|
|
16
|
+
* only place this wrapper leaked its own dependency into consumer source.
|
|
17
|
+
*
|
|
18
|
+
* @param path - Filesystem path to the database file. `':memory:'` is accepted and
|
|
19
|
+
* yields an owned ephemeral connection.
|
|
20
|
+
* @param label - Package-facing prefix for the failure message.
|
|
21
|
+
* @returns `Success` with a connection this package owns, or `Failure` if the
|
|
22
|
+
* driver could not be loaded or the file could not be opened.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function openOwnedConnection(path: string, label: string): Promise<Result<BetterSqlite3.Database>>;
|
|
26
|
+
/**
|
|
27
|
+
* Closes a connection this package opened.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Only ever called on a connection produced by {@link openOwnedConnection}. A
|
|
31
|
+
* connection supplied through a `create()` param is the consumer's and is never
|
|
32
|
+
* closed here — that asymmetry is the reason `close` travels on the handle
|
|
33
|
+
* returned by `open` rather than sitting on the index class.
|
|
34
|
+
*
|
|
35
|
+
* `better-sqlite3`'s own `close()` is safe to call on an already-closed
|
|
36
|
+
* connection, so a second `close()` on the same handle succeeds rather than
|
|
37
|
+
* failing.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare function closeOwnedConnection(db: BetterSqlite3.Database, label: string): Result<true>;
|
|
42
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/packlets/sqlite-vec-index/connection.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAqC,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAMzC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAK5F"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2026 Erik Fortune
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.openOwnedConnection = openOwnedConnection;
|
|
41
|
+
exports.closeOwnedConnection = closeOwnedConnection;
|
|
42
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
43
|
+
/**
|
|
44
|
+
* Opens a `better-sqlite3` connection this package owns.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* **The value import of `better-sqlite3` lives here, and it is deliberately
|
|
48
|
+
* lazy.** Every other module in this package imports the driver as `import type`
|
|
49
|
+
* only, so merely importing `@fgv/ts-agent-memory-sqlite-vec` has never loaded the
|
|
50
|
+
* native binding — a property the path-based factories must not cost consumers who
|
|
51
|
+
* only ever call `create()`. A static import would move the native load (and its
|
|
52
|
+
* failure mode) to package-load time for everyone. The dynamic `import()` keeps it
|
|
53
|
+
* at the one call that actually needs a connection.
|
|
54
|
+
*
|
|
55
|
+
* Taking this import is the entire point of the path-based factories: it is the
|
|
56
|
+
* only place this wrapper leaked its own dependency into consumer source.
|
|
57
|
+
*
|
|
58
|
+
* @param path - Filesystem path to the database file. `':memory:'` is accepted and
|
|
59
|
+
* yields an owned ephemeral connection.
|
|
60
|
+
* @param label - Package-facing prefix for the failure message.
|
|
61
|
+
* @returns `Success` with a connection this package owns, or `Failure` if the
|
|
62
|
+
* driver could not be loaded or the file could not be opened.
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
async function openOwnedConnection(path, label) {
|
|
66
|
+
return (await (0, ts_utils_1.captureAsyncResult)(async () => (await Promise.resolve().then(() => __importStar(require('better-sqlite3')))).default))
|
|
67
|
+
.withErrorFormat((m) => `${label}: failed to load the 'better-sqlite3' driver: ${m}`)
|
|
68
|
+
.onSuccess((driver) => (0, ts_utils_1.captureResult)(() => new driver(path)).withErrorFormat((m) => `${label}: failed to open '${path}': ${m}`));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Closes a connection this package opened.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* Only ever called on a connection produced by {@link openOwnedConnection}. A
|
|
75
|
+
* connection supplied through a `create()` param is the consumer's and is never
|
|
76
|
+
* closed here — that asymmetry is the reason `close` travels on the handle
|
|
77
|
+
* returned by `open` rather than sitting on the index class.
|
|
78
|
+
*
|
|
79
|
+
* `better-sqlite3`'s own `close()` is safe to call on an already-closed
|
|
80
|
+
* connection, so a second `close()` on the same handle succeeds rather than
|
|
81
|
+
* failing.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
function closeOwnedConnection(db, label) {
|
|
86
|
+
return (0, ts_utils_1.captureResult)(() => {
|
|
87
|
+
db.close();
|
|
88
|
+
return true;
|
|
89
|
+
}).withErrorFormat((m) => `${label}: failed to close the connection: ${m}`);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/packlets/sqlite-vec-index/connection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BH,kDASC;AAiBD,oDAKC;AAvDD,4CAA0E;AAE1E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,KAAK,UAAU,mBAAmB,CACvC,IAAY,EACZ,KAAa;IAEb,OAAO,CAAC,MAAM,IAAA,6BAAkB,EAAC,KAAK,IAAI,EAAE,CAAC,CAAC,wDAAa,gBAAgB,GAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACpF,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,iDAAiD,CAAC,EAAE,CAAC;SACpF,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CACpB,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,qBAAqB,IAAI,MAAM,CAAC,EAAE,CAAC,CACzG,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,oBAAoB,CAAC,EAA0B,EAAE,KAAa;IAC5E,OAAO,IAAA,wBAAa,EAAO,GAAG,EAAE;QAC9B,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,qCAAqC,CAAC,EAAE,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport type BetterSqlite3 from 'better-sqlite3';\nimport { Result, captureAsyncResult, captureResult } from '@fgv/ts-utils';\n\n/**\n * Opens a `better-sqlite3` connection this package owns.\n *\n * @remarks\n * **The value import of `better-sqlite3` lives here, and it is deliberately\n * lazy.** Every other module in this package imports the driver as `import type`\n * only, so merely importing `@fgv/ts-agent-memory-sqlite-vec` has never loaded the\n * native binding — a property the path-based factories must not cost consumers who\n * only ever call `create()`. A static import would move the native load (and its\n * failure mode) to package-load time for everyone. The dynamic `import()` keeps it\n * at the one call that actually needs a connection.\n *\n * Taking this import is the entire point of the path-based factories: it is the\n * only place this wrapper leaked its own dependency into consumer source.\n *\n * @param path - Filesystem path to the database file. `':memory:'` is accepted and\n * yields an owned ephemeral connection.\n * @param label - Package-facing prefix for the failure message.\n * @returns `Success` with a connection this package owns, or `Failure` if the\n * driver could not be loaded or the file could not be opened.\n * @internal\n */\nexport async function openOwnedConnection(\n path: string,\n label: string\n): Promise<Result<BetterSqlite3.Database>> {\n return (await captureAsyncResult(async () => (await import('better-sqlite3')).default))\n .withErrorFormat((m) => `${label}: failed to load the 'better-sqlite3' driver: ${m}`)\n .onSuccess((driver) =>\n captureResult(() => new driver(path)).withErrorFormat((m) => `${label}: failed to open '${path}': ${m}`)\n );\n}\n\n/**\n * Closes a connection this package opened.\n *\n * @remarks\n * Only ever called on a connection produced by {@link openOwnedConnection}. A\n * connection supplied through a `create()` param is the consumer's and is never\n * closed here — that asymmetry is the reason `close` travels on the handle\n * returned by `open` rather than sitting on the index class.\n *\n * `better-sqlite3`'s own `close()` is safe to call on an already-closed\n * connection, so a second `close()` on the same handle succeeds rather than\n * failing.\n *\n * @internal\n */\nexport function closeOwnedConnection(db: BetterSqlite3.Database, label: string): Result<true> {\n return captureResult<true>(() => {\n db.close();\n return true;\n }).withErrorFormat((m) => `${label}: failed to close the connection: ${m}`);\n}\n"]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type BetterSqlite3 from 'better-sqlite3';
|
|
2
|
+
import type { Result } from '@fgv/ts-utils';
|
|
3
|
+
import type { SqliteVecFragmentIndex } from './sqliteVecFragmentIndex';
|
|
4
|
+
import type { SqliteVecVectorIndex } from './sqliteVecVectorIndex';
|
|
2
5
|
/**
|
|
3
6
|
* Parameters for {@link SqliteVecVectorIndex.create}.
|
|
4
7
|
* @public
|
|
@@ -22,6 +25,95 @@ export interface ISqliteVecVectorIndexCreateParams {
|
|
|
22
25
|
*/
|
|
23
26
|
readonly tableName?: string;
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Parameters for {@link SqliteVecVectorIndex.open}.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export interface ISqliteVecVectorIndexOpenParams {
|
|
33
|
+
/**
|
|
34
|
+
* Filesystem path to the database file, opened by this package rather than by
|
|
35
|
+
* the consumer. Created if it does not exist, exactly as `better-sqlite3` would.
|
|
36
|
+
* `':memory:'` is accepted and yields an owned ephemeral connection.
|
|
37
|
+
*
|
|
38
|
+
* **Two `open` calls on one path produce two independent connections, not a
|
|
39
|
+
* shared one.** That is legal in SQLite and has a different locking story than
|
|
40
|
+
* the single-connection case — writes contend, and a reader can see a
|
|
41
|
+
* `SQLITE_BUSY`. To put a record index and a fragment index on one connection
|
|
42
|
+
* (the intended shared-handle case), open the connection yourself and pass it to
|
|
43
|
+
* both `create` methods.
|
|
44
|
+
*/
|
|
45
|
+
readonly path: string;
|
|
46
|
+
/**
|
|
47
|
+
* Name of the `vec0` virtual table that holds the embeddings. Must be a simple
|
|
48
|
+
* SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to `'memory_vectors'`.
|
|
49
|
+
* Supply a distinct name to hold more than one independent index in a single
|
|
50
|
+
* database file.
|
|
51
|
+
*/
|
|
52
|
+
readonly tableName?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* An index plus the connection {@link SqliteVecVectorIndex.open} opened for it.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export interface ISqliteVecVectorIndexHandle {
|
|
60
|
+
/** The index, ready to use. */
|
|
61
|
+
readonly index: SqliteVecVectorIndex;
|
|
62
|
+
/**
|
|
63
|
+
* Closes the connection **this `open` call created**. Idempotent — a second
|
|
64
|
+
* `close` succeeds rather than failing.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* The disposer travels on this handle rather than on the index class because an
|
|
68
|
+
* index built by `create` holds a connection the **consumer** owns, and must stay
|
|
69
|
+
* incapable of closing it. A `close()` method meaningful on some instances and
|
|
70
|
+
* forbidden on others would be a lie in the type; here, only the caller that
|
|
71
|
+
* caused the connection to exist is handed the means to end it.
|
|
72
|
+
*
|
|
73
|
+
* The index is unusable afterwards — every operation on it will fail against a
|
|
74
|
+
* closed connection.
|
|
75
|
+
*/
|
|
76
|
+
close(): Result<true>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Parameters for {@link SqliteVecFragmentIndex.open}.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export interface ISqliteVecFragmentIndexOpenParams {
|
|
83
|
+
/**
|
|
84
|
+
* Filesystem path to the database file, opened by this package rather than by
|
|
85
|
+
* the consumer. Created if it does not exist, exactly as `better-sqlite3` would.
|
|
86
|
+
* `':memory:'` is accepted and yields an owned ephemeral connection.
|
|
87
|
+
*
|
|
88
|
+
* **Two `open` calls on one path produce two independent connections, not a
|
|
89
|
+
* shared one** — see {@link ISqliteVecVectorIndexOpenParams.path}. To put a
|
|
90
|
+
* fragment index and a record index on one connection, open it yourself and pass
|
|
91
|
+
* it to both `create` methods.
|
|
92
|
+
*/
|
|
93
|
+
readonly path: string;
|
|
94
|
+
/**
|
|
95
|
+
* Name of the `vec0` virtual table that holds the fragment embeddings. Must be a
|
|
96
|
+
* simple SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to
|
|
97
|
+
* `'memory_fragments'`.
|
|
98
|
+
*/
|
|
99
|
+
readonly tableName?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* An index plus the connection {@link SqliteVecFragmentIndex.open} opened for it.
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
export interface ISqliteVecFragmentIndexHandle {
|
|
107
|
+
/** The index, ready to use. */
|
|
108
|
+
readonly index: SqliteVecFragmentIndex;
|
|
109
|
+
/**
|
|
110
|
+
* Closes the connection **this `open` call created**. Idempotent — a second
|
|
111
|
+
* `close` succeeds rather than failing. See
|
|
112
|
+
* {@link ISqliteVecVectorIndexHandle.close} for why the disposer lives here
|
|
113
|
+
* rather than on the index class.
|
|
114
|
+
*/
|
|
115
|
+
close(): Result<true>;
|
|
116
|
+
}
|
|
25
117
|
/**
|
|
26
118
|
* Parameters for {@link SqliteVecFragmentIndex.create}.
|
|
27
119
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/packlets/sqlite-vec-index/model.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/packlets/sqlite-vec-index/model.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,iCAAiC;IAChD;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC;IAE1C;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC1C,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IAErC;;;;;;;;;;;;;OAaG;IACH,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,iCAAiC;IAChD;;;;;;;;;OASG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC5C,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,sBAAsB,CAAC;IAEvC;;;;;OAKG;IACH,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,mCAAmC;IAClD;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC;IAE1C;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/packlets/sqlite-vec-index/model.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport type BetterSqlite3 from 'better-sqlite3';\n\n/**\n * Parameters for {@link SqliteVecVectorIndex.create}.\n * @public\n */\nexport interface ISqliteVecVectorIndexCreateParams {\n /**\n * A `better-sqlite3` `Database` the consumer owns (bring-your-own, mirroring\n * the boundary-package convention). The consumer opens it (`new Database(path)`\n * for a persistent file, or `new Database(':memory:')` for an ephemeral index)\n * and owns its lifecycle — this index never closes it. `create` loads the\n * `sqlite-vec` extension onto the connection and, if the vector table already\n * exists (a reopened persistent file), recovers its established dimension so no\n * re-embedding is required on open.\n */\n readonly database: BetterSqlite3.Database;\n\n /**\n * Name of the `vec0` virtual table that holds the embeddings. Must be a simple\n * SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to `'memory_vectors'`.\n * Supply a distinct name to hold more than one independent index in a single\n * database file.\n */\n readonly tableName?: string;\n}\n\n/**\n * Parameters for {@link SqliteVecFragmentIndex.create}.\n * @public\n */\nexport interface ISqliteVecFragmentIndexCreateParams {\n /**\n * A `better-sqlite3` `Database` the consumer owns (bring-your-own, mirroring\n * {@link ISqliteVecVectorIndexCreateParams.database}). The consumer opens it and\n * owns its lifecycle — this index never closes it. `create` loads the\n * `sqlite-vec` extension onto the connection and, if the fragment table already\n * exists (a reopened persistent file), recovers its established dimension so no\n * re-embedding is required on open.\n */\n readonly database: BetterSqlite3.Database;\n\n /**\n * Name of the `vec0` virtual table that holds the fragment embeddings. Must be a\n * simple SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to\n * `'memory_fragments'`. Supply a distinct name (distinct from any record-level\n * {@link SqliteVecVectorIndex} table) to hold more than one independent index in\n * a single database file.\n */\n readonly tableName?: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/packlets/sqlite-vec-index/model.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport type BetterSqlite3 from 'better-sqlite3';\nimport type { Result } from '@fgv/ts-utils';\nimport type { SqliteVecFragmentIndex } from './sqliteVecFragmentIndex';\nimport type { SqliteVecVectorIndex } from './sqliteVecVectorIndex';\n\n/**\n * Parameters for {@link SqliteVecVectorIndex.create}.\n * @public\n */\nexport interface ISqliteVecVectorIndexCreateParams {\n /**\n * A `better-sqlite3` `Database` the consumer owns (bring-your-own, mirroring\n * the boundary-package convention). The consumer opens it (`new Database(path)`\n * for a persistent file, or `new Database(':memory:')` for an ephemeral index)\n * and owns its lifecycle — this index never closes it. `create` loads the\n * `sqlite-vec` extension onto the connection and, if the vector table already\n * exists (a reopened persistent file), recovers its established dimension so no\n * re-embedding is required on open.\n */\n readonly database: BetterSqlite3.Database;\n\n /**\n * Name of the `vec0` virtual table that holds the embeddings. Must be a simple\n * SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to `'memory_vectors'`.\n * Supply a distinct name to hold more than one independent index in a single\n * database file.\n */\n readonly tableName?: string;\n}\n\n/**\n * Parameters for {@link SqliteVecVectorIndex.open}.\n * @public\n */\nexport interface ISqliteVecVectorIndexOpenParams {\n /**\n * Filesystem path to the database file, opened by this package rather than by\n * the consumer. Created if it does not exist, exactly as `better-sqlite3` would.\n * `':memory:'` is accepted and yields an owned ephemeral connection.\n *\n * **Two `open` calls on one path produce two independent connections, not a\n * shared one.** That is legal in SQLite and has a different locking story than\n * the single-connection case — writes contend, and a reader can see a\n * `SQLITE_BUSY`. To put a record index and a fragment index on one connection\n * (the intended shared-handle case), open the connection yourself and pass it to\n * both `create` methods.\n */\n readonly path: string;\n\n /**\n * Name of the `vec0` virtual table that holds the embeddings. Must be a simple\n * SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to `'memory_vectors'`.\n * Supply a distinct name to hold more than one independent index in a single\n * database file.\n */\n readonly tableName?: string;\n}\n\n/**\n * An index plus the connection {@link SqliteVecVectorIndex.open} opened for it.\n *\n * @public\n */\nexport interface ISqliteVecVectorIndexHandle {\n /** The index, ready to use. */\n readonly index: SqliteVecVectorIndex;\n\n /**\n * Closes the connection **this `open` call created**. Idempotent — a second\n * `close` succeeds rather than failing.\n *\n * @remarks\n * The disposer travels on this handle rather than on the index class because an\n * index built by `create` holds a connection the **consumer** owns, and must stay\n * incapable of closing it. A `close()` method meaningful on some instances and\n * forbidden on others would be a lie in the type; here, only the caller that\n * caused the connection to exist is handed the means to end it.\n *\n * The index is unusable afterwards — every operation on it will fail against a\n * closed connection.\n */\n close(): Result<true>;\n}\n\n/**\n * Parameters for {@link SqliteVecFragmentIndex.open}.\n * @public\n */\nexport interface ISqliteVecFragmentIndexOpenParams {\n /**\n * Filesystem path to the database file, opened by this package rather than by\n * the consumer. Created if it does not exist, exactly as `better-sqlite3` would.\n * `':memory:'` is accepted and yields an owned ephemeral connection.\n *\n * **Two `open` calls on one path produce two independent connections, not a\n * shared one** — see {@link ISqliteVecVectorIndexOpenParams.path}. To put a\n * fragment index and a record index on one connection, open it yourself and pass\n * it to both `create` methods.\n */\n readonly path: string;\n\n /**\n * Name of the `vec0` virtual table that holds the fragment embeddings. Must be a\n * simple SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to\n * `'memory_fragments'`.\n */\n readonly tableName?: string;\n}\n\n/**\n * An index plus the connection {@link SqliteVecFragmentIndex.open} opened for it.\n *\n * @public\n */\nexport interface ISqliteVecFragmentIndexHandle {\n /** The index, ready to use. */\n readonly index: SqliteVecFragmentIndex;\n\n /**\n * Closes the connection **this `open` call created**. Idempotent — a second\n * `close` succeeds rather than failing. See\n * {@link ISqliteVecVectorIndexHandle.close} for why the disposer lives here\n * rather than on the index class.\n */\n close(): Result<true>;\n}\n\n/**\n * Parameters for {@link SqliteVecFragmentIndex.create}.\n * @public\n */\nexport interface ISqliteVecFragmentIndexCreateParams {\n /**\n * A `better-sqlite3` `Database` the consumer owns (bring-your-own, mirroring\n * {@link ISqliteVecVectorIndexCreateParams.database}). The consumer opens it and\n * owns its lifecycle — this index never closes it. `create` loads the\n * `sqlite-vec` extension onto the connection and, if the fragment table already\n * exists (a reopened persistent file), recovers its established dimension so no\n * re-embedding is required on open.\n */\n readonly database: BetterSqlite3.Database;\n\n /**\n * Name of the `vec0` virtual table that holds the fragment embeddings. Must be a\n * simple SQL identifier (`[A-Za-z_][A-Za-z0-9_]*`). Defaults to\n * `'memory_fragments'`. Supply a distinct name (distinct from any record-level\n * {@link SqliteVecVectorIndex} table) to hold more than one independent index in\n * a single database file.\n */\n readonly tableName?: string;\n}\n"]}
|