@mastra/mongodb 1.27.1 → 1.28.0-alpha.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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +23 -23
- package/dist/docs/references/integrations-databases-mongodb.md +2 -2
- package/dist/docs/references/integrations-vectors-mongodb.md +224 -20
- package/dist/index.cjs +2466 -252
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2467 -253
- package/dist/index.js.map +1 -1
- package/dist/vector/__fixtures__/atlas-local.d.ts +101 -0
- package/dist/vector/__fixtures__/atlas-local.d.ts.map +1 -0
- package/dist/vector/index.d.ts +372 -53
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/ownership.d.ts +46 -0
- package/dist/vector/ownership.d.ts.map +1 -0
- package/dist/vector/provisioning.d.ts +122 -0
- package/dist/vector/provisioning.d.ts.map +1 -0
- package/dist/vector/search-definition.d.ts +5 -0
- package/dist/vector/search-definition.d.ts.map +1 -0
- package/package.json +6 -6
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { MongoClient } from 'mongodb';
|
|
2
|
+
import type { CommandStartedEvent, Db, Document } from 'mongodb';
|
|
3
|
+
import type { MongoDBVector } from '..//index.js';
|
|
4
|
+
/** `OWNERSHIP_TEST_URI` points the suites at an Atlas cluster instead (design §7 cluster runs). */
|
|
5
|
+
export declare const ATLAS_LOCAL_URI: string;
|
|
6
|
+
export declare const DB_NAME = "vector_db";
|
|
7
|
+
export declare const REGISTRY = "__mastra_vector_indexes__";
|
|
8
|
+
export declare const JOURNAL = "__mastra_vector_ops__";
|
|
9
|
+
export declare function rawClient(): Promise<MongoClient>;
|
|
10
|
+
export declare function seedCollection(db: Db, name: string, docs?: Document[]): Promise<void>;
|
|
11
|
+
export declare function createRawSearchIndex(db: Db, coll: string, name: string, definition: Document, type?: 'search' | 'vectorSearch'): Promise<void>;
|
|
12
|
+
export declare function searchIndexNames(db: Db, coll: string): Promise<string[]>;
|
|
13
|
+
/**
|
|
14
|
+
* The search-index names on `coll` once they equal `expected`, or the last listing after `ms`. A
|
|
15
|
+
* drop is asynchronous on an Atlas cluster, so a name can stay listed for a while after it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function settledNames(db: Db, coll: string, expected: string[], ms?: number): Promise<string[]>;
|
|
18
|
+
export declare function seedRegistry(db: Db, doc: Document): Promise<void>;
|
|
19
|
+
export declare function seedJournal(db: Db, doc: Document): Promise<void>;
|
|
20
|
+
export declare function uniqueName(prefix: string): string;
|
|
21
|
+
export declare function waitFor(cond: () => Promise<boolean>, ms?: number): Promise<void>;
|
|
22
|
+
export declare function deferred<T = void>(): {
|
|
23
|
+
promise: Promise<T>;
|
|
24
|
+
resolve: (v: T) => void;
|
|
25
|
+
};
|
|
26
|
+
/** A test hook that signals `reached` when called, then blocks until `release` resolves. */
|
|
27
|
+
export declare function pause(): {
|
|
28
|
+
reached: {
|
|
29
|
+
promise: Promise<void>;
|
|
30
|
+
resolve: (v: void) => void;
|
|
31
|
+
};
|
|
32
|
+
release: {
|
|
33
|
+
promise: Promise<void>;
|
|
34
|
+
resolve: (v: void) => void;
|
|
35
|
+
};
|
|
36
|
+
hook: () => Promise<void>;
|
|
37
|
+
};
|
|
38
|
+
/** Fails fast instead of hanging when a hook is never called. */
|
|
39
|
+
export declare function reached(p: {
|
|
40
|
+
reached: {
|
|
41
|
+
promise: Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/** Every command the store's client sends from now on. The store needs `options: { monitorCommands: true }`. */
|
|
45
|
+
export declare function captureCommands(store: MongoDBVector): CommandStartedEvent[];
|
|
46
|
+
/** The store's `createSearchIndexesCommand` seam: `run` sends the real command. */
|
|
47
|
+
type CreateCommandHook = (command: Document, run: () => Promise<Document>) => Promise<Document>;
|
|
48
|
+
/** The id Atlas lists for search index `name` on `coll`, if any. */
|
|
49
|
+
export declare function listedId(db: Db, coll: string, name: string): Promise<string | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* Emulates the cluster's answer to an identical create: the existing index's id. Atlas Local
|
|
52
|
+
* answers with a fake id, or refuses a racing identical create as a duplicate name.
|
|
53
|
+
*/
|
|
54
|
+
export declare function clusterCreateMode(db: Db): CreateCommandHook;
|
|
55
|
+
/** A create whose response is lost: optionally sent for real first. */
|
|
56
|
+
export declare function unknownCreateMode(opts: {
|
|
57
|
+
perform: boolean;
|
|
58
|
+
}): CreateCommandHook;
|
|
59
|
+
/** Records every `warn` and `error` message the store logs from now on. */
|
|
60
|
+
export declare function captureLogs(store: MongoDBVector): {
|
|
61
|
+
warn: string[];
|
|
62
|
+
error: string[];
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Drop a collection after dropping its search indexes by id and waiting until none is listed.
|
|
66
|
+
* Atlas Local keeps the indexes of a collection dropped with them as DOES_NOT_EXIST rows, which
|
|
67
|
+
* come back when a collection of that name is recreated and then block createIndex (stuck row).
|
|
68
|
+
*/
|
|
69
|
+
export declare function dropCollectionWithSearchIndexes(db: Db, name: string): Promise<void>;
|
|
70
|
+
/** Merge `extra` into the store's test hooks, keeping the ones already set (the checker's drop hook). */
|
|
71
|
+
export declare function hooks(store: MongoDBVector, extra: Document): Document;
|
|
72
|
+
/** Every search-index drop the store sends from now on. */
|
|
73
|
+
export declare function recordDrops(store: MongoDBVector): {
|
|
74
|
+
drops: {
|
|
75
|
+
collectionName: string;
|
|
76
|
+
name: string;
|
|
77
|
+
id: string;
|
|
78
|
+
}[];
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The shared end-of-test invariant checker (design §7). At every drop the stores send it reads the
|
|
82
|
+
* registry on the primary and records a violation when a live registration references the name
|
|
83
|
+
* (I11a); it samples `rev` per `_id`/`generation` there and in {@link assertClean}.
|
|
84
|
+
*
|
|
85
|
+
* R13: a drop whose cleanup record has `dropDecided` is not blocked by a registration (one written
|
|
86
|
+
* after the decision). Instead {@link assertClean} checks the post-condition: no live registration
|
|
87
|
+
* records the dropped id, and every live registration referencing the name has a live index of
|
|
88
|
+
* another id under it, so none is left attached to the dropped incarnation.
|
|
89
|
+
*/
|
|
90
|
+
export declare function installInvariantChecker(db: Db, stores: MongoDBVector[]): {
|
|
91
|
+
assertClean(colls: string[], opts?: {
|
|
92
|
+
expectedLeaks?: string[];
|
|
93
|
+
userIndexes?: string[];
|
|
94
|
+
journalExpected?: boolean;
|
|
95
|
+
}): Promise<void>;
|
|
96
|
+
/** Reset each store's test hooks to the checker's drop hook alone. */
|
|
97
|
+
restoreHooks(): void;
|
|
98
|
+
violations: string[];
|
|
99
|
+
};
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=atlas-local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atlas-local.d.ts","sourceRoot":"","sources":["../../../src/vector/__fixtures__/atlas-local.ts"],"names":[],"mappings":"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"}
|
package/dist/vector/index.d.ts
CHANGED
|
@@ -41,6 +41,121 @@ export interface MongoDBQueryVectorParams extends QueryVectorParams<MongoDBVecto
|
|
|
41
41
|
*/
|
|
42
42
|
metadataMode?: 'field' | 'document';
|
|
43
43
|
}
|
|
44
|
+
/** Flat options for {@link MongoDBVector.hybridQuery}, sharing one limit across both branches. */
|
|
45
|
+
export interface MongoDBHybridQueryParams {
|
|
46
|
+
indexName: string;
|
|
47
|
+
/** Query embedding for the vector branch. Supply this or `queryText`, not both. */
|
|
48
|
+
queryVector?: number[];
|
|
49
|
+
/**
|
|
50
|
+
* Text for MongoDB to embed server-side for the vector branch. autoEmbed indexes only.
|
|
51
|
+
* Independent of `query`, so the two branches can search for different things.
|
|
52
|
+
*/
|
|
53
|
+
queryText?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Embedding model for the vector branch, overriding the index's. Requires `queryText`
|
|
56
|
+
* and must be compatible with the index's model.
|
|
57
|
+
*/
|
|
58
|
+
model?: string;
|
|
59
|
+
/** Full-text (BM25) term for the text branch. */
|
|
60
|
+
query: string;
|
|
61
|
+
paths: string[];
|
|
62
|
+
topK?: number;
|
|
63
|
+
filter?: MongoDBVectorFilter;
|
|
64
|
+
weights?: {
|
|
65
|
+
vector?: number;
|
|
66
|
+
text?: number;
|
|
67
|
+
};
|
|
68
|
+
numCandidates?: number;
|
|
69
|
+
metadataMode?: 'field' | 'document';
|
|
70
|
+
/** Override the resolved full-text search index name for this call. */
|
|
71
|
+
textSearchIndexName?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Per-branch retrieval and optional native reranking options for {@link MongoDBVector.hybridQuery}.
|
|
75
|
+
*
|
|
76
|
+
* The result shape follows the collection: managed indexes return the managed `metadata` and
|
|
77
|
+
* `document` fields; bring-your-own (BYO) indexes return the source document as `metadata`.
|
|
78
|
+
* The embedding is excluded unless `includeVector` is true, which also returns it as `vector`.
|
|
79
|
+
*/
|
|
80
|
+
export interface MongoDBHybridQueryBranchParams {
|
|
81
|
+
/** Logical Mastra index, resolving the collection and its registered search indexes. */
|
|
82
|
+
indexName: string;
|
|
83
|
+
/** Final result limit, applied after fusion and optional reranking. Integer from 1 to 10000; defaults to 10. */
|
|
84
|
+
topK?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Filter applied to both retrieval branches before fusion. On managed indexes, bare keys
|
|
87
|
+
* target the managed `metadata` fields; on BYO indexes, they target source document fields.
|
|
88
|
+
*/
|
|
89
|
+
filter?: MongoDBVectorFilter;
|
|
90
|
+
/** Non-negative, finite fusion weights. Each omitted weight defaults to 1; at least one must be positive. */
|
|
91
|
+
weights?: {
|
|
92
|
+
vector?: number;
|
|
93
|
+
text?: number;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Return each result's stored embedding as `vector`. Defaults to false. Not supported on
|
|
97
|
+
* autoEmbed indexes, whose generated embeddings are not stored on the documents.
|
|
98
|
+
*/
|
|
99
|
+
includeVector?: boolean;
|
|
100
|
+
/** Vector retrieval using either an embedding you generate or text for an autoEmbed index. */
|
|
101
|
+
vector: ({
|
|
102
|
+
/**
|
|
103
|
+
* Embedding that you generate. Mutually exclusive with query and model. Not supported on
|
|
104
|
+
* autoEmbed indexes, which only accept query text; passing it there throws a USER error.
|
|
105
|
+
*/
|
|
106
|
+
queryVector: number[];
|
|
107
|
+
query?: never;
|
|
108
|
+
model?: never;
|
|
109
|
+
} | {
|
|
110
|
+
/** Non-empty text for MongoDB to embed. Requires an autoEmbed index. */
|
|
111
|
+
query: string;
|
|
112
|
+
queryVector?: never;
|
|
113
|
+
/** Query embedding model override, independent of the reranking model. */
|
|
114
|
+
model?: string;
|
|
115
|
+
}) & {
|
|
116
|
+
/**
|
|
117
|
+
* Candidates considered by vector search, from 1 to 10000. Defaults to min(10000, 20 * limit),
|
|
118
|
+
* following MongoDB's recommendation of at least 20 times the vector limit.
|
|
119
|
+
* An explicit value is sent to MongoDB unchanged, which rejects one below the vector limit.
|
|
120
|
+
*/
|
|
121
|
+
numCandidates?: number;
|
|
122
|
+
/** Vector results contributed to fusion, from 1 to 10000. Defaults to min(10000, max(4 * topK, 20)). */
|
|
123
|
+
limit?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Bring-your-own collections only: search this existing vector index instead of the registered
|
|
126
|
+
* one. Filters with this option always use the `_id` pre-filter, so the index must declare `_id`
|
|
127
|
+
* as a filter field. It must also index the registered embedding field with the same embedding
|
|
128
|
+
* mode (vectors or `autoEmbed`), or MongoDB rejects the query. Rejected on managed indexes,
|
|
129
|
+
* which use their registered indexes.
|
|
130
|
+
*/
|
|
131
|
+
searchIndexName?: string;
|
|
132
|
+
};
|
|
133
|
+
/** Full-text (BM25) retrieval, configured independently of vector retrieval. */
|
|
134
|
+
text: {
|
|
135
|
+
/** Non-empty full-text query. */
|
|
136
|
+
query: string;
|
|
137
|
+
/** Non-empty array of indexed field paths to search, relative to the document root (e.g. `metadata.text`). */
|
|
138
|
+
paths: string[];
|
|
139
|
+
/**
|
|
140
|
+
* Bring-your-own collections only: search this existing full-text index instead of the
|
|
141
|
+
* registered one. Rejected on managed indexes, which use their registered indexes.
|
|
142
|
+
*/
|
|
143
|
+
searchIndexName?: string;
|
|
144
|
+
/** Text results contributed to fusion, from 1 to 10000. Defaults to min(10000, max(4 * topK, 20)). */
|
|
145
|
+
limit?: number;
|
|
146
|
+
};
|
|
147
|
+
/** Enable native $rerank after fusion. Omit to return fused results without reranking. */
|
|
148
|
+
rerank?: {
|
|
149
|
+
/** Non-empty query used to judge relevance, independent of both retrieval queries. */
|
|
150
|
+
query: string;
|
|
151
|
+
/** Non-empty array of field paths, relative to the document root. Missing document fields cause a server error. */
|
|
152
|
+
paths: string[];
|
|
153
|
+
/** Native reranking model. Defaults to 'rerank-2.5'; never changes the embedding model. */
|
|
154
|
+
model?: string;
|
|
155
|
+
/** Maximum fused documents to rerank and return before topK. Required integer from 1 to 1000. */
|
|
156
|
+
numDocsToRerank: number;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
44
159
|
/**
|
|
45
160
|
* Automated Embedding configuration. MongoDB embeds the text at `path` when documents are
|
|
46
161
|
* written, and embeds a `queryText` string at query time, using the same model.
|
|
@@ -98,7 +213,11 @@ export interface MongoDBCreateIndexParams extends Omit<CreateIndexParams, 'dimen
|
|
|
98
213
|
* supports — are passed directly to `$vectorSearch` instead of pre-filtering
|
|
99
214
|
* candidate `_id`s, avoiding the 16 MB BSON limit on large result sets.
|
|
100
215
|
* Filters that reference an undeclared field, or use an unsupported
|
|
101
|
-
* operator, automatically fall back to the pre-filter
|
|
216
|
+
* operator, automatically fall back to the pre-filter, which fails once it
|
|
217
|
+
* matches more than 100,000 documents or its candidate `_id` array exceeds 12 MiB of BSON.
|
|
218
|
+
*
|
|
219
|
+
* With `collectionName` (bring-your-own), names are declared as root paths
|
|
220
|
+
* as given (e.g. `lane`), matching `metadataMode: 'document'` filters.
|
|
102
221
|
* @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/
|
|
103
222
|
*/
|
|
104
223
|
filterFields?: string[];
|
|
@@ -119,6 +238,9 @@ export interface MongoDBCreateIndexParams extends Omit<CreateIndexParams, 'dimen
|
|
|
119
238
|
* a BYO index is **read-only** — the store never mutates the caller's
|
|
120
239
|
* operational documents unless explicitly allowed. Ignored for managed
|
|
121
240
|
* collections (which the store owns and can always write to).
|
|
241
|
+
*
|
|
242
|
+
* @deprecated Keep bring-your-own collections read-only: write embeddings from your
|
|
243
|
+
* application or use `autoEmbed`. To be removed in the next major version.
|
|
122
244
|
*/
|
|
123
245
|
allowWrites?: boolean;
|
|
124
246
|
}
|
|
@@ -165,6 +287,7 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
165
287
|
* this process and lazily hydrated from the live index definition otherwise.
|
|
166
288
|
* `_id` is excluded because it is materialised separately by the fallback path.
|
|
167
289
|
*/
|
|
290
|
+
/** Filter paths per logical index, with the physical index (`collection/searchIndex`) they were read from. */
|
|
168
291
|
private declaredFilterPaths;
|
|
169
292
|
/**
|
|
170
293
|
* Per-index target: where the data lives, what the Atlas index is called, and whether
|
|
@@ -185,12 +308,27 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
185
308
|
* command; `version` is retained for the unsupported-version error message.
|
|
186
309
|
*/
|
|
187
310
|
private rankFusionSupport?;
|
|
311
|
+
/** Cached result of a successful transaction capability probe; a failed probe is never cached. */
|
|
312
|
+
private transactionSupport?;
|
|
313
|
+
/** @internal test seam; never set in production. */
|
|
314
|
+
private testHooks?;
|
|
188
315
|
/**
|
|
189
316
|
* Name of the mastra-owned collection that durably records the logical-index → target
|
|
190
317
|
* mapping (`_id: <indexName>`). Kept separate from caller data so a BYO operational
|
|
191
318
|
* collection is never polluted with mastra bookkeeping. Excluded from `listIndexes`.
|
|
192
319
|
*/
|
|
193
320
|
private static readonly REGISTRY_COLLECTION;
|
|
321
|
+
/** The provisioning journal (§2.2): one doc per search-index create attempt. Excluded from `listIndexes`. */
|
|
322
|
+
private static readonly JOURNAL_COLLECTION;
|
|
323
|
+
/** The journal's indexes, ensured once per instance; reset on failure so a later call retries. */
|
|
324
|
+
private journalIndexes?;
|
|
325
|
+
/** Set once the journal-index failure was logged, so a persistent failure warns once per instance. */
|
|
326
|
+
private journalIndexWarned;
|
|
327
|
+
/**
|
|
328
|
+
* Registry reads and writes, and their transactions, never inherit the client's read preference
|
|
329
|
+
* or concerns (I7a): a read from a lagging secondary would miss a committed registration.
|
|
330
|
+
*/
|
|
331
|
+
private static readonly TXN_OPTIONS;
|
|
194
332
|
/**
|
|
195
333
|
* Waits between attempts while a queried index is in INITIAL_SYNC, about six seconds in all.
|
|
196
334
|
* On a live Atlas cluster the window lasted around two seconds for both a regular and an
|
|
@@ -198,6 +336,10 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
198
336
|
* for long.
|
|
199
337
|
*/
|
|
200
338
|
private static readonly INITIAL_SYNC_RETRY_DELAYS_MS;
|
|
339
|
+
/** Maximum number of matching `_id`s materialized by the pre-filter fallback. */
|
|
340
|
+
private static readonly MAX_PREFILTER_CANDIDATES;
|
|
341
|
+
/** BSON array budget, reserving 4 MiB of the 16 MiB command limit for the rest of the pipeline. */
|
|
342
|
+
private static readonly MAX_PREFILTER_ID_BYTES;
|
|
201
343
|
/**
|
|
202
344
|
* MongoDB query operators supported inside `$vectorSearch.filter`. Intentionally
|
|
203
345
|
* conservative: filters using any operator outside this set fall back to the
|
|
@@ -223,13 +365,6 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
223
365
|
* async methods so awaiting is free.
|
|
224
366
|
*/
|
|
225
367
|
private resolveIndexTarget;
|
|
226
|
-
/**
|
|
227
|
-
* True when another logical index (a different registry `_id`) on the same collection
|
|
228
|
-
* references `physicalIndexName` as its vector or text search index. Used by deleteIndex
|
|
229
|
-
* to preserve a shared Atlas index that a sibling logical index still depends on
|
|
230
|
-
* (e.g. two BYO logical indexes on one collection sharing the default dynamic text index).
|
|
231
|
-
*/
|
|
232
|
-
private isIndexNameReferencedElsewhere;
|
|
233
368
|
/**
|
|
234
369
|
* Reject metadata containing circular references BEFORE it reaches the driver.
|
|
235
370
|
*
|
|
@@ -258,6 +393,55 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
258
393
|
* here instead of querying a non-existent Atlas index.
|
|
259
394
|
*/
|
|
260
395
|
private resolveTextSearchIndexName;
|
|
396
|
+
/** The registry handle, pinned to the primary with majority concerns (I7a). */
|
|
397
|
+
private registry;
|
|
398
|
+
/** The journal handle, with the registry's I7a options. */
|
|
399
|
+
private journal;
|
|
400
|
+
/** Run `fn` in a transaction with the I7a options. */
|
|
401
|
+
private inTransaction;
|
|
402
|
+
/**
|
|
403
|
+
* The lazy reconciler (§4): resolves this collection's journal docs whose lease expired. An
|
|
404
|
+
* `intent` never reached Atlas and goes; a `creating` one goes when its name is absent or its
|
|
405
|
+
* row is explained, and otherwise becomes `uncertain` (I9). Every write is conditioned on the
|
|
406
|
+
* observed state, so concurrent reconcilers and a live op never double-apply. A `created` doc
|
|
407
|
+
* is recorded (P7, P7b or P7c), an `orphaned` one cleaned from §3.8 step 2. Never throws.
|
|
408
|
+
* Returns the ids of the docs it tried, so the call's handshake cleans a stale block only once.
|
|
409
|
+
*/
|
|
410
|
+
private reconcile;
|
|
411
|
+
/** Expire a journal doc still in `doc.state` now, so any call retries it at once and behind older ones (R14). */
|
|
412
|
+
private expireLease;
|
|
413
|
+
/**
|
|
414
|
+
* §4.2 `created`: P7 with the stored id, else P7b (retired) or P7c (§3.8 from step 1), as the op
|
|
415
|
+
* would; their CONFLICT is only logged here. P7 and P7b take the doc in their transaction, so a
|
|
416
|
+
* second reconciler's transaction conflicts, then finds it gone and stops.
|
|
417
|
+
*/
|
|
418
|
+
private reconcileCreated;
|
|
419
|
+
/** §4.2 `creating`: list the name, then delete the doc or mark it `uncertain`. */
|
|
420
|
+
private reconcileCreating;
|
|
421
|
+
private warnUncertain;
|
|
422
|
+
private warnForeignByTimestamp;
|
|
423
|
+
/**
|
|
424
|
+
* The only path for `createSearchIndexes`, `dropSearchIndex` and `updateSearchIndex` (I7a): on the
|
|
425
|
+
* primary, with no read or write concern, which the server rejects for these commands.
|
|
426
|
+
*/
|
|
427
|
+
private runSearchIndexCommand;
|
|
428
|
+
/**
|
|
429
|
+
* List the search indexes named `name` on the primary with `readConcern: local` (I7a). The driver's
|
|
430
|
+
* listing cursor ignores the handle's and the client's settings, and takes a read preference only
|
|
431
|
+
* as a `ReadPreference` instance, so both are passed per call. A missing collection has none.
|
|
432
|
+
*/
|
|
433
|
+
private listSearchIndexRows;
|
|
434
|
+
/** The id of the live row listed for `name`; a dying row is present but not ours (§3.1), so it counts as none. */
|
|
435
|
+
private liveIdOf;
|
|
436
|
+
/**
|
|
437
|
+
* §2.3 refresh-time TOFU (Q5): for each owned name with no `indexIds` entry, list it and record the
|
|
438
|
+
* observed id. Filtered on the name still owned, no entry yet, and the call's P0 pin, so only a
|
|
439
|
+
* call whose P0 is still the latest write records it, and only once. A write advances `pin` in
|
|
440
|
+
* place, so the call's rollback (§3.9) still matches and undoes P0's fields; it keeps the id,
|
|
441
|
+
* which is TOFU proof of a name the registration already owned (§2.3), not part of P0's write.
|
|
442
|
+
* Best effort: delete-time TOFU (§3.7) covers a name it misses.
|
|
443
|
+
*/
|
|
444
|
+
private tofuIndexIds;
|
|
261
445
|
/** Read a logical-index target from the durable registry collection, if present. */
|
|
262
446
|
private readRegistryEntry;
|
|
263
447
|
/**
|
|
@@ -269,16 +453,134 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
269
453
|
* still pins `_id`, an incompatible entry matches nothing, the upsert attempts an insert, and
|
|
270
454
|
* the duplicate `_id` surfaces as a duplicate-key error (code 11000) instead of overwriting
|
|
271
455
|
* the entry someone else registered. Callers that only refresh part of an entry omit it.
|
|
456
|
+
*
|
|
457
|
+
* Every write backfills `generation`, bumps `rev` and sets the `claimToken` in `entry` (a fresh
|
|
458
|
+
* one if absent). `expressions` are pipeline expressions set in the same stage, so they read the
|
|
459
|
+
* pre-write document. Returns what it left, or null when nothing matched without upsert.
|
|
272
460
|
*/
|
|
273
461
|
private writeRegistryEntry;
|
|
274
|
-
/** Remove a logical-index target from the durable registry (called by deleteIndex). */
|
|
275
|
-
private deleteRegistryEntry;
|
|
276
462
|
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
|
|
463
|
+
* A P0 write. It returns the document as it was before the write, so a rollback restores what
|
|
464
|
+
* this write overwrote (not what the call read earlier) and removes the entry only when this
|
|
465
|
+
* write inserted it (I4). The pin is derived from that pre-image: the same `$ifNull` generation
|
|
466
|
+
* and `rev + 1` the pipeline computes. Null when nothing matched and nothing was inserted.
|
|
467
|
+
*/
|
|
468
|
+
private p0Write;
|
|
469
|
+
/**
|
|
470
|
+
* P7: record that this store created search index `name` for `role`, with its proven `id`.
|
|
471
|
+
* Pinned on the registration's `generation` and on `name` still being its current name for the
|
|
472
|
+
* role, not on the call's `claimToken`, so an identical concurrent refresh never makes it miss.
|
|
473
|
+
* The id guard (I11b) requires the name's `indexIds` entry to be absent, `id`, or the R′ read
|
|
474
|
+
* just before; a newer R′ (another call's later create) is kept and logged. No upsert, so a
|
|
475
|
+
* deleted entry stays deleted. Bumps `rev` and sets a fresh `claimToken`, so a concurrent
|
|
476
|
+
* call's rollback never restores a snapshot from before this flag. Returns the id recorded
|
|
477
|
+
* for the name (`id`, or the newer R′ kept), or undefined when the write missed.
|
|
478
|
+
*/
|
|
479
|
+
private recordOwnership;
|
|
480
|
+
/**
|
|
481
|
+
* Provision one search index (§3.1): the attach fast path (P1), the journal intent (P2), the P3
|
|
482
|
+
* check, the decisive pre-list (P3a), the fence (P3b), the create by raw command (P4), the
|
|
483
|
+
* verdict (P5), the durable proof (P6) and recording the proven id (P7). Never rolls back itself;
|
|
484
|
+
* every failure is a {@link ProvisionAbort} telling the caller whether it still may.
|
|
485
|
+
*/
|
|
486
|
+
private provisionSearchIndex;
|
|
487
|
+
/**
|
|
488
|
+
* Undo this call's P0 write after provisioning failed (§3.9). Pinned on the `generation`,
|
|
489
|
+
* `claimToken` and `rev` P0 left (I4): any write since (a refresh, a P7, a claim, a delete
|
|
490
|
+
* transaction) makes it miss, and then everything stays as it is. `restore` null means P0
|
|
491
|
+
* inserted the entry, so it is removed; otherwise only the fields P0 wrote are restored, with
|
|
492
|
+
* `rev` bumped and a fresh `claimToken`, so `rev` never goes down and a backfilled `generation`
|
|
493
|
+
* stays. Callers never run it after a P7 of the same call. Best effort, so the caller still sees
|
|
494
|
+
* the provisioning error. Returns true when the inserted entry was removed.
|
|
495
|
+
*/
|
|
496
|
+
private rollbackRegistryEntry;
|
|
497
|
+
/** Refuse to reuse an entry whose deletion has started; only finishing the delete clears it. */
|
|
498
|
+
private assertNotDeleting;
|
|
499
|
+
/**
|
|
500
|
+
* Whether the deployment supports transactions (replica set or sharded cluster). Throws when
|
|
501
|
+
* the check itself fails: a failed check must never be mistaken for a standalone server.
|
|
502
|
+
*/
|
|
503
|
+
private probeTransactionSupport;
|
|
504
|
+
/**
|
|
505
|
+
* Run a delete decision in a transaction, or directly on a confirmed standalone server.
|
|
506
|
+
* Returns only the result of the attempt that committed. Never rolls registry state back.
|
|
507
|
+
*/
|
|
508
|
+
private runDeleteTransaction;
|
|
509
|
+
/**
|
|
510
|
+
* Whether `own` (read inside a delete transaction) is a newer lifetime than `entry` (the call's
|
|
511
|
+
* first read): true means the registration to delete is finished and `own` replaced it. An entry
|
|
512
|
+
* read without a generation can't tell a backfill from a replacement, so that refuses retryably.
|
|
513
|
+
*/
|
|
514
|
+
private replacedSince;
|
|
515
|
+
/**
|
|
516
|
+
* Delete a registration whose collection stays (BYO, or managed with `ownsCollection: false`).
|
|
517
|
+
* Step 1 decides, in one transaction, which Mastra-created search indexes to drop and which to
|
|
518
|
+
* hand to a sibling still using them; steps 2 and 3 drop the rest and remove the entry. A
|
|
519
|
+
* `null` collection means it is gone, so every drop is already done.
|
|
520
|
+
*/
|
|
521
|
+
private deleteKeepCollection;
|
|
522
|
+
/**
|
|
523
|
+
* Write a delete plan's transfers (the owns flag, plus the id when the plan carries one) and id
|
|
524
|
+
* rewrites, and log its kept names. Every user the plan chose (a recipient, or an owner of a
|
|
525
|
+
* released name among `siblings`) gets `rev + 1` and a fresh `claimToken` (R4-2, R5-2), so a
|
|
526
|
+
* pinned undo by its own op misses; the other live siblings get `rev + 1`. False when a recipient
|
|
527
|
+
* no longer uses the name it was planned for, or an owner no longer owns the name it was to
|
|
528
|
+
* rewrite, which only a deployment without transactions can see.
|
|
529
|
+
*/
|
|
530
|
+
private applyCleanupWrites;
|
|
531
|
+
/**
|
|
532
|
+
* Last check before a delete drops `name`: a registration that started using it after the delete
|
|
533
|
+
* committed its drop set takes over the cleanup responsibility instead (or keeps it, if it
|
|
534
|
+
* already owns the index), and the name leaves this delete's drop set. This is the delete half
|
|
535
|
+
* of a write-then-read handshake with {@link assertNoPendingDrop}: each side writes its
|
|
536
|
+
* registration state before reading the other's, and both reads go to the primary (the client's
|
|
537
|
+
* default), which returns every committed write, so at least one side sees the conflict.
|
|
538
|
+
* Returns `drop` when nothing uses the name, `kept` when it was handed over, `gone` when another
|
|
539
|
+
* call finished this delete attempt.
|
|
540
|
+
*/
|
|
541
|
+
private handOverPendingDrop;
|
|
542
|
+
/**
|
|
543
|
+
* §3.8: proven incarnation `doc.indexId` (R) of `doc.name` lost the registration of its lifetime.
|
|
544
|
+
* Step 1 marks the journal doc `orphaned` (the cleaner half of the I7 handshake: written before
|
|
545
|
+
* the users are read, so an attach either sees it or is seen). Step 3 decides in a transaction
|
|
546
|
+
* that re-reads the doc and the users: any live user blocks the drop (I11a); owners are released,
|
|
547
|
+
* else the lowest-`_id` user gets R when the listing confirms it; every user written gets
|
|
548
|
+
* `rev + 1` and a fresh `claimToken` (R4-2). With no user, the decision to drop is written to the
|
|
549
|
+
* doc (R11), so every later cleaner drops too instead of handing R to a later attacher, and step
|
|
550
|
+
* 4 drops R by id. The doc goes only after the drop, so attaches stay refused (M8) until then. A
|
|
551
|
+
* failed drop keeps the doc, logs at error and returns `failed`.
|
|
552
|
+
*/
|
|
553
|
+
private cleanupOrphan;
|
|
554
|
+
/**
|
|
555
|
+
* Refuse to reference a search index that a delete in progress is about to drop. The attach half
|
|
556
|
+
* of the handshake described on {@link handOverPendingDrop}: callers run it after writing their
|
|
557
|
+
* registration, so either this read sees the pending drop or the delete's read sees the registration.
|
|
558
|
+
*
|
|
559
|
+
* It also re-reads this call's own entry, which a deleteIndex may have removed or started removing
|
|
560
|
+
* since the write: provisioning then would leave a search index no registration records. Callers
|
|
561
|
+
* run it last before provisioning. The entry must still record `collectionName` and every name in
|
|
562
|
+
* `expected`, the targets this call provisions: another call may have retargeted it since, and
|
|
563
|
+
* provisioning the old target would leave an index nothing records. A rewrite with the same
|
|
564
|
+
* targets (an identical concurrent call) passes. Last, it must still carry `generation`, the one
|
|
565
|
+
* this call's write left: a delete and an identical recreate (or an old-code recreate without a
|
|
566
|
+
* generation) is another registration, and this call must not provision for it.
|
|
567
|
+
*/
|
|
568
|
+
private assertNoPendingDrop;
|
|
569
|
+
/**
|
|
570
|
+
* The read half of the I7 handshake: the `INDEX_DELETING` error for the first of `names` an
|
|
571
|
+
* `orphaned` journal doc or another registration's `deleting` drop set covers, if any. A stale
|
|
572
|
+
* orphan block is cleaned once per call (the call's own reconcile counts), then re-checked (P3).
|
|
573
|
+
*/
|
|
574
|
+
private pendingDropError;
|
|
575
|
+
/**
|
|
576
|
+
* Delete a managed registration with recorded ownership (`ownsCollection: true`) by dropping
|
|
577
|
+
* its collection, which removes every search index on it. Refuses with `IN_USE` while any other
|
|
578
|
+
* registration points at the collection. Same token protocol as `deleteKeepCollection`.
|
|
579
|
+
*/
|
|
580
|
+
private deleteManagedCollection;
|
|
581
|
+
/**
|
|
582
|
+
* $rankFusion is available in MongoDB >= 8.0, so the gate rejects only older servers and lets the
|
|
583
|
+
* server be the final authority on anything else.
|
|
282
584
|
*/
|
|
283
585
|
private assertRankFusionSupported;
|
|
284
586
|
/** Validates a text upsert: `documents` is present, and `metadata`/`ids` line up with it. */
|
|
@@ -324,18 +626,22 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
324
626
|
* "index not found" or "index not ready" errors on subsequent operations.
|
|
325
627
|
*/
|
|
326
628
|
createIndex(params: MongoDBCreateIndexParams): Promise<void>;
|
|
629
|
+
/** `refresh` marks the single retry after losing a registration race to a compatible entry. */
|
|
630
|
+
private createIndexAttempt;
|
|
327
631
|
/**
|
|
328
|
-
*
|
|
329
|
-
* `
|
|
330
|
-
*
|
|
632
|
+
* The only search-index drop (I1): by `id`, so only that incarnation goes. `IndexNotFound` and
|
|
633
|
+
* `NamespaceNotFound` mean it is already gone (with its collection, for the latter), which
|
|
634
|
+
* counts as done, so a retried delete still clears its registry entry.
|
|
331
635
|
*/
|
|
332
|
-
private
|
|
636
|
+
private dropSearchIndexById;
|
|
333
637
|
/**
|
|
334
|
-
* Drop
|
|
335
|
-
*
|
|
336
|
-
*
|
|
638
|
+
* Drop `name` by its recorded `id`. A legacy name with none is listed and dropped by the observed
|
|
639
|
+
* id (§3.7, delete-time TOFU); absent means done. Residual X2: an external drop and recreate
|
|
640
|
+
* before this listing makes the observed id the stranger's.
|
|
337
641
|
*/
|
|
338
|
-
private
|
|
642
|
+
private dropRecordedOrListed;
|
|
643
|
+
/** Atlas Search reads a dotted mapping key as a literal field name, so nested paths need `document` mappings. */
|
|
644
|
+
private toSearchFieldMappings;
|
|
339
645
|
/**
|
|
340
646
|
* Provision an Atlas Search (BM25/full-text) index on the index's collection and record
|
|
341
647
|
* it as the text-search index that `textQuery`/`hybridQuery` will target.
|
|
@@ -380,37 +686,23 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
380
686
|
/**
|
|
381
687
|
* Run a hybrid search that fuses vector similarity and full-text (BM25) results
|
|
382
688
|
* using MongoDB's server-side $rankFusion aggregation stage. Requires MongoDB >= 8.0
|
|
383
|
-
* (see {@link assertRankFusionSupported}
|
|
384
|
-
* need a MongoDB support case to enable, and runs where enabled, e.g. Atlas 8.0.x).
|
|
689
|
+
* (see {@link assertRankFusionSupported}).
|
|
385
690
|
*/
|
|
386
|
-
hybridQuery(params:
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
query: string;
|
|
402
|
-
paths: string[];
|
|
403
|
-
topK?: number;
|
|
404
|
-
filter?: MongoDBVectorFilter;
|
|
405
|
-
weights?: {
|
|
406
|
-
vector?: number;
|
|
407
|
-
text?: number;
|
|
408
|
-
};
|
|
409
|
-
numCandidates?: number;
|
|
410
|
-
metadataMode?: 'field' | 'document';
|
|
411
|
-
/** Override the resolved full-text search index name for this call. */
|
|
412
|
-
textSearchIndexName?: string;
|
|
413
|
-
}): Promise<QueryResult[]>;
|
|
691
|
+
hybridQuery(params: MongoDBHybridQueryParams): Promise<QueryResult[]>;
|
|
692
|
+
/**
|
|
693
|
+
* Fuse vector and full-text results with independent retrieval limits and optional native
|
|
694
|
+
* reranking. Returns QueryResult[] with the final fusion or reranking score.
|
|
695
|
+
*
|
|
696
|
+
* @see https://mastra.ai/reference/vectors/mongodb#per-branch-options-and-native-reranking
|
|
697
|
+
* @see https://www.mongodb.com/docs/vector-search/query/aggregation-stages/rerank/
|
|
698
|
+
* @throws {MastraError} Invalid inputs, incompatible indexes, or server failures. Server
|
|
699
|
+
* errors retain their causes; reranking is never silently skipped or substituted.
|
|
700
|
+
*/
|
|
701
|
+
hybridQuery(params: MongoDBHybridQueryBranchParams): Promise<QueryResult[]>;
|
|
702
|
+
private hybridQueryBranches;
|
|
703
|
+
/** Builds and runs the $rankFusion pipeline shared by both hybridQuery shapes. */
|
|
704
|
+
private runHybridPipeline;
|
|
705
|
+
private validateHybridQueryBranchParams;
|
|
414
706
|
/**
|
|
415
707
|
* Waits for the index to be ready.
|
|
416
708
|
*
|
|
@@ -471,6 +763,12 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
471
763
|
* @returns Array of results ordered by descending similarity score.
|
|
472
764
|
*/
|
|
473
765
|
query({ indexName, queryVector, queryText, model, topK, filter, includeVector, documentFilter, numCandidates, metadataMode, }: MongoDBQueryVectorParams): Promise<QueryResult[]>;
|
|
766
|
+
/**
|
|
767
|
+
* Runs a filter that `$vectorSearch` cannot apply itself and returns the matching `_id`s.
|
|
768
|
+
* Reads one id past {@link MongoDBVector.MAX_PREFILTER_CANDIDATES} so an oversized set fails
|
|
769
|
+
* with a USER error instead of exhausting memory or the 16 MB command limit.
|
|
770
|
+
*/
|
|
771
|
+
private collectCandidateIds;
|
|
474
772
|
/**
|
|
475
773
|
* Runs a `$vectorSearch` pipeline, retrying while the index is in INITIAL_SYNC.
|
|
476
774
|
*
|
|
@@ -502,7 +800,19 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
502
800
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
503
801
|
*/
|
|
504
802
|
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
803
|
+
/**
|
|
804
|
+
* Reads dimension and metric from the Atlas vectorSearch index definition. Unlike
|
|
805
|
+
* {@link describeIndex} it never counts documents, so writes can validate dimensions
|
|
806
|
+
* without scanning the collection.
|
|
807
|
+
*/
|
|
808
|
+
private readVectorIndexDefinition;
|
|
505
809
|
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
810
|
+
/**
|
|
811
|
+
* One-time upgrade helper for managed indexes created before `@mastra/mongodb@1.15.0`, or registered by 1.15–1.27 without ownership records. Calling it asserts that Mastra created the collection and its recorded search indexes; `deleteIndex()` will then drop the collection and all its data.
|
|
812
|
+
*/
|
|
813
|
+
claimLegacyIndex({ indexName }: {
|
|
814
|
+
indexName: string;
|
|
815
|
+
}): Promise<void>;
|
|
506
816
|
/**
|
|
507
817
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
508
818
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -550,6 +860,10 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
550
860
|
* qualified filter paths stored in the index, e.g. `category` → `metadata.category`.
|
|
551
861
|
* Blank entries are dropped and duplicates collapsed. A name already carrying the
|
|
552
862
|
* `metadata.` prefix is left untouched so callers can pass either form.
|
|
863
|
+
*
|
|
864
|
+
* A bring-your-own collection keeps its fields at the document root, where document-mode
|
|
865
|
+
* filters address them, so its names are declared as given. `_id` and `document` are
|
|
866
|
+
* skipped there because createIndex always declares them.
|
|
553
867
|
*/
|
|
554
868
|
private buildDeclaredMetadataPaths;
|
|
555
869
|
/**
|
|
@@ -584,6 +898,11 @@ export declare class MongoDBVector extends MastraVector<MongoDBVectorFilter> {
|
|
|
584
898
|
* occur outside deliberately mixed test data.
|
|
585
899
|
*/
|
|
586
900
|
private buildIdMatch;
|
|
901
|
+
/**
|
|
902
|
+
* Convert Date values to ISO strings. Object.fromEntries keeps a `__proto__` key as data
|
|
903
|
+
* instead of replacing the prototype and losing it.
|
|
904
|
+
*/
|
|
905
|
+
private normalizeMetadata;
|
|
587
906
|
private transformFilter;
|
|
588
907
|
/**
|
|
589
908
|
* Transform metadata field filters to use MongoDB dot notation.
|