News for hackers. Stuff that matters.
Re:Why HNSW is not the answer and disk-based alternatives mi... by PaulHoule on Monday December 23, 2024 @02:13PM (#42496850)
I've been doing vector search since 2002 or so and it's amazing how far you can get keeping vectors in RAM and using primitive search algorithms, enough that I'm afraid the market for vector databases is 1% of what VC's think it is. (e.g. full scan was good enough for a search engine of international patents and non-patent literature)
Re:Why HNSW is not the answer and disk-based alternatives mi... by montebicyclelo on Monday December 23, 2024 @03:30PM (#42497345)
This 100%. Vector DBs have been heavily pushed by vector DB companies and cloud providers, and despite companies often having mere MBs of documents to search through for their use cases, amounts that trivially fit into RAM / can be searched via dot product in milliseconds, managers and engineers less familiar with the space think people are doing it wrong if they don't use a vector db. So.. vector DBs end up getting used when actually a simpler in-memory, non-approximate, solution would be fine, (but less monetizable)
Re:Why HNSW is not the answer and disk-based alternatives mi... by zackangelo on Monday December 23, 2024 @02:20PM (#42496907)
This is so true. A plain old exhaustive SIMD-optimized similarity search will do just fine in many cases and not have any of the approximation tradeoffs of HNSW.
Re:Why HNSW is not the answer and disk-based alternatives mi... by PhilippGille on Monday December 23, 2024 @02:43PM (#42497047)
In chromem-go [1] I'm searching through 100,000 vectors in 40ms on a mid-range laptop CPU, even without SIMD. It's quick enough for many use cases.

[1] https://github.com/philippgille/chromem-go

Re:Why HNSW is not the answer and disk-based alternatives mi... by PaulHoule on Monday December 23, 2024 @03:08PM (#42497211)
It would be very hard to find a problem that has better mechanical sympathy than full-scan similarity search. Even if the operation count of some other algorithm was 1/10 on paper it might not be faster if the prefetcher and branch predictor aren't running at their best.

People who want to start with RAG should not start with a vector search engine but instead download

https://sbert.net/

and start messing around w/ Jupyter notebooks and maybe FAISS. People who think I'm going to upload vectors to an expensive cloud service over a slow ADSL connection are delusional.

Re:Why HNSW is not the answer and disk-based alternatives mi... by abhgh on Monday December 23, 2024 @03:34PM (#42497372)
I strongly advocate this! If you're starting off in this space, check if this barebones implementation isn't all you need. You can't beat the accuracy of a full search; in theory, you're trading off scalability, but validate if you need the scale where this tradeoff begins to show. And yes, sbert is great, and it gives you options to choose [1] between accuracy (MPNet) and speed (MiniLM). There are also multi-lingual options. And remember, you can also fine-tune MPNet with SetFit. And there are always new and interesting embeddings being released, so remember to re-assess the fitment of embeddings once in a while against what you're using, e.g., LLM2vec or ModernBERT. A good idea would be to keep checking MTEB [2].

[1] https://www.sbert.net/docs/sentence_transformer/pretrained_m...

[2] https://huggingface.co/spaces/mteb/leaderboard

Re:Why HNSW is not the answer and disk-based alternatives mi... by VoVAllen on Monday December 23, 2024 @10:46PM (#42499594)
Hi, I'm the author of the article. I agree with your point. The model from https://www.mixedbread.ai/blog/mxbai-embed-xsmall-v1 also looks great, though I haven’t had the chance to try it yet.
Re:Why HNSW is not the answer and disk-based alternatives mi... by rockwotj on Monday December 23, 2024 @03:24PM (#42497308)
Swap out FAISS with usearch, you get all the awesome SIMD acceleration (via dynamic dispatch), optional compression. Not affiliated but really cool tech.

https://github.com/unum-cloud/usearch

Re:Why HNSW is not the answer and disk-based alternatives mi... by zackangelo on Monday December 23, 2024 @05:40PM (#42498178)
fwiw faiss, although a bit unwieldy, has an optimized full scan search built into it as well
Re:Why HNSW is not the answer and disk-based alternatives mi... by ashvardanian on Tuesday December 24, 2024 @07:08AM (#42501398)
Yes, it does, but it may be somewhat limited. If you need AVX2 float32 kernels for cosine distance, you are in luck. If you want dynamic dispatch from 200+ SIMD kernels across 4 generations of AVX-512 (Skylake-X, Ice Lake, Sapphire Rapids, and AMD Genoa), AVX2, Arm NEON, Arm SVE, and SVE2 for different mixed-precision distance functions, you may find other options more capable :)
Re:Why HNSW is not the answer and disk-based alternatives mi... by zackangelo on Tuesday December 24, 2024 @08:24AM (#42501752)
lol good to know! I've had the luxury of only needing the first one :)
Re:Why HNSW is not the answer and disk-based alternatives mi... by vegabook on Monday December 23, 2024 @06:12PM (#42498356)
Just tried usearch against ol’ faithful np.dot, and found the latter to be 8x faster than usearch on 10m brute force scan as described in their readme [1] for top 50 matches. Identical output result. 1.74 seconds for numpy and around 12 seconds for usearch on an M2 max with enough ram to hold the vectors without swapping.

[1] https://github.com/unum-cloud/usearch?tab=readme-ov-file#exa...

Re:Why HNSW is not the answer and disk-based alternatives mi... by ashvardanian on Tuesday December 24, 2024 @03:54AM (#42500619)
Author here :)

This might not be an apples-to-apples comparison. NumPy uses BLAS for matrix multiplication, which benefits from tiling to make better use of CPU caches.

USearch, on the other hand, computes L2 distance directly (not the dot product) and supports a variety of metrics. It doesn't use tiling, so it's expected to be slower than BLAS GEMM routines for single or double-precision vectors.

Things might get more interesting with half-precision, brain-float16, or integer representations, where the trade-offs are less straightforward. Let me know if you decide to try it with those — I'd love to hear how it performs.

PS: You may find related benchmarks here: https://github.com/ashvardanian/SimSIMD

Re:Why HNSW is not the answer and disk-based alternatives mi... by vegabook on Tuesday December 24, 2024 @06:00AM (#42501131)
It turns out, my bad and I apologise, that although 10e6 x 1e3 FP32 fits well within 96GB of RAM, during the np.random.rand initialization phase intermediate allocations mean we go to about 32GB of swap files. These only get cleared if more ram is demanded and that happens on the first bench run. So whichever gets run first, np or usearch, gets penalised bigtime. So now I have re-run with sizes that never reach swap threshold, and the results are MUCH more impressive for usearch. Basically usearch is twice as fast. 7e6x1e3 scan for 1e3 top 50 is 1.32 seconds for numpy and 0.633 seconds for usearch. Swapped the order of benchmarks as well to rerun, and results check out. Nice work. usearch is now in my toolkit and I apologise again for the misleading comment.

As an aside, it's kind of amazing how it takes essentially just over half a second to scan 7m 1032-size vectors for semantic similarity, on a (beefy but not extraordinary) desktop computer. Modern hardware is so awesome. And I'm guessing I could get another order of magnitude or two speedup if I got Metal involved.

EDIT: Linux on tiny el-cheapo 100 dollar Intel n95 mini PC with 32GIG of (single channel) RAM, and dropping size to 3mx1024: usearch: 0.65 seconds numpy: 0.99 seconds. Amazing.

Re:Why HNSW is not the answer and disk-based alternatives mi... by ashvardanian on Tuesday December 24, 2024 @07:03AM (#42501383)
Oh, epic! Thanks for taking the time to double check :)
Re:Why HNSW is not the answer and disk-based alternatives mi... by LunaSea on Monday December 23, 2024 @02:34PM (#42496990)
VC are terrible at technical due diligence so the money will keep pouring in.

However, CTOs are also terrible at assessing their technical necessities and vector databases will have customers the same way web scale databases did.

Re:Why HNSW is not the answer and disk-based alternatives mi... by raverbashing on Wednesday December 25, 2024 @07:25AM (#42508476)
This is for which vector dimension and number of vectors? (just curious)