Pinecone向量存储
🌐 Pinecone Vector Store
PineconeVector 类提供了一个接口,用于访问 Pinecone 的向量数据库。它提供实时向量搜索,具有混合搜索、元数据过滤和命名空间管理等功能。
🌐 The PineconeVector class provides an interface to Pinecone's vector database. It provides real-time vector search, with features like hybrid search, metadata filtering, and namespace management.
构造函数选项Direct link to 构造函数选项
🌐 Constructor Options
构造函数接受所有 Pinecone 配置选项 以及 Mastra 特定字段。
🌐 The constructor accepts all Pinecone configuration options plus Mastra-specific fields.
id:
apiKey:
controllerHostUrl?:
additionalHeaders?:
sourceTag?:
cloud?:
region?:
方法Direct link to 方法
🌐 Methods
createIndex()Direct link to createIndex()
indexName:
dimension:
metric?:
upsert()Direct link to upsert()
indexName:
vectors:
sparseVectors?:
metadata?:
ids?:
namespace?:
query()Direct link to query()
indexName:
vector:
sparseVector?:
topK?:
filter?:
includeVector?:
namespace?:
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?:
namespace?:
update:
update.vector?:
update.metadata?:
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?:
namespace?:
响应类型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 错误处理
🌐 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 环境变量
🌐 Environment Variables
所需的环境变量:
🌐 Required environment variables:
PINECONE_API_KEY:你的 Pinecone API 密钥
混合搜索Direct link to 混合搜索
🌐 Hybrid Search
Pinecone 通过结合密集向量和稀疏向量来支持混合搜索。使用混合搜索的方法如下:
🌐 Pinecone supports hybrid search by combining dense and sparse vectors. To use hybrid search:
- 使用
metric: 'dotproduct'创建索引 - 在执行 upsert 时,使用
sparseVectors参数提供稀疏向量 - 在查询时,使用
sparseVector参数提供一个稀疏向量
相关Direct link to 相关
🌐 Related