hnswlib icon indicating copy to clipboard operation
hnswlib copied to clipboard

Complexity of add_items?

Open otmhi opened this issue 2 years ago • 1 comments

Hello everyone,

This is more a question than an issue. I want to know how the algorithm handles adding items and what's the complexity of this method. It can be split into 2 questions, basically: 1 - What is the complexity of the add_items method when the item is new? 2 - If the item already exists, what the complexity of updating it? 3 - Is it better to mark the item as deleted and then adding the updated embedding as a new item?

Thank you very much for your insight!

otmhi avatar Jun 30 '22 15:06 otmhi

Hi @otmhi,

  1. The insertion complexity is somewhat comparable to a search complexity (you can think that it has a constant 2X or something multiplier overhead)
  2. Updating is much more expensive than insertion (I think something like tens of insertions to make the accuracy not degrade over time).
  3. That depends on the definition of "better". It is faster, but uses more memory and will degrade some performance at search time.

yurymalkov avatar Jul 05 '22 20:07 yurymalkov