microsoft / SPTAG

A distributed approximate nearest neighborhood search (ANN) library which provides a high quality vector index build, search and distributed online serving toolkits for large scale vector search scenario.
MIT License
4.83k stars 580 forks source link

`DeleteWithMetaData` function in Python #337

Closed MohamedAliRashad closed 2 years ago

MohamedAliRashad commented 2 years ago

How to delete data in SPTAG using metadata ? I found no way to do this in one function, If it's unavailable can it be added ?

MohamedAliRashad commented 2 years ago

For those who will come with the same question, Here is what I found:

  1. There is a function called DeleteByMetaData that takes the metadata string as input and deletes all samples in the tree with this metadata name (Not exposed in the documentation sadly).
  2. The function won't work if the creation or the addition of samples in the tree is done without enabling metadata deletion ... To do this I made the second to last argument in the BuildWithMetaData and AddWithMetaData with True (Didn't work without it).
index.AddWithMetaData(index_set, meta_data, index_set.shape[0], True, False)
# or
index.BuildWithMetaData(index_set, meta_data, index_set.shape[0], True, False)
# then
index.DeleteByMetaData(sample_name+'\n')