Since Pinecone records can always be efficiently accessed using their ID, deleting by ID is the most efficient way to remove specific records from a namespace.
To remove records from the default namespace, specify "__default__" as the namespace in your request.
Copy
# pip install "pinecone[grpc]"from pinecone.grpc import PineconeGRPC as Pineconepc = Pinecone(api_key="YOUR_API_KEY")# To get the unique host for an index, # see https://docs.pinecone.io/guides/manage-data/target-an-indexindex = pc.Index(host="INDEX_HOST")index.delete(ids=["id-1", "id-2"], namespace='example-namespace')
To delete records from a namespace based on their metadata values, pass a metadata filter expression to the delete operation. This deletes all records in the namespace that match the filter expression.For example, the following code deletes all records with a genre field set to documentary from namespace example-namespace:
Copy
# pip install "pinecone[grpc]"from pinecone.grpc import PineconeGRPC as Pineconepc = Pinecone(api_key="YOUR_API_KEY")# To get the unique host for an index, # see https://docs.pinecone.io/guides/manage-data/target-an-indexindex = pc.Index(host="INDEX_HOST")index.delete( filter={ "genre": {"$eq": "documentary"} }, namespace="example-namespace")
To delete all of the records in a namespace but not the namespace itself, provide a namespace parameter and specify the appropriate deleteAll parameter for your SDK. To target the default namespace, set namespace to "__default__".
Copy
# pip install "pinecone[grpc]"from pinecone.grpc import PineconeGRPC as Pineconepc = Pinecone(api_key="YOUR_API_KEY")# To get the unique host for an index, # see https://docs.pinecone.io/guides/manage-data/target-an-indexindex = pc.Index(host="INDEX_HOST")index.delete(delete_all=True, namespace='example-namespace')
Pinecone is eventually consistent, so there can be a slight delay before new or changed records are visible to queries. You can view index stats to check data freshness.