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 optionsConstructor options的直接链接
apiKey:
baseUrl?:
connectTimeout?:
connectionIdleTimeout?:
warmConnections?:
compression?:
consistency?:
schemaConfigForIndex?:
MethodsMethods的直接链接
createIndex()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()upsert的直接链接
vectors:
metadata?:
ids?:
query()query的直接链接
indexName:
queryVector:
topK?:
filter?:
includeVector?:
consistency?:
listIndexes()listindexes的直接链接
Returns an array of index names as strings.
describeIndex()describeindex的直接链接
indexName:
Returns:
interface IndexStats {
dimension: number
count: number
metric: 'cosine' | 'euclidean' | 'dotproduct'
}
deleteIndex()deleteindex的直接链接
indexName:
updateVector()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()deletevector的直接链接
indexName:
id:
deleteVectors()deletevectors的直接链接
Delete multiple vectors by IDs or by metadata filter. Either ids or filter must be provided, but not both.
indexName:
ids?:
filter?:
Response typesResponse 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 configurationSchema 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 handlingError 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
}
}