How To Delete A Namespace in a Pinecone Database

This crap changes all the time and it’s super annoying.

But as of May 30, 2024, this code works in Python:

import os
from pinecone import Pinecone, ServerlessSpec

# Initialize Pinecone with your API key
# Replace 'put-your-pinecone-api-key-here' with your actual Pinecone API key.
pc = Pinecone(api_key='put-your-pinecone-api-key-here')

# Define the Pinecone index name
index_name = 'enter-your-pinecone-index-name'

# Check if the index exists and create it if it does not exist.
# Note: The cloud and region might be different for your setup.
if index_name not in pc.list_indexes().names():
    pc.create_index(
        name=index_name,
        dimension=1536,  # The number of dimensions for your index.
        metric='euclidean',  # The metric used for similarity search (e.g., 'euclidean', 'cosine').
        spec=ServerlessSpec(
            cloud='aws',  # The cloud provider, e.g., 'aws'.
            region='us-east-1'  # The region for your index, e.g., 'us-east-1'.
        )
    )

# Access the Pinecone index
index = pc.Index(index_name)

# Delete all vectors in the specified namespace
# Replace 'put-your-name-space-in-here' with the name of the namespace you want to delete.
index.delete(delete_all=True, namespace='put-your-name-space-in-here')

Make sure you have Pinecone installed in your Python library:

pip install --upgrade pinecone-client

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *