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 Options
apiKey:
string
The API key to authenticate with Turbopuffer
baseUrl?:
string
= https://api.turbopuffer.com
The base URL for the Turbopuffer API
connectTimeout?:
number
= 10000
The timeout to establish a connection, in ms. Only applicable in Node and Deno.
connectionIdleTimeout?:
number
= 60000
The socket idle timeout, in ms. Only applicable in Node and Deno.
warmConnections?:
number
= 0
The number of connections to open initially when creating a new client.
compression?:
boolean
= true
Whether to compress requests and accept compressed responses.
schemaConfigForIndex?:
function
A callback function that takes an index name and returns a config object for that index. This allows you to define explicit schemas per index.
Methods
createIndex()
indexName:
string
Name of the index to create
dimension:
number
Vector dimension (must match your embedding model)
metric?:
'cosine' | 'euclidean' | 'dotproduct'
= cosine
Distance metric for similarity search
upsert()
vectors:
number[][]
Array of embedding vectors
metadata?:
Record<string, any>[]
Metadata for each vector
ids?:
string[]
Optional vector IDs (auto-generated if not provided)
query()
indexName:
string
Name of the index to query
queryVector:
number[]
Query vector to find similar vectors
topK?:
number
= 10
Number of results to return
filter?:
Record<string, any>
Metadata filters for the query
includeVector?:
boolean
= false
Whether to include vectors in the results
listIndexes()
Returns an array of index names as strings.
describeIndex()
indexName:
string
Name of the index to describe
Returns:
interface IndexStats {
dimension: number;
count: number;
metric: "cosine" | "euclidean" | "dotproduct";
}
deleteIndex()
indexName:
string
Name of the index to delete
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 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 Handling
The store throws typed errors that can be caught:
try {
await store.query({
indexName: "index_name",
queryVector: queryVector,
});
} catch (error) {
if (error instanceof VectorStoreError) {
console.log(error.code); // 'connection_failed' | 'invalid_dimension' | etc
console.log(error.details); // Additional error context
}
}