@mastra/pg 1.33.0-alpha.3 → 1.33.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 +1 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +4 -2
- package/dist/docs/references/reference-memory-memory-class.md +8 -6
- package/dist/index.cjs +93 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +94 -14
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/observability/v-next/ddl.d.ts +6 -0
- package/dist/storage/domains/observability/v-next/ddl.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/helpers.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/signal-schema.d.ts +37 -1
- package/dist/storage/domains/observability/v-next/signal-schema.d.ts.map +1 -1
- package/dist/vector/sql-builder.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
|
@@ -456,8 +456,10 @@ const agent = new Agent({
|
|
|
456
456
|
indexConfig: {
|
|
457
457
|
type: 'hnsw', // Use HNSW for better performance
|
|
458
458
|
metric: 'dotproduct', // Best for OpenAI embeddings
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
hnsw: {
|
|
460
|
+
m: 16, // Number of bi-directional links (default: 16)
|
|
461
|
+
efConstruction: 64, // Size of candidate list during construction (default: 64)
|
|
462
|
+
},
|
|
461
463
|
},
|
|
462
464
|
},
|
|
463
465
|
},
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# Memory class
|
|
6
6
|
|
|
7
|
-
The `Memory` class provides a reliable system for managing conversation history and thread-based message storage in Mastra. It enables persistent storage of conversations, semantic search capabilities, and efficient message retrieval. You must configure a storage provider for conversation history, and if you enable semantic recall you will also need to provide a vector store and embedder.
|
|
7
|
+
The `Memory` class provides a reliable system for managing conversation history and thread-based message storage in Mastra. It enables persistent storage of conversations, semantic search capabilities, and efficient message retrieval. You must configure a storage provider for conversation history, and if you enable semantic recall you will also need to provide a vector store and, unless that vector store embeds text itself, an embedder.
|
|
8
8
|
|
|
9
9
|
## Usage example
|
|
10
10
|
|
|
@@ -31,11 +31,11 @@ export const agent = new Agent({
|
|
|
31
31
|
|
|
32
32
|
## Constructor parameters
|
|
33
33
|
|
|
34
|
-
**storage** (`MastraCompositeStore`): Storage implementation for persisting memory data.
|
|
34
|
+
**storage** (`MastraCompositeStore`): Storage implementation for persisting memory data. Optional: when omitted, an agent uses the storage of the Mastra instance it belongs to. If neither is configured, accessing memory.storage throws Memory requires a storage provider to function.
|
|
35
35
|
|
|
36
36
|
**vector** (`MastraVector | false`): Vector store for semantic search capabilities. Set to false to disable vector operations.
|
|
37
37
|
|
|
38
|
-
**embedder** (`EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder
|
|
38
|
+
**embedder** (`string | EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder for vector embeddings, as a model-router ID string (for example "openai/text-embedding-3-small"), an EmbeddingModel, or an EmbeddingModelV2. Required when semantic recall is enabled and the vector store doesn't generate embeddings itself (vector.isSelfEmbedding is false).
|
|
39
39
|
|
|
40
40
|
**embeddingDimension** (`number`): Output dimension of the embedder, as a positive integer. When set, Memory uses it to name the semantic recall index instead of embedding a probe string on first use. It must match the vectors the embedder returns: a mismatch throws a MASTRA_MEMORY_EMBEDDING_DIMENSION_MISMATCH error before any index is created. See Setting the embedding dimension.
|
|
41
41
|
|
|
@@ -49,7 +49,7 @@ export const agent = new Agent({
|
|
|
49
49
|
|
|
50
50
|
**options.retainFullInput** (`boolean`): When true, the request input is processed exactly as supplied instead of being filtered against stored history. Use this when you assemble the input yourself and need the message sequence preserved. Stored history is still loaded underneath, and every input message that isn't already stored is saved to the thread, including few-shot examples. Can be set per call on memory.options or agent-wide in the memory constructor options.
|
|
51
51
|
|
|
52
|
-
**options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires
|
|
52
|
+
**options.semanticRecall** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires a vector store, and an embedder unless the vector store embeds text itself (isSelfEmbedding). Default topK is 4, default messageRange is {before: 1, after: 1}.
|
|
53
53
|
|
|
54
54
|
**options.workingMemory** (`WorkingMemory`): Configuration for working memory feature. Can be { enabled: boolean; template?: string; schema?: ZodObject\<any> | JSONSchema7; scope?: 'thread' | 'resource' } or { enabled: boolean } to disable.
|
|
55
55
|
|
|
@@ -128,8 +128,10 @@ export const agent = new Agent({
|
|
|
128
128
|
indexConfig: {
|
|
129
129
|
type: 'hnsw', // Use HNSW for better performance
|
|
130
130
|
metric: 'dotproduct', // Optimal for OpenAI embeddings
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
hnsw: {
|
|
132
|
+
m: 16, // Number of bi-directional links
|
|
133
|
+
efConstruction: 64, // Construction-time candidate list size
|
|
134
|
+
},
|
|
133
135
|
},
|
|
134
136
|
},
|
|
135
137
|
workingMemory: {
|
package/dist/index.cjs
CHANGED
|
@@ -262,7 +262,7 @@ const createNumericOperator = (symbol) => {
|
|
|
262
262
|
sql: `(CASE WHEN jsonb_typeof(${jsonExtract}) = 'number' THEN (${textExtract})::numeric ${symbol} $${paramIndex}::numeric ELSE NULL END)`,
|
|
263
263
|
needsValue: true
|
|
264
264
|
};
|
|
265
|
-
|
|
265
|
+
return {
|
|
266
266
|
sql: `${textExtract} ${symbol} $${paramIndex}::text`,
|
|
267
267
|
needsValue: true
|
|
268
268
|
};
|
|
@@ -16126,6 +16126,51 @@ const SPAN_EVENT_COLUMNS = [
|
|
|
16126
16126
|
type: "double precision",
|
|
16127
16127
|
nullable: true
|
|
16128
16128
|
},
|
|
16129
|
+
{
|
|
16130
|
+
name: "externalParentSpanId",
|
|
16131
|
+
type: "text",
|
|
16132
|
+
nullable: true
|
|
16133
|
+
},
|
|
16134
|
+
{
|
|
16135
|
+
name: "resumedFromSpanId",
|
|
16136
|
+
type: "text",
|
|
16137
|
+
nullable: true
|
|
16138
|
+
},
|
|
16139
|
+
{
|
|
16140
|
+
name: "model",
|
|
16141
|
+
type: "text",
|
|
16142
|
+
nullable: true
|
|
16143
|
+
},
|
|
16144
|
+
{
|
|
16145
|
+
name: "provider",
|
|
16146
|
+
type: "text",
|
|
16147
|
+
nullable: true
|
|
16148
|
+
},
|
|
16149
|
+
{
|
|
16150
|
+
name: "outcome",
|
|
16151
|
+
type: "text",
|
|
16152
|
+
nullable: true
|
|
16153
|
+
},
|
|
16154
|
+
{
|
|
16155
|
+
name: "stopReason",
|
|
16156
|
+
type: "text",
|
|
16157
|
+
nullable: true
|
|
16158
|
+
},
|
|
16159
|
+
{
|
|
16160
|
+
name: "timeToFirstTokenMs",
|
|
16161
|
+
type: "double precision",
|
|
16162
|
+
nullable: true
|
|
16163
|
+
},
|
|
16164
|
+
{
|
|
16165
|
+
name: "errorCount",
|
|
16166
|
+
type: "integer",
|
|
16167
|
+
nullable: true
|
|
16168
|
+
},
|
|
16169
|
+
{
|
|
16170
|
+
name: "stopReasonContext",
|
|
16171
|
+
type: "jsonb",
|
|
16172
|
+
nullable: true
|
|
16173
|
+
},
|
|
16129
16174
|
{
|
|
16130
16175
|
name: "tags",
|
|
16131
16176
|
type: "text[]",
|
|
@@ -16834,6 +16879,26 @@ function allTableDDL(schema, mode) {
|
|
|
16834
16879
|
];
|
|
16835
16880
|
}
|
|
16836
16881
|
/**
|
|
16882
|
+
* Span event columns added after the table first shipped, with their types. All
|
|
16883
|
+
* nullable with no default, so each ALTER is a catalog-only change; rows written
|
|
16884
|
+
* before it read NULL and readers fall back to the payload or attributes.
|
|
16885
|
+
*/
|
|
16886
|
+
const ADDED_SPAN_COLUMNS = [
|
|
16887
|
+
["inputPreview", "text"],
|
|
16888
|
+
["outputPreview", "text"],
|
|
16889
|
+
["errorPreview", "text"],
|
|
16890
|
+
["timeToFirstChunkMs", "double precision"],
|
|
16891
|
+
["externalParentSpanId", "text"],
|
|
16892
|
+
["resumedFromSpanId", "text"],
|
|
16893
|
+
["model", "text"],
|
|
16894
|
+
["provider", "text"],
|
|
16895
|
+
["outcome", "text"],
|
|
16896
|
+
["stopReason", "text"],
|
|
16897
|
+
["timeToFirstTokenMs", "double precision"],
|
|
16898
|
+
["errorCount", "integer"],
|
|
16899
|
+
["stopReasonContext", "jsonb"]
|
|
16900
|
+
];
|
|
16901
|
+
/**
|
|
16837
16902
|
* Additive column migrations for tables created by an older version of this
|
|
16838
16903
|
* schema. `CREATE TABLE IF NOT EXISTS` is a no-op on an existing table, so new
|
|
16839
16904
|
* columns have to be added out of band.
|
|
@@ -16850,20 +16915,11 @@ function additiveColumns(schema) {
|
|
|
16850
16915
|
column: "isPending",
|
|
16851
16916
|
ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "isPending" boolean NOT NULL DEFAULT false`
|
|
16852
16917
|
},
|
|
16853
|
-
...[
|
|
16854
|
-
"inputPreview",
|
|
16855
|
-
"outputPreview",
|
|
16856
|
-
"errorPreview"
|
|
16857
|
-
].map((column) => ({
|
|
16918
|
+
...ADDED_SPAN_COLUMNS.map(([column, type]) => ({
|
|
16858
16919
|
table: TABLE_SPAN_EVENTS,
|
|
16859
16920
|
column,
|
|
16860
|
-
ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "${column}"
|
|
16921
|
+
ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "${column}" ${type}`
|
|
16861
16922
|
})),
|
|
16862
|
-
{
|
|
16863
|
-
table: TABLE_SPAN_EVENTS,
|
|
16864
|
-
column: "timeToFirstChunkMs",
|
|
16865
|
-
ddl: `ALTER TABLE ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} ADD COLUMN IF NOT EXISTS "timeToFirstChunkMs" double precision`
|
|
16866
|
-
},
|
|
16867
16923
|
{
|
|
16868
16924
|
table: TABLE_FEEDBACK_EVENTS,
|
|
16869
16925
|
column: "reviewStatus",
|
|
@@ -17416,6 +17472,11 @@ const PROMOTED_KEYS = /* @__PURE__ */ new Set([
|
|
|
17416
17472
|
"executionSource",
|
|
17417
17473
|
"serviceName"
|
|
17418
17474
|
]);
|
|
17475
|
+
function nullableNumber$1(value) {
|
|
17476
|
+
if (value == null || value === "") return null;
|
|
17477
|
+
const n = Number(value);
|
|
17478
|
+
return Number.isNaN(n) ? null : n;
|
|
17479
|
+
}
|
|
17419
17480
|
function nullableString(value) {
|
|
17420
17481
|
if (typeof value === "string") return value === "" ? null : value;
|
|
17421
17482
|
if (value == null) return null;
|
|
@@ -17577,6 +17638,15 @@ function spanRecordToRow(span) {
|
|
|
17577
17638
|
startedAt: toIsoOrDate(span.startedAt),
|
|
17578
17639
|
endedAt: toIsoOrDate(endedAt),
|
|
17579
17640
|
timeToFirstChunkMs: span.timeToFirstChunkMs ?? null,
|
|
17641
|
+
externalParentSpanId: span.externalParentSpanId ?? null,
|
|
17642
|
+
resumedFromSpanId: span.resumedFromSpanId ?? null,
|
|
17643
|
+
model: span.model ?? null,
|
|
17644
|
+
provider: span.provider ?? null,
|
|
17645
|
+
outcome: span.outcome ?? null,
|
|
17646
|
+
stopReason: span.stopReason ?? null,
|
|
17647
|
+
stopReasonContext: jsonField(span.stopReasonContext),
|
|
17648
|
+
timeToFirstTokenMs: span.timeToFirstTokenMs ?? null,
|
|
17649
|
+
errorCount: span.errorCount ?? null,
|
|
17580
17650
|
tags: normalizeTags(span.tags),
|
|
17581
17651
|
metadataSearch: buildMetadataSearch(metadata),
|
|
17582
17652
|
metadataRaw: jsonField(metadata),
|
|
@@ -17606,6 +17676,7 @@ function rowToSpanRecord(row) {
|
|
|
17606
17676
|
const startedAt = toDate(row.startedAt);
|
|
17607
17677
|
const endedAt = spanRowEndedAt(row, startedAt);
|
|
17608
17678
|
const error = parsedJson(row.error);
|
|
17679
|
+
const attributes = parsedJson(row.attributes);
|
|
17609
17680
|
const { executionSource, ...ctx } = rowToCommonContext(row);
|
|
17610
17681
|
return {
|
|
17611
17682
|
...ctx,
|
|
@@ -17618,10 +17689,19 @@ function rowToSpanRecord(row) {
|
|
|
17618
17689
|
isEvent: Boolean(row.isEvent),
|
|
17619
17690
|
startedAt,
|
|
17620
17691
|
endedAt,
|
|
17692
|
+
externalParentSpanId: nullableString(row.externalParentSpanId),
|
|
17693
|
+
resumedFromSpanId: nullableString(row.resumedFromSpanId),
|
|
17694
|
+
model: nullableString(row.model) ?? (0, _mastra_core_storage.getStringAttribute)(attributes, "model"),
|
|
17695
|
+
provider: nullableString(row.provider) ?? (0, _mastra_core_storage.getStringAttribute)(attributes, "provider"),
|
|
17696
|
+
outcome: nullableString(row.outcome),
|
|
17697
|
+
stopReason: nullableString(row.stopReason),
|
|
17698
|
+
stopReasonContext: parsedJson(row.stopReasonContext) ?? null,
|
|
17699
|
+
timeToFirstTokenMs: nullableNumber$1(row.timeToFirstTokenMs),
|
|
17700
|
+
errorCount: nullableNumber$1(row.errorCount),
|
|
17621
17701
|
tags: normalizeTags(row.tags),
|
|
17622
17702
|
metadata: parsedJson(row.metadataRaw) ?? void 0,
|
|
17623
17703
|
scope: parsedJson(row.scope) ?? void 0,
|
|
17624
|
-
attributes:
|
|
17704
|
+
attributes: attributes ?? void 0,
|
|
17625
17705
|
links: parsedJson(row.links) ?? void 0,
|
|
17626
17706
|
input: parsedJson(row.input) ?? void 0,
|
|
17627
17707
|
output: parsedJson(row.output) ?? void 0,
|