@mastra/lance 0.1.3-alpha.0 → 0.1.3-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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +26 -0
- package/dist/_tsup-dts-rollup.d.cts +18 -4
- package/dist/_tsup-dts-rollup.d.ts +18 -4
- package/dist/index.cjs +802 -160
- package/dist/index.js +769 -127
- package/package.json +5 -5
- package/src/storage/index.test.ts +72 -2
- package/src/storage/index.ts +486 -68
- package/src/vector/filter.test.ts +3 -3
- package/src/vector/filter.ts +24 -4
- package/src/vector/index.test.ts +3 -3
- package/src/vector/index.ts +320 -79
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/lance",
|
|
3
|
-
"version": "0.1.3-alpha.
|
|
3
|
+
"version": "0.1.3-alpha.2",
|
|
4
4
|
"description": "Lance provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.8",
|
|
27
27
|
"@types/node": "^20.19.0",
|
|
28
|
-
"eslint": "^9.
|
|
28
|
+
"eslint": "^9.29.0",
|
|
29
29
|
"tsup": "^8.5.0",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"vitest": "^3.2.3",
|
|
32
|
-
"@internal/
|
|
33
|
-
"@mastra/core": "^0.10.7-alpha.
|
|
34
|
-
"@internal/
|
|
32
|
+
"@internal/lint": "0.0.13",
|
|
33
|
+
"@mastra/core": "^0.10.7-alpha.2",
|
|
34
|
+
"@internal/storage-test-utils": "0.0.9"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@mastra/core": ">=0.10.4-0 <0.11.0"
|
|
@@ -54,6 +54,7 @@ function generateMessageRecords(count: number, threadId?: string): MastraMessage
|
|
|
54
54
|
toolCallIds: [],
|
|
55
55
|
toolCallArgs: [],
|
|
56
56
|
toolNames: [],
|
|
57
|
+
type: 'v2',
|
|
57
58
|
}));
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -232,7 +233,7 @@ describe('LanceStorage tests', async () => {
|
|
|
232
233
|
|
|
233
234
|
it('should throw error when invalid key type is provided', async () => {
|
|
234
235
|
await expect(storage.load({ tableName: TABLE_MESSAGES, keys: { id: '1' } })).rejects.toThrowError(
|
|
235
|
-
|
|
236
|
+
/Expected numeric value for field 'id', got string/,
|
|
236
237
|
);
|
|
237
238
|
});
|
|
238
239
|
|
|
@@ -563,7 +564,6 @@ describe('LanceStorage tests', async () => {
|
|
|
563
564
|
expect(message.threadId).toEqual(threadId);
|
|
564
565
|
expect(message.id.toString()).toEqual(messages[index].id);
|
|
565
566
|
expect(message.content).toEqual(messages[index].content);
|
|
566
|
-
expect(new Date(message.createdAt)).toEqual(new Date(messages[index].createdAt));
|
|
567
567
|
expect(message.role).toEqual(messages[index].role);
|
|
568
568
|
expect(message.resourceId).toEqual(messages[index].resourceId);
|
|
569
569
|
expect(message.type).toEqual(messages[index].type);
|
|
@@ -708,6 +708,76 @@ describe('LanceStorage tests', async () => {
|
|
|
708
708
|
expect(currentDate).toBeLessThanOrEqual(nextDate);
|
|
709
709
|
}
|
|
710
710
|
});
|
|
711
|
+
|
|
712
|
+
it('should upsert messages: duplicate id+threadId results in update, not duplicate row', async () => {
|
|
713
|
+
const thread = 'thread-1';
|
|
714
|
+
const baseMessage = generateMessageRecords(1, thread)[0];
|
|
715
|
+
|
|
716
|
+
// Insert the message for the first time
|
|
717
|
+
await storage.saveMessages({ messages: [baseMessage], format: 'v2' });
|
|
718
|
+
|
|
719
|
+
// Insert again with the same id and threadId but different content
|
|
720
|
+
const updatedMessage: MastraMessageV2 = {
|
|
721
|
+
...generateMessageRecords(1, thread)[0],
|
|
722
|
+
id: baseMessage.id,
|
|
723
|
+
content: { format: 2, parts: [{ type: 'text', text: 'Updated' }] },
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
await storage.saveMessages({ messages: [updatedMessage], format: 'v2' });
|
|
727
|
+
|
|
728
|
+
// Retrieve messages for the thread
|
|
729
|
+
const retrievedMessages = await storage.getMessages({ threadId: thread, format: 'v2' });
|
|
730
|
+
// Only one message should exist for that id+threadId
|
|
731
|
+
expect(retrievedMessages.filter(m => m.id.toString() === baseMessage.id)).toHaveLength(1);
|
|
732
|
+
|
|
733
|
+
// The content should be the updated one
|
|
734
|
+
expect(retrievedMessages.find(m => m.id.toString() === baseMessage.id)?.content.parts[0].text).toBe('Updated');
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
it('should upsert messages: duplicate id and different threadid', async () => {
|
|
738
|
+
const thread1 = 'thread-1';
|
|
739
|
+
const thread2 = 'thread-2';
|
|
740
|
+
const thread3 = 'thread-3';
|
|
741
|
+
|
|
742
|
+
const message = generateMessageRecords(1, thread1)[0];
|
|
743
|
+
|
|
744
|
+
// Insert message into thread1
|
|
745
|
+
await storage.saveMessages({ messages: [message], format: 'v2' });
|
|
746
|
+
|
|
747
|
+
// Attempt to insert a message with the same id but different threadId
|
|
748
|
+
const conflictingMessage: MastraMessageV2 = {
|
|
749
|
+
...generateMessageRecords(1, thread2)[0],
|
|
750
|
+
id: message.id,
|
|
751
|
+
content: { format: 2, parts: [{ type: 'text', text: 'Thread2 Content' }] },
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
const differentMessage: MastraMessageV2 = {
|
|
755
|
+
...generateMessageRecords(1, thread3)[0],
|
|
756
|
+
id: '2',
|
|
757
|
+
content: { format: 2, parts: [{ type: 'text', text: 'Another Message Content' }] },
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
// Save should move the message to the new thread
|
|
761
|
+
await storage.saveMessages({ messages: [conflictingMessage], format: 'v2' });
|
|
762
|
+
|
|
763
|
+
await storage.saveMessages({ messages: [differentMessage], format: 'v2' });
|
|
764
|
+
|
|
765
|
+
// Retrieve messages for both threads
|
|
766
|
+
const thread1Messages = await storage.getMessages({ threadId: thread1, format: 'v2' });
|
|
767
|
+
const thread2Messages = await storage.getMessages({ threadId: thread2, format: 'v2' });
|
|
768
|
+
const thread3Messages = await storage.getMessages({ threadId: thread3, format: 'v2' });
|
|
769
|
+
|
|
770
|
+
// Thread 1 should NOT have the message with that id
|
|
771
|
+
expect(thread1Messages.find(m => m.id.toString() === message.id)).toBeUndefined();
|
|
772
|
+
|
|
773
|
+
// Thread 2 should have the message with that id
|
|
774
|
+
expect(thread2Messages.find(m => m.id.toString() === message.id)?.content.parts[0].text).toBe('Thread2 Content');
|
|
775
|
+
|
|
776
|
+
// Thread 2 should have the other message
|
|
777
|
+
expect(thread3Messages.find(m => m.id.toString() === differentMessage.id)?.content.parts[0].text).toBe(
|
|
778
|
+
'Another Message Content',
|
|
779
|
+
);
|
|
780
|
+
});
|
|
711
781
|
});
|
|
712
782
|
|
|
713
783
|
describe('Trace operations', () => {
|