3 ms·
Yes, HSNWs are not so complex, and they work great. I wrote an implementation myself, it's 2500 lines of code (5x the one of dicroce!), but inside there is bina
by antirez 2y ago
Yes, HSNWs are not so complex, and they work great. I wrote an implementation myself, it's 2500 lines of code (5x the one of dicroce!), but inside there is binary and int8 quantization and many advanced features (include true deletions), and I commented it as much as possible. I hope you may find it useful to read alongside the one proposed by OP:
https://github.com/redis/redis/blob/unstable/modules/vector-sets/hnsw.c https://github.com/redis/redis/blob/unstable/modules/vector-...
Still, to be honest, I'm reading the 500 lines of code with great interest because I didn't thought it was possible to go so small, maybe part of the trick is that's in C++ and not in C, as for instance you don't have the queue code.
Also the strategy used by my implementation in order to re-link the orphaned nodes upon deletion adds complexity, too. (btw any feedback on that part is especially appreciated)
EDIT: Ok after carefully inspection this makes more sense :D
1. Yes, C++ helps, the vector class, the priority queue, ...
2. I forgot to say that I implemented serialization other than quantization, and this also includes quite some code.
3. Support for threads is another complexity / code-size price to pay.
And so forth. Ok, now it makes a lot of sense. Probably the 500 LOC implementation is a better first-exposure experience for newcomers. After accumulating all the "but how to..." questions, maybe my C implementation is a useful read.