How do I check if a namespace already exists in an Index?

I would like to check if I have already created vectors with a specific namespace. Is there an API I could hit for that info?

Did you find an answer?

Hi @yangsunwoo

you can run a query with the vector and top_k = 1 then check the score. If its 1 or more the vector is already in the namespace (which you provide in the query itself).

Hope this helps

Edit. If you only want to check if a namespace with some number of vectors exists, you can use the DescribeIndexStats

2 Likes

@muhammad.usman & @yangsunwoo

here is a direct code snippet - really easy. Just grab the list and check if namespace exists via mapping.

1 Like

Thank you @tim , do you have link to the Python version of this function?

Hi @muhammad.usman, the below function will accomplish the same check in Python:

def namespace_exists(index, namespace):
    namespaces = index.describe_index_stats()['namespaces']
    return namespace in namespaces
4 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.