@mastra/lance 1.3.0-alpha.0 → 1.3.0-alpha.2
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 +28 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/guides-rag-vector-databases.md +41 -0
- package/dist/index.cjs +15 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +10 -2
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -755,7 +755,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
755
755
|
};
|
|
756
756
|
const record = {
|
|
757
757
|
id,
|
|
758
|
-
title,
|
|
758
|
+
title: title ?? current.title,
|
|
759
759
|
metadata: JSON.stringify(mergedMetadata),
|
|
760
760
|
updatedAt: (/* @__PURE__ */ new Date()).getTime()
|
|
761
761
|
};
|
|
@@ -868,7 +868,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
868
868
|
hasMore: false
|
|
869
869
|
};
|
|
870
870
|
if (perPage === 0 && include && include.length > 0) {
|
|
871
|
-
const includedMessages = await this._getIncludedMessages(table, include);
|
|
871
|
+
const includedMessages = await this._getIncludedMessages(table, include, resourceId);
|
|
872
872
|
const list = new MessageList().add(includedMessages, "memory");
|
|
873
873
|
return {
|
|
874
874
|
messages: this._sortMessages(list.get.all.db(), field, direction),
|
|
@@ -901,7 +901,7 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
901
901
|
const primaryPageCount = messages.length;
|
|
902
902
|
const messageIds = new Set(messages.map((m) => m.id));
|
|
903
903
|
if (include && include.length > 0) {
|
|
904
|
-
const includedMessages = await this._getIncludedMessages(table, include);
|
|
904
|
+
const includedMessages = await this._getIncludedMessages(table, include, resourceId);
|
|
905
905
|
for (const includeMsg of includedMessages) if (!messageIds.has(includeMsg.id)) {
|
|
906
906
|
messages.push(includeMsg);
|
|
907
907
|
messageIds.add(includeMsg.id);
|
|
@@ -1059,16 +1059,25 @@ var StoreMemoryLance = class extends MemoryStorage {
|
|
|
1059
1059
|
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
1060
1060
|
});
|
|
1061
1061
|
}
|
|
1062
|
-
|
|
1062
|
+
/**
|
|
1063
|
+
* Fetches the messages named by `include` together with their surrounding context.
|
|
1064
|
+
*
|
|
1065
|
+
* @param table - Open handle to the messages table.
|
|
1066
|
+
* @param include - Message ids to pin, each with an optional before/after window.
|
|
1067
|
+
* @param resourceId - When set, restricts both the pinned messages and their context
|
|
1068
|
+
* to that resource so an id from another resource returns nothing.
|
|
1069
|
+
*/
|
|
1070
|
+
async _getIncludedMessages(table, include, resourceId) {
|
|
1063
1071
|
if (include.length === 0) return [];
|
|
1072
|
+
const resourceCondition = resourceId ? ` AND resourceId = '${this.escapeSql(resourceId)}'` : "";
|
|
1064
1073
|
const targetIds = include.map((item) => item.id);
|
|
1065
1074
|
const idCondition = targetIds.length === 1 ? `id = '${this.escapeSql(targetIds[0])}'` : `id IN (${targetIds.map((id) => `'${this.escapeSql(id)}'`).join(", ")})`;
|
|
1066
|
-
const targetRecords = await table.query().where(idCondition).toArray();
|
|
1075
|
+
const targetRecords = await table.query().where(`${idCondition}${resourceCondition}`).toArray();
|
|
1067
1076
|
if (!include.some((item) => item.withPreviousMessages || item.withNextMessages)) return targetRecords.map((row) => this.normalizeMessage(row));
|
|
1068
1077
|
const threadIdsToFetch = [...new Set(targetRecords.map((r) => r.thread_id))];
|
|
1069
1078
|
const threadCache = /* @__PURE__ */ new Map();
|
|
1070
1079
|
for (const tid of threadIdsToFetch) {
|
|
1071
|
-
const threadRecords = await table.query().where(`thread_id = '${this.escapeSql(tid)}'`).toArray();
|
|
1080
|
+
const threadRecords = await table.query().where(`thread_id = '${this.escapeSql(tid)}'${resourceCondition}`).toArray();
|
|
1072
1081
|
threadRecords.sort((a, b) => a.createdAt - b.createdAt);
|
|
1073
1082
|
threadCache.set(tid, threadRecords);
|
|
1074
1083
|
}
|