Skip to main content

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. Use 'dotproduct' if you plan to use hybrid search.

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()

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()

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

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()

indexName:

string
Name of the index containing the vector

id:

string
ID of the vector to delete

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 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 Variables

Required environment variables:

  • PINECONE_API_KEY: Your Pinecone API key
  • PINECONE_ENVIRONMENT: Pinecone environment (e.g., 'us-west1-gcp')

Pinecone supports hybrid search by combining dense and sparse vectors. To use hybrid search:

  1. Create an index with metric: 'dotproduct'
  2. During upsert, provide sparse vectors using the sparseVectors parameter
  3. During query, provide a sparse vector using the sparseVector parameter