0.1.0-alpha.24 • Published 10 months ago
@mastra/vector-libsql v0.1.0-alpha.24
@mastra/vector-libsql
Vector store implementation for libSQL/Turso using the official @libsql/client with support for vector similarity search and advanced JSON filtering.
Installation
npm install @mastra/vector-libsqlUsage
import { LibSQLVector } from '@mastra/vector-libsql';
const vectorStore = new LibSQLVector({
connectionUrl: 'libsql://your-database.turso.io',
authToken: 'your-auth-token', // optional
syncUrl: 'your-sync-url', // optional
syncInterval: 1000 // optional
});
// Create a new table
await vectorStore.createIndex('my_vectors', 1536);
// Add vectors
const vectors = [[0.1, 0.2, ...], [0.3, 0.4, ...]];
const metadata = [{ text: 'doc1' }, { text: 'doc2' }];
const ids = await vectorStore.upsert('my_vectors', vectors, metadata);
// Query vectors
const results = await vectorStore.query(
'my_vectors',
[0.1, 0.2, ...],
10, // topK
{ text: 'doc1' }, // filter
false, // includeVector
0.5 // minScore
);Configuration
Required:
connectionUrl: URL of your libSQL/Turso database
Optional:
authToken: Authentication token for TursosyncUrl: URL for database synchronizationsyncInterval: Sync interval in milliseconds
Features
- Vector similarity search using cosine distance
- Advanced JSON metadata filtering
- Support for nested object traversal in filters
- Array contains operations
- Minimum score threshold for queries
- Automatic UUID generation for vectors
- Table management (create, list, describe, delete, truncate)
- Built on top of @libsql/client
- Support for Turso's sync functionality
Supported Filter Operations
Basic Operations
- Equality:
{ field: value } - Comparison:
{ field: { $gt, $gte, $lt, $lte, $ne } } - Array:
{ field: { $in: [...] } }
Advanced Operations
- Contains (Objects):
{
metadata: {
contains: {
nested: {
field: 'value';
}
}
}
}- Contains (Arrays):
{
tags: {
contains: ['tag1', 'tag2'];
}
}Methods
createIndex(indexName, dimension): Create a new tableupsert(indexName, vectors, metadata?, ids?): Add or update vectorsquery(indexName, queryVector, topK?, filter?, includeVector?, minScore?): Search for similar vectorslistIndexes(): List all vector tablesdescribeIndex(indexName): Get table statisticsdeleteIndex(indexName): Delete a tabletruncateIndex(indexName): Remove all data from a table
Related Links
0.1.0-alpha.24
10 months ago
0.1.0-alpha.23
10 months ago
0.1.0-alpha.22
10 months ago
0.1.0-alpha.21
10 months ago
0.0.1-alpha.19
10 months ago
0.0.1-alpha.18
10 months ago
0.0.1-alpha.17
10 months ago
0.0.1-alpha.16
10 months ago
0.0.1-alpha.15
10 months ago
0.0.1-alpha.14
10 months ago
0.0.1-alpha.12
10 months ago
0.0.1-alpha.10
10 months ago
0.0.1-alpha.9
10 months ago
0.0.1-alpha.8
10 months ago
0.0.1-alpha.7
10 months ago
0.0.1-alpha.6
10 months ago
0.0.1-alpha.5
10 months ago
0.0.1-alpha.4
10 months ago
0.0.1-alpha.3
10 months ago
0.0.1-alpha.2
10 months ago
0.0.1-alpha.1
10 months ago
0.0.1-alpha.0
10 months ago