@mastra/mongodb 1.25.0-alpha.0 → 1.26.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.
@@ -0,0 +1,338 @@
1
+ export declare const KNOWLEDGE_STORAGE_CONTRACT_VERSION: 4;
2
+ export declare const KNOWLEDGE_STORAGE_SCHEMA_VERSION: 4;
3
+ export declare const TABLE_KNOWLEDGE_NODE_SCOPES = "mastra_knowledge_node_scopes";
4
+ export declare const TABLE_KNOWLEDGE_RECORD_SCOPES = "mastra_knowledge_record_scopes";
5
+ export declare const TABLE_KNOWLEDGE_SCOPE_GRANTS = "mastra_knowledge_scope_grants";
6
+ export declare const TABLE_KNOWLEDGE_ACCESS_STATE = "mastra_knowledge_access_state";
7
+ export declare const TABLE_KNOWLEDGE_SCOPE_ADDRESSES = "mastra_knowledge_scope_addresses";
8
+ export declare const TABLE_KNOWLEDGE_NODE_ADDRESSES = "mastra_knowledge_node_addresses";
9
+ export declare const TABLE_KNOWLEDGE_IMPORT_STATE = "mastra_knowledge_import_state";
10
+ export declare const TABLE_KNOWLEDGE_IMPORT_RUNS = "mastra_knowledge_import_runs";
11
+ export declare const TABLE_KNOWLEDGE_PROPOSALS = "mastra_knowledge_proposals";
12
+ export declare const KNOWLEDGE_TABLE_NAMES: readonly ["mastra_knowledge_nodes", "mastra_knowledge_records", "mastra_knowledge_mentions", "mastra_knowledge_activity", "mastra_knowledge_semantic_outbox", "mastra_knowledge_node_scopes", "mastra_knowledge_record_scopes", "mastra_knowledge_scope_grants", "mastra_knowledge_access_state", "mastra_knowledge_scope_addresses", "mastra_knowledge_node_addresses", "mastra_knowledge_import_state", "mastra_knowledge_import_runs", "mastra_knowledge_proposals"];
13
+ /** Knowledge v1 tables with no v2 equivalent; an explicit schema reset drops them. */
14
+ export declare const RETIRED_KNOWLEDGE_TABLE_NAMES: readonly ['mastra_knowledge_cursors'];
15
+ export declare const KNOWLEDGE_PAGES_CORE_FEATURE = "knowledge-pages";
16
+ export declare const KNOWLEDGE_PAGES_SCHEMA_VERSION: 4;
17
+ export declare const TABLE_KNOWLEDGE_PAGES = "mastra_knowledge_pages";
18
+ export declare const TABLE_KNOWLEDGE_NOTES = "mastra_knowledge_notes";
19
+ export declare const TABLE_KNOWLEDGE_NOTE_STAMPS = "mastra_knowledge_note_stamps";
20
+ /** Same name as the schema-2 table; schema 4 re-keys it to note → page. */
21
+ export declare const TABLE_KNOWLEDGE_PAGE_MENTIONS = "mastra_knowledge_mentions";
22
+ export declare const TABLE_KNOWLEDGE_PINS = "mastra_knowledge_pins";
23
+ /** Same name as schema 2; schema 4 re-keys it to scope/page/note. */
24
+ export declare const TABLE_KNOWLEDGE_PAGE_ACTIVITY = "mastra_knowledge_activity";
25
+ /** Holds `{ id: 'knowledge', schemaVersion: 4 }`, written when the schema-4 tables are created. */
26
+ export declare const TABLE_KNOWLEDGE_PAGES_STATE = "mastra_knowledge_access_state";
27
+ export declare const KNOWLEDGE_PAGES_TABLE_NAMES: readonly ["mastra_knowledge_pages", "mastra_knowledge_notes", "mastra_knowledge_note_stamps", "mastra_knowledge_mentions", "mastra_knowledge_pins", "mastra_knowledge_activity", "mastra_knowledge_access_state"];
28
+ /** Every Knowledge table any schema version created. Reset drops these and nothing else. */
29
+ export declare const KNOWLEDGE_RESETTABLE_TABLE_NAMES: readonly string[];
30
+ /** Schema-1/2 tables whose presence means the store needs a reset before schema 4 can run. */
31
+ export declare const LEGACY_KNOWLEDGE_TABLE_NAMES: ReadonlySet<string>;
32
+ /** Pages and scope pages. `scopeId` equals `id` on scope pages; `address`/`declaration` only on scope pages. */
33
+ export declare const KNOWLEDGE_PAGES_SCHEMA: {
34
+ readonly id: {
35
+ readonly type: 'text';
36
+ readonly nullable: false;
37
+ readonly primaryKey: true;
38
+ };
39
+ readonly scopeId: {
40
+ readonly type: 'text';
41
+ readonly nullable: false;
42
+ };
43
+ readonly parentId: {
44
+ readonly type: 'text';
45
+ readonly nullable: true;
46
+ };
47
+ readonly isScope: {
48
+ readonly type: 'boolean';
49
+ readonly nullable: false;
50
+ };
51
+ readonly address: {
52
+ readonly type: 'text';
53
+ readonly nullable: true;
54
+ };
55
+ readonly declaration: {
56
+ readonly type: 'text';
57
+ readonly nullable: true;
58
+ };
59
+ readonly key: {
60
+ readonly type: 'text';
61
+ readonly nullable: true;
62
+ };
63
+ readonly position: {
64
+ readonly type: 'text';
65
+ readonly nullable: false;
66
+ };
67
+ readonly name: {
68
+ readonly type: 'text';
69
+ readonly nullable: false;
70
+ };
71
+ readonly canonicalName: {
72
+ readonly type: 'text';
73
+ readonly nullable: false;
74
+ };
75
+ readonly description: {
76
+ readonly type: 'text';
77
+ readonly nullable: true;
78
+ };
79
+ readonly body: {
80
+ readonly type: 'text';
81
+ readonly nullable: true;
82
+ };
83
+ readonly version: {
84
+ readonly type: 'integer';
85
+ readonly nullable: false;
86
+ };
87
+ readonly mergedInto: {
88
+ readonly type: 'text';
89
+ readonly nullable: true;
90
+ };
91
+ readonly createdBy: {
92
+ readonly type: 'jsonb';
93
+ readonly nullable: false;
94
+ };
95
+ readonly updatedBy: {
96
+ readonly type: 'jsonb';
97
+ readonly nullable: false;
98
+ };
99
+ readonly createdAt: {
100
+ readonly type: 'timestamp';
101
+ readonly nullable: false;
102
+ };
103
+ readonly updatedAt: {
104
+ readonly type: 'timestamp';
105
+ readonly nullable: false;
106
+ };
107
+ readonly deletedAt: {
108
+ readonly type: 'timestamp';
109
+ readonly nullable: true;
110
+ };
111
+ readonly deletedBy: {
112
+ readonly type: 'text';
113
+ readonly nullable: true;
114
+ };
115
+ };
116
+ export declare const KNOWLEDGE_NOTES_SCHEMA: {
117
+ readonly id: {
118
+ readonly type: 'text';
119
+ readonly nullable: false;
120
+ readonly primaryKey: true;
121
+ };
122
+ readonly pageId: {
123
+ readonly type: 'text';
124
+ readonly nullable: false;
125
+ readonly references: {
126
+ readonly table: "mastra_knowledge_pages";
127
+ readonly column: 'id';
128
+ };
129
+ };
130
+ readonly text: {
131
+ readonly type: 'text';
132
+ readonly nullable: false;
133
+ };
134
+ readonly when: {
135
+ readonly type: 'timestamp';
136
+ readonly nullable: true;
137
+ };
138
+ readonly provenance: {
139
+ readonly type: 'jsonb';
140
+ readonly nullable: false;
141
+ };
142
+ readonly version: {
143
+ readonly type: 'integer';
144
+ readonly nullable: false;
145
+ };
146
+ readonly createdAt: {
147
+ readonly type: 'timestamp';
148
+ readonly nullable: false;
149
+ };
150
+ readonly updatedAt: {
151
+ readonly type: 'timestamp';
152
+ readonly nullable: false;
153
+ };
154
+ readonly deletedAt: {
155
+ readonly type: 'timestamp';
156
+ readonly nullable: true;
157
+ };
158
+ readonly deletedBy: {
159
+ readonly type: 'text';
160
+ readonly nullable: true;
161
+ };
162
+ };
163
+ /** One row per (note, stamp scope). Primary key is the pair. */
164
+ export declare const KNOWLEDGE_NOTE_STAMPS_SCHEMA: {
165
+ readonly noteId: {
166
+ readonly type: 'text';
167
+ readonly nullable: false;
168
+ readonly references: {
169
+ readonly table: "mastra_knowledge_notes";
170
+ readonly column: 'id';
171
+ };
172
+ };
173
+ readonly scopeId: {
174
+ readonly type: 'text';
175
+ readonly nullable: false;
176
+ readonly references: {
177
+ readonly table: "mastra_knowledge_pages";
178
+ readonly column: 'id';
179
+ };
180
+ };
181
+ };
182
+ /** One row per (note, mentioned page). Primary key is the pair. */
183
+ export declare const KNOWLEDGE_PAGE_MENTIONS_SCHEMA: {
184
+ readonly noteId: {
185
+ readonly type: 'text';
186
+ readonly nullable: false;
187
+ readonly references: {
188
+ readonly table: "mastra_knowledge_notes";
189
+ readonly column: 'id';
190
+ };
191
+ };
192
+ readonly pageId: {
193
+ readonly type: 'text';
194
+ readonly nullable: false;
195
+ readonly references: {
196
+ readonly table: "mastra_knowledge_pages";
197
+ readonly column: 'id';
198
+ };
199
+ };
200
+ };
201
+ /** `audience` is a JSON array of scope addresses (PG may store it as `text[]`, Mongo as an array). */
202
+ export declare const KNOWLEDGE_PINS_SCHEMA: {
203
+ readonly id: {
204
+ readonly type: 'text';
205
+ readonly nullable: false;
206
+ readonly primaryKey: true;
207
+ };
208
+ readonly pageId: {
209
+ readonly type: 'text';
210
+ readonly nullable: false;
211
+ readonly references: {
212
+ readonly table: "mastra_knowledge_pages";
213
+ readonly column: 'id';
214
+ };
215
+ };
216
+ readonly audience: {
217
+ readonly type: 'jsonb';
218
+ readonly nullable: false;
219
+ };
220
+ readonly createdBy: {
221
+ readonly type: 'text';
222
+ readonly nullable: false;
223
+ };
224
+ readonly createdAt: {
225
+ readonly type: 'timestamp';
226
+ readonly nullable: false;
227
+ };
228
+ readonly updatedAt: {
229
+ readonly type: 'timestamp';
230
+ readonly nullable: false;
231
+ };
232
+ };
233
+ export declare const KNOWLEDGE_PAGE_ACTIVITY_SCHEMA: {
234
+ readonly id: {
235
+ readonly type: 'text';
236
+ readonly nullable: false;
237
+ readonly primaryKey: true;
238
+ };
239
+ readonly action: {
240
+ readonly type: 'text';
241
+ readonly nullable: false;
242
+ };
243
+ readonly scopeId: {
244
+ readonly type: 'text';
245
+ readonly nullable: false;
246
+ };
247
+ readonly pageId: {
248
+ readonly type: 'text';
249
+ readonly nullable: false;
250
+ };
251
+ readonly noteId: {
252
+ readonly type: 'text';
253
+ readonly nullable: true;
254
+ };
255
+ readonly provenance: {
256
+ readonly type: 'jsonb';
257
+ readonly nullable: false;
258
+ };
259
+ readonly createdAt: {
260
+ readonly type: 'timestamp';
261
+ readonly nullable: false;
262
+ };
263
+ };
264
+ export declare const KNOWLEDGE_PAGES_STATE_SCHEMA: {
265
+ readonly id: {
266
+ readonly type: 'text';
267
+ readonly nullable: false;
268
+ readonly primaryKey: true;
269
+ };
270
+ readonly schemaVersion: {
271
+ readonly type: 'integer';
272
+ readonly nullable: false;
273
+ };
274
+ };
275
+ export type KnowledgePagesSchemaInspection = {
276
+ status: 'compatible';
277
+ schemaVersion: typeof KNOWLEDGE_PAGES_SCHEMA_VERSION;
278
+ } | {
279
+ status: 'uninitialized';
280
+ schemaVersion: null;
281
+ } | {
282
+ status: 'incompatible-reset-required';
283
+ schemaVersion: number | null;
284
+ reason: string;
285
+ };
286
+ /**
287
+ * Classifies what an adapter found before creating schema-4 tables. `tableNames` is every
288
+ * `mastra_knowledge_*` table present; `schemaVersion` is the state row's version, if any.
289
+ */
290
+ export declare function inspectKnowledgePagesSchema(snapshot: {
291
+ tableNames: readonly string[];
292
+ schemaVersion?: number;
293
+ }): KnowledgePagesSchemaInspection;
294
+ /**
295
+ * The old Knowledge tables an adapter drops on init, rows included: Knowledge before schema 4 was an
296
+ * experimental store with no migration. Every schema-1/2-only table present is dropped. The table
297
+ * names schema 4 reuses (mentions, activity, the state table) are dropped too, but only when an old
298
+ * table is present and no schema-4 state row exists, so they are old-shaped. Schema-4-only tables
299
+ * are never listed. On a schema-4 store this lists only tables an older process recreated during a
300
+ * rolling deploy. Drop order is safe for adapters that enforce references.
301
+ */
302
+ export declare function legacyKnowledgeTablesToDrop(snapshot: {
303
+ tableNames: readonly string[];
304
+ schemaVersion?: number;
305
+ }): string[];
306
+ /** Message for the error an adapter throws on `incompatible-reset-required`. */
307
+ export declare function knowledgePagesResetMessage(reason: string): string;
308
+ /**
309
+ * The page-store runtime pieces adapters take from `@mastra/core/storage`. They are loaded through
310
+ * `createKnowledgePagesCoreLoader` instead of static imports so adapters keep loading on cores
311
+ * older than the `knowledge-pages` feature without raising their `@mastra/core` peer floor.
312
+ */
313
+ export interface KnowledgePagesCore {
314
+ assertKnowledgePageDescriptionWithinBound(description: string | undefined): void;
315
+ assertKnowledgeNoteTextWithinBound(text: string): void;
316
+ canonicalKnowledgeName(name: string): string;
317
+ knowledgePositionBetween(before?: string, after?: string): string;
318
+ MAX_KNOWLEDGE_MOVE_PAGES: number;
319
+ MAX_KNOWLEDGE_PAGE_DEPTH: number;
320
+ MAX_KNOWLEDGE_PAGE_LIST_LIMIT: number;
321
+ KnowledgeMoveTooLargeError: new (pageId: string, pages: number) => Error;
322
+ KnowledgePageDepthError: new (pageId: string) => Error;
323
+ KnowledgePageHasChildrenError: new (pageId: string) => Error;
324
+ KnowledgePageKeyConflictError: new (key: string, parentId: string) => Error;
325
+ }
326
+ /** Loads core's page-store runtime once, after checking core advertises `knowledge-pages`. */
327
+ export declare function createKnowledgePagesCoreLoader(features: ReadonlySet<string>, loadStorageModule: () => Promise<unknown>): () => Promise<KnowledgePagesCore>;
328
+ /**
329
+ * Keyword-search words: the query split on whitespace, lowercased, deduplicated. Every word must
330
+ * appear (as a case-insensitive substring) in a hit; an empty list means the search returns nothing.
331
+ */
332
+ export declare function knowledgeSearchWords(query: string): string[];
333
+ /**
334
+ * Why `key` can't be a Knowledge page key, or undefined when it can. Keys are one path segment:
335
+ * non-empty, with no `/` (path separator), `#` (scope/path separator) or `%` (escape character).
336
+ */
337
+ export declare function knowledgePageKeyProblem(key: string): string | undefined;
338
+ //# sourceMappingURL=index.d.ts.map
@@ -3,7 +3,7 @@ name: mastra-mongodb
3
3
  description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mongodb"
