News for hackers. Stuff that matters.
Re:How to Implement a Cosine Similarity Function in TypeScript by ashvardanian on Monday March 10, 2025 @05:54PM (#43326534)
It’s a nice post, but “using array methods” probably shouldn’t be placed in the “Efficient Implementation” section. As often happens with high-level languages, a single plain old loop is faster than three array methods.

Similarly, if you plan to query those vectors in search, you should consider continuous `TypedArray` types and smaller scalars than the double precision `number`.

I know very little about JS, but some of the amazing HackerNews community members have previously helped port SimSIMD to JavaScript (https://github.com/ashvardanian/SimSIMD), and I wrote a blog post covering some of those JS/TS-specifics, NumJS, and MathJS in 2023 (https://ashvardanian.com/posts/javascript-ai-vector-search/).

Hopefully, it should help unlock another 10-100x in performance.

Re:How to Implement a Cosine Similarity Function in TypeScript by mariusseufzer on Monday March 10, 2025 @06:58PM (#43327104)
Oh this is awesome! We actually have a really good use case for this, it should improve performance in our case a lot and help us stay away from WASM a bit longer. Thanks for sharing!
Re:How to Implement a Cosine Similarity Function in TypeScript by jgord on Monday March 10, 2025 @09:31PM (#43328246)
ooh, fantastic.. thankyou !

Im doing a bunch of 3D rotation transforms on millions of points in javascript .. this looks like what I need.

Re:How to Implement a Cosine Similarity Function in TypeScript by MrLeap on Tuesday March 11, 2025 @06:56AM (#43331189)
I'd probably use gpu.js for something like this.