I am facing a challenge when it es to deleting vectors in a namespace in pinecone. I am using javascript and trying to delete all vectors in a namespace,I get this error “[ErrorWithoutStackTrace: No ids provided]”, could anyone be knowing why this is and how to solve it? thanks in advance
I have tried using this code, “await index.delete1([ ], true, “example-namespace”);” as specified in the Delete vectors by namespace part of the pinecone documentation but i get the error mentioned above,
I am facing a challenge when it es to deleting vectors in a namespace in pinecone. I am using javascript and trying to delete all vectors in a namespace,I get this error “[ErrorWithoutStackTrace: No ids provided]”, could anyone be knowing why this is and how to solve it? thanks in advance
I have tried using this code, “await index.delete1([ ], true, “example-namespace”);” as specified in the Delete vectors by namespace part of the pinecone documentation but i get the error mentioned above,
Share Improve this question asked Apr 2, 2023 at 14:42 shane Atwiineshane Atwiine 1811 silver badge5 bronze badges6 Answers
Reset to default 8I found a solution:
await index.delete1({
deleteAll: true,
namespace,
});
I got this from the Pinecone GitHub repo.
index.delete(namespace='your-namespace', delete_all=True)
const index = pinecone.Index("your_index_name");
await index.delete1({
deleteAll: true,
namespace: "your_namespace_name"
});
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
const deleteAllVectorsOfIndex = async () => {
const index = pinecone.Index(process.env.PINECONE_INDEX_NAME);
const deleteResponse = await index.delete1({
deleteAll: true,
namespace: process.env.PINECONE_NAME_SPACE
})
console.log("deleteResponse: ", deleteResponse);
}
deleteAllVectorsOfIndex();
After upgrade of pinecone library to version 1 it should be coded as follows:
const pineconeClient = new Pinecone({
apiKey: PINECONE_API_KEY,
environment: PINECONE_ENVIRONMENT
})
const index = pineconeClient.Index(indexName)
const namespaceIndex = index.namespace(nameSpace);
const res = await namespaceIndex.deleteAll();