# GPU based Nearest Neighbor (brute force)

**URL:** <https://discourse.julialang.org/t/gpu-based-nearest-neighbor-brute-force/135753>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 20, 2026, 5:06pm UTC](https://discourse.julialang.org/t/gpu-based-nearest-neighbor-brute-force/135753 "2026-02-20T17:06:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [February 20, 2026, 5:06pm UTC](https://discourse.julialang.org/t/gpu-based-nearest-neighbor-brute-force/135753/1 "2026-02-20T17:06:02Z")

</div>

Hi,

Is there a maintained Julia package that can perform high-dimensional nearest-neighbor queries on the GPU, e.g., 1000s of queries against 10s of thousands of database vectors?

I’m aware of the wrapper for FAISS, but I wonder if there’s another Julia-native library (e.g., using Kernel Abstractions).

Regards.

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [February 21, 2026, 8:14pm UTC](https://discourse.julialang.org/t/gpu-based-nearest-neighbor-brute-force/135753/2 "2026-02-21T20:14:19Z")

</div>

The place for nn searches is [JuliaNeighbors · GitHub](https://github.com/JuliaNeighbors) . I do not think any of the libraries has GPU support however it can probably be added in a straightforward manner.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [February 21, 2026, 9:04pm UTC](https://discourse.julialang.org/t/gpu-based-nearest-neighbor-brute-force/135753/3 "2026-02-21T21:04:33Z")

</div>

In the `Distances` package, the function `pairwise` calculates all pairwise distances. The result can be reduced to the nearest neighbours.  
Since the calculation for appropriate metrics uses matrix products, they are GPU accelerated. Not sure this gains much compared to a brute-force double `for` loop.

---

<div class="post-metadata">

**Author:** ![langestefan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/langestefan/32/207923_2.png) [@langestefan](https://discourse.julialang.org/u/langestefan)\
**Post date:** [February 21, 2026, 9:19pm UTC](https://discourse.julialang.org/t/gpu-based-nearest-neighbor-brute-force/135753/4 "2026-02-21T21:19:05Z")

</div>

Perhaps it’s possible to run NearestNeighbors.jl using Reactant.jl? That would make it trivial to run on GPU.

---

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [February 23, 2026, 3:16pm UTC](https://discourse.julialang.org/t/gpu-based-nearest-neighbor-brute-force/135753/5 "2026-02-23T15:16:45Z")

</div>

You should clarify your setting a little more.

What do you want? Nearest neighbor, K nearest neighbor, approximate KNN, ???

Euclidean distance or something else?

“High-dimensional” is a meaningless term. Give us the number of zeros of the dimension.

By dimension, I assume you mean extrinsic dimension, e.g. “oh I have 5000 long Float32 vectors”.

There is also an intrinsic dimension, e.g. “…but the data tends lies on an effectively 4.7 dimensional data manifold” (which is not a manifold; datasets tend to have fractal and scale-dependent dimension, like e.g. the space of sequences with `sum(xn^2/n^2 for (n,xn) in enumerate(x)) < 1` with respect to the euclidean norm).

Intrinsic dimension tends to determine the performance of non-brute-force approaches. But the intrinsic dimension may not be apparent.

You have not told us whether you have single queries or batched queries, and whether you care about latency or throughput or power consumption. (If you have single queries and care about throughput, then batch them!)

You have not told us why you want brute-force and why you want GPU.

All that being said… ~1e3 queries against ~1e4 points is tiny. You should not need a GPU for that, this is a job for a toaster. And if you use GPU, you should not need a fancy library, this is one matmul.

---

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [February 23, 2026, 7:50pm UTC](https://discourse.julialang.org/t/gpu-based-nearest-neighbor-brute-force/135753/6 "2026-02-23T19:50:49Z")

</div>

cos similarity or Euclidean distance, 128 to 512 dimensional Float 32 embeddings batched. query, roughly matching 10,000 against 10,000; 2-nearest neigbors.
