@mastra/lance 1.1.2 → 1.2.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/CHANGELOG.md +25 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-rag-vector-databases.md +7 -2
- package/dist/index.cjs +13 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +13 -12
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { connect, Index } from '@lancedb/lancedb';
|
|
2
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
-
import { BackgroundTasksStorage, TABLE_SCHEMAS, TABLE_BACKGROUND_TASKS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, createStorageErrorId, normalizePerPage, calculatePagination, ScoresStorage, SCORERS_SCHEMA, TABLE_SCORERS, WorkflowsStorage, ensureDate, TABLE_WORKFLOW_SNAPSHOT, MastraCompositeStore, createVectorErrorId, getDefaultValue } from '@mastra/core/storage';
|
|
3
|
+
import { BackgroundTasksStorage, TABLE_SCHEMAS, TABLE_BACKGROUND_TASKS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, createStorageErrorId, normalizePerPage, calculatePagination, validateStorageMetadataFilter, storageMessageMatchesMetadataFilter, ScoresStorage, SCORERS_SCHEMA, TABLE_SCORERS, WorkflowsStorage, ensureDate, TABLE_WORKFLOW_SNAPSHOT, MastraCompositeStore, createVectorErrorId, getDefaultValue } from '@mastra/core/storage';
|
|
4
4
|
import { MastraBase } from '@mastra/core/base';
|
|
5
5
|
import { Utf8, Float64, Binary, Float32, Int32, Field, Schema } from 'apache-arrow';
|
|
6
6
|
import { MessageList } from '@mastra/core/agent';
|
|
@@ -1028,6 +1028,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
1028
1028
|
}
|
|
1029
1029
|
const perPage = normalizePerPage(perPageInput, 40);
|
|
1030
1030
|
const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
|
|
1031
|
+
const metadataFilter = validateStorageMetadataFilter(filter?.metadata);
|
|
1031
1032
|
try {
|
|
1032
1033
|
if (page < 0) {
|
|
1033
1034
|
throw new MastraError(
|
|
@@ -1072,9 +1073,14 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
1072
1073
|
hasMore: false
|
|
1073
1074
|
};
|
|
1074
1075
|
}
|
|
1075
|
-
const total = await table.countRows(whereClause);
|
|
1076
1076
|
const query = table.query().where(whereClause);
|
|
1077
1077
|
let allRecords = await query.toArray();
|
|
1078
|
+
if (metadataFilter) {
|
|
1079
|
+
allRecords = allRecords.filter(
|
|
1080
|
+
(row) => storageMessageMatchesMetadataFilter(this.normalizeMessage(row).content, metadataFilter)
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
const total = allRecords.length;
|
|
1078
1084
|
allRecords.sort((a, b) => {
|
|
1079
1085
|
const aValue = field === "createdAt" ? a.createdAt : a[field];
|
|
1080
1086
|
const bValue = field === "createdAt" ? b.createdAt : b[field];
|
|
@@ -1097,6 +1103,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
1097
1103
|
hasMore: false
|
|
1098
1104
|
};
|
|
1099
1105
|
}
|
|
1106
|
+
const primaryPageCount = messages.length;
|
|
1100
1107
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
1101
1108
|
if (include && include.length > 0) {
|
|
1102
1109
|
const includedMessages = await this._getIncludedMessages(table, include);
|
|
@@ -1110,10 +1117,11 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
1110
1117
|
const list = new MessageList().add(messages, "memory");
|
|
1111
1118
|
let finalMessages = list.get.all.db();
|
|
1112
1119
|
finalMessages = this._sortMessages(finalMessages, field, direction);
|
|
1113
|
-
const
|
|
1114
|
-
const
|
|
1115
|
-
|
|
1116
|
-
|
|
1120
|
+
const threadIdSet = new Set(threadIds);
|
|
1121
|
+
const returnedThreadMessageIds = new Set(
|
|
1122
|
+
finalMessages.filter((message) => message.threadId && threadIdSet.has(message.threadId)).map((message) => message.id)
|
|
1123
|
+
);
|
|
1124
|
+
const hasMore = perPageInput !== false && (metadataFilter || returnedThreadMessageIds.size < total) && offset + primaryPageCount < total;
|
|
1117
1125
|
return {
|
|
1118
1126
|
messages: finalMessages,
|
|
1119
1127
|
total,
|