Here is a node.js script I wrote to delete all vectors in all namespaces:
(async () => {
// Import the PineconeClient
const { PineconeClient } = require('@pinecone-database/pinecone');
const axios = require('axios'); // Ensure axios is imported
// Declare your API key and environment
const PINECONE_API_KEY = process.env.PINECONE_API_KEY;
const PINECONE_ENVIRONMENT = 'asia-northeast-gcp'; // replace with your environment
// Create the client
const client = new PineconeClient();
// Initialize the client
await client.init({
apiKey: PINECONE_API_KEY,
environment: PINECONE_ENVIRONMENT,
});
// select my index
const index = client.Index('atheneum');
// get all of the namespaces using curl equivalent and parsing the response
let namespacesArr = [];
try {
// Make a GET request
const url = `${process.env.PINECONE_API_ENDPOINT}/describe_index_stats`;
const response = await axios.get(url, {
headers: {
'Api-Key': PINECONE_API_KEY,
},
});
// Parse the response
namespacesArr = Object.keys(response.data.namespaces);
console.log(namespaces);
} catch (error) {
console.error('error describing index', error);
}
// iterate through namespaces and delete all indexes
for (const namespace of namespacesArr) {
try {
await index.delete1({
deleteAll: true,
namespace,
});
console.log(`Deleted all vectors in namespace: ${namespace}`);
} catch (error) {
console.error(
`Error deleting vectors in namespace: ${namespace}`,
error
);
}
}
})();
If you want to delete just one namespace, you can modify it like so:
let namespacesArr = ["your namespace that you want to delete"];
// iterate through namespaces and delete all indexes
for (const namespace of namespacesArr) {
try {
await index.delete1({
deleteAll: true,
namespace,
});
console.log(`Deleted all vectors in namespace: ${namespace}`);
} catch (error) {
console.error(
`Error deleting vectors in namespace: ${namespace}`,
error
);
}
}
You would have to install axios and the pinecone client libs:
npm install --save-dev axios
npm install --save-dev @pinecone-database/pinecone
And then you can run the script like this:
node ./path/to/script/node-delete-all-indexes.js