Pinecone Python Client (Legacy)
The `pinecone-client` library is the **DEPRECATED** Python client for the Pinecone vector database, which allows users to store, search, and manage high-dimensional vectors. This package is no longer maintained, and its last version is 6.0.0. All users should migrate to the new `pinecone` package for continued support, updates, and new features. The new `pinecone` package follows a quarterly release cadence aligned with Pinecone's API versioning.
Warnings
- breaking The `pinecone-client` package is DEPRECATED. The official Python client has been renamed to `pinecone`. Continuing to use `pinecone-client` will result in no further updates, bug fixes, or new features, and may lead to conflicts if both packages are installed.
- breaking The `pinecone.init()` function is no longer available in the new `pinecone` package (and was deprecated in later `pinecone-client` versions). Attempts to call it will result in an `AttributeError`.
- breaking The Python compatibility has changed. While `pinecone-client` supported Python 3.9+, the new `pinecone` SDK officially requires Python 3.10 or greater.
- gotcha Installing both `pinecone-client` and `pinecone` in the same environment can lead to confusing interactions and unexpected behavior.
- deprecated The `openapi_config` parameter for client initialization was deprecated in `pinecone-client` v5.x and removed in favor of direct parameters such as `proxy_url`, `proxy_headers`, and `ssl_ca_certs`.
Install
-
pip install pinecone-client -
pip install "pinecone-client[grpc]"
Imports
- Pinecone
from pinecone import Pinecone
Quickstart
import os
from pinecone import Pinecone, ServerlessSpec, CloudProvider, AwsRegion
# Initialize the Pinecone client (using the new 'pinecone' package)
api_key = os.environ.get('PINECONE_API_KEY', 'YOUR_API_KEY')
# Ensure you have a Pinecone API Key set as an environment variable or replace 'YOUR_API_KEY'
pc = Pinecone(api_key=api_key)
index_name = 'my-first-index'
dimension = 1536 # Example dimension, choose based on your embedding model
# Create a serverless index (if it doesn't exist)
if index_name not in pc.list_indexes().names():
pc.create_index(
name=index_name,
dimension=dimension,
metric='cosine', # or 'euclidean', 'dotproduct'
spec=ServerlessSpec(
cloud=CloudProvider.AWS,
region=AwsRegion.US_EAST_1
)
)
print(f"Index '{index_name}' created or already exists.")
# Connect to the index
index = pc.Index(name=index_name)
# Example: Upserting data (replace with your actual vectors/text)
vectors_to_upsert = [
{"id": "vec1", "values": [0.1]*dimension, "metadata": {"genre": "fiction"}},
{"id": "vec2", "values": [0.2]*dimension, "metadata": {"genre": "non-fiction"}}
]
index.upsert(vectors=vectors_to_upsert)
print(f"Upserted {len(vectors_to_upsert)} vectors to '{index_name}'.")
# Example: Querying the index
query_vector = [0.15]*dimension
query_results = index.query(vector=query_vector, top_k=1, include_metadata=True)
print("Query results:", query_results)
# Example: Deleting the index (uncomment to run)
# pc.delete_index(index_name)
# print(f"Index '{index_name}' deleted.")