6
- version: "1.25.0-alpha.0"
6
+ version: "1.26.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.25.0-alpha.0",
2
+ "version": "1.26.0-alpha.0",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -435,6 +435,8 @@ When using PostgreSQL as your vector store, you can optimize semantic recall per
435
435
 
436
436
  PostgreSQL supports both IVFFlat and HNSW indexes. By default, Mastra creates an IVFFlat index, but HNSW indexes typically provide better performance, especially with OpenAI embeddings which use inner product distance.
437
437
 
438
+ Semantic recall always filters by thread or resource. PgVector uses the vector index for these searches only with HNSW on pgvector 0.8.0 or newer. With IVFFlat, each search compares the query against every message in the thread or resource.
439
+
438
440
  ```typescript
439
441
  import { Memory } from '@mastra/memory'
440
442
  import { PostgresStore, PgVector } from '@mastra/pg'
@@ -251,7 +251,11 @@ const results = await pgVector.query({
251
251
  })
252
252
  ```
253
253
 
254
- Postgres vector indexes (HNSW and IVFFlat) can't restrict that search to rows matching a condition. When a filter is present, pgVector instead compares the query vector against every matching row and returns the closest `topK`. Results are exact, but the work grows with the number of rows the filter matches. Indexing the metadata column speeds up row retrieval. The distance comparisons still happen per row.
254
+ With an HNSW index on pgvector 0.8.0 or newer, PostgreSQL searches the index and skips rows that don't match the filter. When the index search can't fill `topK`, pgVector reruns the query as an exact search.
255
+
256
+ With IVFFlat, or HNSW on older pgvector versions, pgVector compares the query vector against every matching row. Results are exact, but the work grows with the number of matching rows.
257
+
258
+ Indexing the metadata fields you filter on speeds up both cases and gives PostgreSQL the row counts it needs to choose between them.
255
259
 
256
260
  ### Vector Query Tool
257
261