# Sample notebook for merging hnsw graphs

**URL:** <https://discuss.elastic.co/t/sample-notebook-for-merging-hnsw-graphs/378834>\
**Category:** Elasticsearch\
**Created:** [June 4, 2025, 1:09am UTC](https://discuss.elastic.co/t/sample-notebook-for-merging-hnsw-graphs/378834 "2025-06-04T01:09:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chenzhe\_Jin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenzhe_jin/32/143507_2.png) [@Chenzhe\_Jin](https://discuss.elastic.co/u/Chenzhe_Jin)\
**Post date:** [June 4, 2025, 1:09am UTC](https://discuss.elastic.co/t/sample-notebook-for-merging-hnsw-graphs/378834/1 "2025-06-04T01:09:35Z")

</div>

I am wondering whether or where I can find the sample code for this blog [Speeding up merging of HNSW graphs - Elasticsearch Labs](https://www.elastic.co/search-labs/blog/hnsw-graphs-speed-up-merging)?

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [June 4, 2025, 11:10am UTC](https://discuss.elastic.co/t/sample-notebook-for-merging-hnsw-graphs/378834/2 "2025-06-04T11:10:02Z")

</div>

Hi @Chenzhe_Jin,

Welcome! To confirm are you looking for a notebook containing the code for the experiment rather than the discussed pseudocode? Normally search labs accompanying notebooks are located in the [elasticsearch-labs GitHub repo under the `supporting-blog-content` folder](https://github.com/elastic/elasticsearch-labs/tree/main/supporting-blog-content), but I expect there isn't one for this piece.

The author @Tom_Veasey and @mayya may be able to help.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [June 4, 2025, 1:04pm UTC](https://discuss.elastic.co/t/sample-notebook-for-merging-hnsw-graphs/378834/3 "2025-06-04T13:04:06Z")

</div>

This change is incorporated in Lucene (a library that Elasticsearch uses underneath).

You can study the code in the following [PR](https://github.com/apache/lucene/pull/14331).

---

<div class="post-metadata">

**Author:** ![Chenzhe\_Jin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenzhe_jin/32/143507_2.png) [@Chenzhe\_Jin](https://discuss.elastic.co/u/Chenzhe_Jin)\
**Post date:** [June 4, 2025, 8:30pm UTC](https://discuss.elastic.co/t/sample-notebook-for-merging-hnsw-graphs/378834/4 "2025-06-04T20:30:21Z")

</div>

Thanks for your reply! I am also wondering if there is some code or instructions we can follow to reproduce the experiments in the blog and PR?

---

<div class="post-metadata">

**Author:** ![Chenzhe\_Jin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chenzhe_jin/32/143507_2.png) [@Chenzhe\_Jin](https://discuss.elastic.co/u/Chenzhe_Jin)\
**Post date:** [June 5, 2025, 2:31am UTC](https://discuss.elastic.co/t/sample-notebook-for-merging-hnsw-graphs/378834/5 "2025-06-05T02:31:58Z")

</div>

Hi, I have another question when I read the code. Can your merge strategy support parallelism? When I read the code, I find there is no parallelism design. Thanks for your patience.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [June 5, 2025, 4:01pm UTC](https://discuss.elastic.co/t/sample-notebook-for-merging-hnsw-graphs/378834/6 "2025-06-05T16:01:44Z")

</div>

No, currently there is no parallelism.  
We go [through all segment graphs](https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/util/hnsw/MergingHnswGraphBuilder.java#L125-L127) and add them incrementally to the biggest graph.
