@mastra/libsql 0.0.0-1.x-tester-20251106055847

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/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ # Apache License 2.0
2
+
3
+ Copyright (c) 2025 Kepler Software, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # @mastra/libsql
2
+
3
+ SQLite implementation for Mastra, providing both vector similarity search and general storage capabilities with connection pooling and transaction support.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/libsql
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Vector Store
14
+
15
+ ```typescript
16
+ import { LibSQLVector } from '@mastra/libsql';
17
+
18
+ const vectorStore = new LibSQLVector({
19
+ url: 'file:./my-db.db'
20
+ });
21
+
22
+ // Create a new table with vector support
23
+ await vectorStore.createIndex({
24
+ indexName: 'my_vectors',
25
+ dimension: 1536,
26
+ metric: 'cosine',
27
+ });
28
+
29
+ // Add vectors
30
+ const ids = await vectorStore.upsert({
31
+ indexName: 'my_vectors',
32
+ vectors: [[0.1, 0.2, ...], [0.3, 0.4, ...]],
33
+ metadata: [{ text: 'doc1' }, { text: 'doc2' }],
34
+ });
35
+
36
+ // Query vectors
37
+ const results = await vectorStore.query({
38
+ indexName: 'my_vectors',
39
+ queryVector: [0.1, 0.2, ...],
40
+ topK: 10, // topK
41
+ filter: { text: 'doc1' }, // filter
42
+ includeVector: false, // includeVector
43
+ minScore: 0.5, // minScore
44
+ });
45
+ ```
46
+
47
+ ### Storage
48
+
49
+ ```typescript
50
+ import { LibSQLStore } from '@mastra/libsql';
51
+
52
+ const store = new LibSQLStore({
53
+ id: 'libsql-storage',
54
+ url: 'file:./my-db.db',
55
+ });
56
+
57
+ // Create a thread
58
+ await store.saveThread({
59
+ thread: {
60
+ id: 'thread-123',
61
+ resourceId: 'resource-456',
62
+ title: 'My Thread',
63
+ metadata: { key: 'value' },
64
+ createdAt: new Date(),
65
+ },
66
+ });
67
+
68
+ // Add messages to thread
69
+ await store.saveMessages({
70
+ messages: [
71
+ {
72
+ id: 'msg-789',
73
+ threadId: 'thread-123',
74
+ role: 'user',
75
+ content: { content: 'Hello' },
76
+ resourceId: 'resource-456',
77
+ createdAt: new Date(),
78
+ },
79
+ ],
80
+ });
81
+
82
+ // Query threads and messages
83
+ const savedThread = await store.getThreadById({ threadId: 'thread-123' });
84
+ const messages = await store.listMessages({ threadId: 'thread-123' });
85
+ ```
86
+
87
+ ## Configuration
88
+
89
+ The LibSQLStore store can be initialized with:
90
+
91
+ - Configuration object with url and auth. Auth is only necessary when using a provider like [Turso](https://turso.tech/)
92
+
93
+ ## Features
94
+
95
+ ### Vector Store Features
96
+
97
+ - Vector similarity search with cosine, euclidean, and dot product metrics
98
+ - Advanced metadata filtering with MongoDB-like query syntax
99
+ - Minimum score threshold for queries
100
+ - Automatic UUID generation for vectors
101
+ - Table management (create, list, describe, delete, truncate)
102
+
103
+ ### Storage Features
104
+
105
+ - Thread and message storage with JSON support
106
+ - Atomic transactions for data consistency
107
+ - Efficient batch operations
108
+ - Rich metadata support
109
+ - Timestamp tracking
110
+ - Cascading deletes
111
+
112
+ ## Supported Filter Operators
113
+
114
+ The following filter operators are supported for metadata queries:
115
+
116
+ - Comparison: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
117
+ - Logical: `$and`, `$or`
118
+ - Array: `$in`, `$nin`
119
+ - Text: `$regex`, `$like`
120
+
121
+ Example filter:
122
+
123
+ ```typescript
124
+ {
125
+ $and: [{ age: { $gt: 25 } }, { tags: { $in: ['tag1', 'tag2'] } }];
126
+ }
127
+ ```
128
+
129
+ ## Vector Store Methods
130
+
131
+ - `createIndex({indexName, dimension, metric?, indexConfig?, defineIndex?})`: Create a new table with vector support
132
+ - `upsert({indexName, vectors, metadata?, ids?})`: Add or update vectors
133
+ - `query({indexName, queryVector, topK?, filter?, includeVector?, minScore?})`: Search for similar vectors
134
+ - `defineIndex({indexName, metric?, indexConfig?})`: Define an index
135
+ - `listIndexes()`: List all vector-enabled tables
136
+ - `describeIndex(indexName)`: Get table statistics
137
+ - `deleteIndex(indexName)`: Delete a table
138
+ - `truncateIndex(indexName)`: Remove all data from a table
139
+
140
+ ## Storage Methods
141
+
142
+ - `saveThread({ thread })`: Create or update a thread
143
+ - `getThreadById({ threadId })`: Get a thread by ID
144
+ - `deleteThread({ threadId })`: Delete a thread and its messages
145
+ - `saveMessages({ messages })`: Save multiple messages in a transaction
146
+ - `listMessages({ threadId, perPage?, page? })`: Get messages for a thread with pagination
147
+ - `deleteMessages(messageIds)`: Delete specific messages
148
+
149
+ ## Related Links
150
+
151
+ - [LibSQL Documentation](https://docs.turso.tech/sdk/introductionh)