Pinecone Vector Store
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.
Constructor OptionsDirect link to Constructor Options
The constructor accepts all Pinecone configuration options plus Mastra-specific fields.
id:
apiKey:
controllerHostUrl?:
additionalHeaders?:
sourceTag?:
cloud?:
region?:
MethodsDirect 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()
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()
Delete multiple vectors by IDs or by metadata filter. Either ids or filter must be provided, but not both.
indexName:
ids?:
filter?:
namespace?:
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
}
Error HandlingDirect 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
}
}
Environment VariablesDirect link to Environment Variables
Required environment variables:
PINECONE_API_KEY: Your Pinecone API key
Hybrid SearchDirect link to Hybrid Search
Pinecone supports hybrid search by combining dense and sparse vectors. To use hybrid search:
- Create an index with
metric: 'dotproduct' - During upsert, provide sparse vectors using the
sparseVectorsparameter - During query, provide a sparse vector using the
sparseVectorparameter