Using the Pinecone connector (Preview)

Warning

Pinecone has dropped the .NET SDK support by archiving their repository.

Warning

The Semantic Kernel Vector Store functionality is in preview, and improvements that require breaking changes may still occur in limited circumstances before release.

Warning

The Semantic Kernel Vector Store functionality is in preview, and improvements that require breaking changes may still occur in limited circumstances before release.

Overview

The Pinecone Vector Store connector can be used to access and manage data in Pinecone. The connector has the following characteristics.

Feature Area Support
Collection maps to Pinecone serverless Index
Supported key property types string
Supported data property types
  • string
  • int
  • long
  • double
  • float
  • decimal
  • bool
  • DateTime
  • and iterables of each of these types
Supported vector property types
  • list[float]
  • list[int]
  • numpy array
Supported index types PGA (Pinecone Graph Algorithm)
Supported distance functions
  • CosineSimilarity
  • DotProductSimilarity
  • EuclideanSquaredDistance
Supported filter clauses
  • EqualTo
  • AnyTagEqualTo
Supports multiple vectors in a record No
IsFilterable supported? Yes
IsFullTextSearchable supported? No
Integrated Embeddings supported? Yes, see here
GRPC Supported? Yes, see here

Getting started

Add the Pinecone Vector Store connector extra to your project.

pip install semantic-kernel[pinecone]

You can then create a PineconeStore instance and use it to create a collection. This will read the Pinecone API key from the environment variable PINECONE_API_KEY.

from semantic_kernel.connectors.pinecone import PineconeStore

store = PineconeStore()
collection = store.get_collection(collection_name="collection_name", record_type=DataModel)

It is possible to construct a direct reference to a named collection.

from semantic_kernel.connectors.pinecone import PineconeCollection

collection = PineconeCollection(collection_name="collection_name", record_type=DataModel)

You can also create your own Pinecone client and pass it into the constructor. The client needs to be either PineconeAsyncio or PineconeGRPC (see GRPC Support).

from semantic_kernel.connectors.pinecone import PineconeStore, PineconeCollection
from pinecone import PineconeAsyncio

client = PineconeAsyncio(api_key="your_api_key") 
store = PineconeStore(client=client)
collection = store.get_collection(collection_name="collection_name", record_type=DataModel)

GRPC support

We also support two options on the collection constructor, the first is to enable GRPC support:

from semantic_kernel.connectors.pinecone import PineconeCollection

collection = PineconeCollection(collection_name="collection_name", record_type=DataModel, use_grpc=True)

Or with your own client:

from semantic_kernel.connectors.pinecone import PineconeStore
from pinecone.grpc import PineconeGRPC

client = PineconeGRPC(api_key="your_api_key")
store = PineconeStore(client=client)
collection = store.get_collection(collection_name="collection_name", record_type=DataModel)

Integrated Embeddings

The second is to use the integrated embeddings of Pinecone, this will check for a environment variable called PINECONE_EMBED_MODEL with the model name, or you can pass in a embed_settings dict, which can contain just the model key, or the full settings for the embedding model. In the former case, the other settings will be derived from the data model definition.

See Pinecone docs and then the Use integrated embeddings sections.

from semantic_kernel.connectors.pinecone import PineconeCollection

collection = PineconeCollection(collection_name="collection_name", record_type=DataModel)

Alternatively, when not settings the environment variable, you can pass the embed settings into the constructor:

from semantic_kernel.connectors.pinecone import PineconeCollection

collection = PineconeCollection(collection_name="collection_name", record_type=DataModel, embed_settings={"model": "multilingual-e5-large"})

This can include other details about the vector setup, like metric and field mapping. You can also pass the embed settings into the ensure_collection_exists method, this will override the default settings set during initialization.

from semantic_kernel.connectors.pinecone import PineconeCollection

collection = PineconeCollection(collection_name="collection_name", record_type=DataModel)
await collection.ensure_collection_exists(embed_settings={"model": "multilingual-e5-large"})

Important: GRPC and Integrated embeddings cannot be used together.

Index Namespace

The Vector Store abstraction does not support a multi tiered record grouping mechanism. Collections in the abstraction map to a Pinecone serverless index and no second level exists in the abstraction. Pinecone does support a second level of grouping called namespaces.

By default the Pinecone connector will pass '' as the namespace for all operations. However it is possible to pass a single namespace to the Pinecone collection when constructing it and use this instead for all operations.

from semantic_kernel.connectors.pinecone import PineconeCollection

collection = PineconeCollection(
    collection_name="collection_name", 
    record_type=DataModel, 
    namespace="seasidehotels"
)

The Pinecone connector is not yet available in Java.