Turbopuffer 向量存储
🌐 Turbopuffer Vector Store
TurbopufferVector 类使用 Turbopuffer 提供向量搜索,Turbopuffer 是针对 RAG 应用优化的高性能向量数据库。Turbopuffer 提供快速的向量相似性搜索,具备高级过滤功能和高效的存储管理能力。
🌐 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.
构造函数选项Direct link to 构造函数选项
🌐 Constructor Options
apiKey:
baseUrl?:
connectTimeout?:
connectionIdleTimeout?:
warmConnections?:
compression?:
schemaConfigForIndex?:
方法Direct link to 方法
🌐 Methods
createIndex()Direct link to createIndex()
indexName:
dimension:
metric?:
upsert()Direct link to upsert()
vectors:
metadata?:
ids?:
query()Direct link to query()
indexName:
queryVector:
topK?:
filter?:
includeVector?:
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()
通过 ID 或元数据过滤器更新单个向量。必须提供 id 或 filter 中的一个,但不能同时提供两者。
🌐 Update a single vector by ID or by 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()
通过 ID 或元数据过滤器删除多个向量。必须提供 ids 或 filter 中的一个,但不能同时提供两者。
🌐 Delete multiple vectors by IDs or by metadata filter. Either ids or filter must be provided, but not both.
indexName:
ids?:
filter?:
响应类型Direct 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
}
模式配置Direct link to 模式配置
🌐 Schema Configuration
schemaConfigForIndex 选项允许你为不同的索引定义明确的模式:
🌐 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}`);
}
};
错误处理Direct link to 错误处理
🌐 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
}
}
相关Direct link to 相关
🌐 Related