Turbopuffer vector store
The TurbopufferVector class provides vector search using Turbopuffer, a high-performance vector database optimized for RAG applications. Turbopuffer offers fast vector similarity search with advanced filtering capabilities and efficient storage management.
Constructor optionsDirect link to Constructor options
apiKey:
baseUrl?:
connectTimeout?:
connectionIdleTimeout?:
warmConnections?:
compression?:
consistency?:
schemaConfigForIndex?:
MethodsDirect link to Methods
createIndex()Direct link to createindex
Turbopuffer has no explicit create-index operation. createIndex() validates the arguments and records the dimension and metric locally; the namespace is created in Turbopuffer on the first upsert().
indexName:
dimension:
metric?:
upsert()Direct link to upsert
vectors:
metadata?:
ids?:
query()Direct link to query
indexName:
queryVector:
topK?:
filter?:
includeVector?:
consistency?:
listIndexes()Direct link to listindexes
Returns an array of index names as strings.
describeIndex()Direct link to describeindex
indexName:
Returns:
interface IndexStats {
dimension: number
count: number
metric: 'cosine' | 'euclidean' | 'dotproduct'
}
deleteIndex()Direct link to deleteindex
indexName:
updateVector()Direct link to updatevector
Update a single vector by ID, or every vector that matches a metadata filter. Either id or filter must be provided, but not both.
indexName:
id?:
filter?:
update:
deleteVector()Direct link to deletevector
indexName:
id:
deleteVectors()Direct link to deletevectors
Delete multiple vectors by IDs or by metadata filter. Either ids or filter must be provided, but not both.
indexName:
ids?:
filter?:
Response typesDirect link to Response types
Query results are returned in this format:
interface QueryResult {
id: string
score: number
metadata?: Record<string, any>
vector?: number[] // Only included if includeVector is true
}
Schema configurationDirect link to Schema configuration
The schemaConfigForIndex option allows you to define explicit schemas for different indexes:
schemaConfigForIndex: (indexName: string) => {
// Mastra's default embedding model and index for memory messages:
if (indexName === 'memory_messages_384') {
return {
dimensions: 384,
schema: {
thread_id: {
type: 'string',
filterable: true,
},
},
}
} else {
throw new Error(`TODO: add schema for index: ${indexName}`)
}
}
Error handlingDirect link to Error handling
The store throws MastraError instances from @mastra/core/error:
import { MastraError } from '@mastra/core/error'
try {
await store.query({
indexName: 'index_name',
queryVector: queryVector,
})
} catch (error) {
if (error instanceof MastraError) {
console.log(error.id) // 'MASTRA_VECTOR_TURBOPUFFER_QUERY_FAILED'
console.log(error.domain) // 'STORAGE'
console.log(error.category) // 'USER' | 'THIRD_PARTY'
console.log(error.details) // Additional error context
}
}