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 Options
apiKey:
string
Pinecone API key
environment:
string
Pinecone environment (e.g., "us-west1-gcp")
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()
indexName:
string
Name of your Pinecone index
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
vector:
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 the vector in the result
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>;
}
Error Handling
The store throws typed errors that can be caught:
try {
await store.query("index_name", queryVector);
} catch (error) {
if (error instanceof VectorStoreError) {
console.log(error.code); // 'connection_failed' | 'invalid_dimension' | etc
console.log(error.details); // Additional error context
}
}
Environment Variables
Required environment variables:
PINECONE_API_KEY
: Your Pinecone API keyPINECONE_ENVIRONMENT
: Pinecone environment (e.g., ‘us-west1-gcp’)