# Is it possible to update NearestNeighbors.jl trees after construction?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-update-nearestneighbors-jl-trees-after-construction/137892
**Category:** General Usage
**Tags:** question, package, nearest-neighbors
**Created:** [July 1, 2026, 2:32pm UTC](https://discourse.julialang.org/t/is-it-possible-to-update-nearestneighbors-jl-trees-after-construction/137892 "2026-07-01T14:32:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [July 1, 2026, 2:32pm UTC](https://discourse.julialang.org/t/is-it-possible-to-update-nearestneighbors-jl-trees-after-construction/137892/1 "2026-07-01T14:32:56Z")

</div>

Is it possible to update the data in a tree after construction? Say we need to add more points to the tree, how to `push!` or `append!`? I’ve read the documentation and there is no example for that. By reading the source code I couldn’t find it either.

I’ve opened an issue in the GitHub repository to track it over there as well, in case anyone knows a solution: [Documentation for tree updates? · Issue #244 · KristofferC/NearestNeighbors.jl · GitHub](https://github.com/KristofferC/NearestNeighbors.jl/issues/244)

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [July 1, 2026, 3:49pm UTC](https://discourse.julialang.org/t/is-it-possible-to-update-nearestneighbors-jl-trees-after-construction/137892/2 "2026-07-01T15:49:48Z")

</div>

Kristoffer answered on GitHub. Not possible by design.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [July 1, 2026, 3:59pm UTC](https://discourse.julialang.org/t/is-it-possible-to-update-nearestneighbors-jl-trees-after-construction/137892/3 "2026-07-01T15:59:37Z")

</div>

Just to mention that the complementary package AdaptiveKDTrees.jl seems to have that functionality.

---

<div class="post-metadata">

### Author: ![cgeoga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgeoga/32/216186_2.png) [@cgeoga](https://discourse.julialang.org/u/cgeoga)
#### Post date: [July 4, 2026, 4:38pm UTC](https://discourse.julialang.org/t/is-it-possible-to-update-nearestneighbors-jl-trees-after-construction/137892/4 "2026-07-04T16:38:14Z")

</div>

@juliohm, FYI: I don’t know what your exact task is, but I wrote a small [`jll`](https://github.com/cgeoga/sequentialknn) package for using [`kiddo`](https://github.com/https://github.com/sdd/kiddo), a rust package that allows for dynamic trees. In plenty of benchmarks, it appears to be the fastest tree library available. For a pure Julia solution, I use [`HNSW.jl`](https://github.com/JuliaNeighbors/HNSW.jl) for the dynamic lookups, although these are not exact/deterministic.

I have an [extension](https://github.com/cgeoga/Vecchia.jl/blob/main/ext/VecchiasequentialknnExt.jl) for `Vecchia.jl`. The speedups for specifying the conditioning sets can be pretty significant:

```julia-auto
julia> using BenchmarkTools, Vecchia, StaticArrays

julia> kernel(x, y, params) = exp(-norm(x-y)/params[2])
kernel (generic function with 1 method)

julia> pts = rand(SVector{2,Float64}, 50_000);

julia> @btime VecchiaApproximation($pts, kernel; conditioning=$(KNNConditioning(30))); # HNSW.jl
  1.606 s (4763276 allocations: 1.09 GiB)

julia> using sequentialknn_jll
 │ Package sequentialknn_jll not found, but a package named sequentialknn_jll is available from a registry. 
 │ Install package?
 │ (jl_Q8Qptm) pkg> add sequentialknn_jll 
 └ (y/n/o) [y]: 
   Resolving package versions...
    Updating `/tmp/jl_Q8Qptm/Project.toml`
  [a3d66c5c] + sequentialknn_jll v0.2.0+0
    Updating `/tmp/jl_Q8Qptm/Manifest.toml`
  [692b3bcd] + JLLWrappers v1.8.0
  [94ce4f54] + Libiconv_jll v1.18.0+0
  [a3d66c5c] + sequentialknn_jll v0.2.0+0
[Info: Precompiling VecchiasequentialknnExt [7df10478-612b-5f95-b980-c0b68bb95406](cache misses: wrong dep version loaded (2))
Precompiling Vecchia → VecchiasequentialknnExt finished.
  1 dependency successfully precompiled in 1 seconds. 20 already precompiled.

julia> @btime VecchiaApproximation($pts, kernel; conditioning=$(KNNConditioning(30)));
[ Info: Using accelerated sequentialknn_jll methods...
  97.890 ms (200089 allocations: 47.00 MiB)

```

If this or other functionality from `kiddo` might be useful to you, I would be happy to participate in expanding that interface and jll. Longer term, it would be cool to have a Julia-native solution that accepted as wide a range of distance metrics as possible, but I think Kristoffer, who I won’t @ because I’ve annoyed him enough about this stuff, has explained would require basically a clean re-write to try and specialize on. So that seems like a longer term project.
