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
apiKey:
string
Pinecone API key
environment?:
string
Pinecone environment controller host URL
cloud?:
'aws' | 'gcp' | 'azure'
= aws
Cloud provider for Pinecone serverless
region?:
string
= us-east-1
Region for Pinecone serverless
MethodsDirect link to Methods
createIndex()Direct link to 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. Use 'dotproduct' if you plan to use hybrid search.
upsert()Direct link to upsert()
indexName:
string
Name of your Pinecone index
vectors:
number[][]
Array of dense embedding vectors
sparseVectors?:
{ indices: number[], values: number[] }[]
Array of sparse vectors for hybrid search. Each vector must have matching indices and values arrays.
metadata?:
Record<string, any>[]
Metadata for each vector
ids?:
string[]
Optional vector IDs (auto-generated if not provided)
namespace?:
string
Optional namespace to store vectors in. Vectors in different namespaces are isolated from each other.
query()Direct link to query()
indexName:
string
Name of the index to query
vector:
number[]
Dense query vector to find similar vectors
sparseVector?:
{ indices: number[], values: number[] }
Optional sparse vector for hybrid search. Must have matching indices and values arrays.
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
namespace?:
string
Optional namespace to query vectors from. Only returns results from the specified namespace.
listIndexes()Direct link to listIndexes()
Returns an array of index names as strings.
describeIndex()Direct link to describeIndex()
indexName:
string
Name of the index to describe
Returns:
interface IndexStats {
dimension: number;
count: number;
metric: "cosine" | "euclidean" | "dotproduct";
}
deleteIndex()Direct link to deleteIndex()
indexName:
string
Name of the index to delete
updateVector()Direct link to updateVector()
indexName:
string
Name of the index containing the vector
id:
string
ID of the vector to update
update:
object
Update parameters
update.vector?:
number[]
New vector values to update
update.metadata?:
Record<string, any>
New metadata to update
deleteVector()Direct link to deleteVector()
indexName:
string
Name of the index containing the vector
id:
string
ID of the vector to delete
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 keyPINECONE_ENVIRONMENT: Pinecone environment (e.g., 'us-west1-gcp')
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