To delete a namespace, you must delete all records in the namespace. Once you’ve deleted all the records in the namespace, the namespace will no longer appear in the index.

You can delete all the records in a namespace using the Python client with the following approach:

namespace = "<INSERT_NAMESPACE>"

index.delete(namespace=namespace, delete_all=True)

For more documentation on the Delete operation, see our API reference.

If you have several hundred records in your namespace, using delete_all=True could negatively impact the performance of your queries. We recommend deleting the records in batches of a couple of hundred at a time and implementing a brief sleep between operations. You can batch your deletions with the following approach:

def batch_deletes_within_namespace(index, namespace, dimensions, batch=100):
  # Import some libraries in case they weren't elsewhere
  import numpy as np
  import time

  # Next, we'll create a random vector to use as a query.
  query_vector = np.random.uniform(-1, 1, size=dimensions).tolist()

 # Now, cycle through the index and add a slight sleep time in between batches to make sure we don't overwhelm the index.
 deletes = []
 deleted = 0
 results = index.query(vector=query\_vector, namespace=namespace, top\_k=batch)
 while len(results['matches']) > 0:
 ids = [i['id'] for i in results['matches']]
 index.delete(ids=ids, namespace=namespace)
 deleted += len(ids)
 results = index.query(vector=query\_vector, namespace=namespace, top\_k=batch)
 return deleted