• Home
  • Categories
  • Tags
  • Pricing
  • Submit
  1. Home
  2. Sdks & Libraries
  3. HNSW (Go)

HNSW (Go)

A Go implementation of the HNSW approximate nearest neighbor search algorithm, enabling developers to embed efficient vector similarity search directly into Go services and custom vector database solutions.

🌐Visit Website

About this tool

HNSW (Go)

Category: SDKs & Libraries
Technology: Go, Approximate Nearest Neighbor (ANN), Vector Search
Source: https://github.com/coder/hnsw

Overview

HNSW (Go) is a Go implementation of Hierarchical Navigable Small World (HNSW) graphs for fast approximate nearest neighbor (ANN) search over high-dimensional vectors. It can serve as an in-memory alternative to a vector database, suitable for embedding vector similarity search directly into Go applications and custom vector databases.

Features

Core Functionality

  • In-memory HNSW graph implementation in pure Go.
  • Approximate nearest neighbor search for high-dimensional vector data.
  • Designed as an in-memory alternative to vector databases (e.g., Pinecone, Weaviate) with essential operations.

Data Model & Operations

  • Insert
    • Operation: Insert a vector into the graph.
    • Complexity: ~O(log n).
  • Delete
    • Operation: Delete a vector from the graph.
    • Complexity: ~O(M² · log n), where M is the maximum number of neighbors per node.
  • Search
    • Operation: Search for nearest neighbors of a query vector.
    • Complexity: ~O(log n).
  • Lookup
    • Operation: Retrieve a vector by ID.
    • Complexity: O(1).
  • Configurable construction parameters (e.g., M, mL/Graph.Ml) to trade off speed, recall, and memory usage, following the original HNSW paper.

Go API & Usage

  • Simple Go module import:
    go get github.com/coder/hnsw@main
    
  • Graph creation via hnsw.NewGraph[IDType](), where the ID is generic (e.g., int).
  • Node creation with hnsw.MakeNode(id, []float32{...}).
  • Vector addition using Graph.Add(...).
  • Nearest neighbor search using Graph.Search(queryVector, k).

Persistence & Serialization

  • In-memory graph operations with optional persistent storage support.
  • Import/Export via streams:
    • Graph.Export(io.Writer) — write graph to an io.Writer.
    • Graph.Import(io.Reader) — load graph from an io.Reader.
  • File-backed SavedGraph abstraction:
    • LoadSavedGraph[T](path) to load or initialize a graph backed by a single file.
    • SavedGraph.Save() to persist the current graph state to disk.
  • Uses a fast binary encoding for the graph to achieve near disk-speed save/load performance (benchmarks provided for import/export on 100 vectors × 256 dimensions).

Performance & Tuning

  • Designed for fast querying with approximate nearest neighbor results.
  • Performance characteristics:
    • At high dimensionality (e.g., 1536 dimensions), a large portion of query time is spent in the distance function.
  • Suggested tuning guidelines:
    • To reduce latency:
      • Reduce vector dimensionality.
      • Increase M (maximum neighbors per node) for better search behavior at the cost of memory.
    • To reduce memory usage:
      • Decrease Graph.M (M — maximum neighbors per node).
      • Decrease Graph.Ml (mL — level generation parameter).

Pricing

Not applicable. HNSW (Go) is an open-source Go library; no pricing information is provided in the source content.

Surveys

Loading more......

Information

Websitegithub.com
PublishedDec 25, 2025

Categories

1 Item
Sdks & Libraries

Tags

3 Items
#ANN
#Go
#vector search

Similar Products

6 result(s)
HNSW (Rust)

A Rust implementation of the HNSW (Hierarchical Navigable Small World) approximate nearest neighbor search algorithm, useful for building high-performance, memory-safe vector search components in Rust-based AI and retrieval systems.

jvector

jvector is a high-performance Java-based library and engine for vector search and approximate nearest neighbor indexing.

NearestNeighbors.jl

NearestNeighbors.jl is a Julia package implementing various nearest neighbor search algorithms and index structures for high-dimensional vector data.

Voyager

Voyager is a Spotify open-source vector search library and service for efficient nearest neighbor search on large-scale vector datasets.

vsag

vsag is an Alibaba open-source library implementing efficient vector search algorithms, including approximate nearest neighbor search for high-dimensional vectors.

NVIDIA CAGRA

NVIDIA CAGRA is a GPU-accelerated graph-based library for approximate nearest neighbor searches, optimized for high-performance vector search leveraging modern GPU parallelism. It is suitable for scenarios requiring rapid, large-scale vector retrieval.

Built with
Ever Works
Ever Works

Connect with us

Stay Updated

Get the latest updates and exclusive content delivered to your inbox.

Product

  • Categories
  • Tags
  • Pricing
  • Help

Clients

  • Sign In
  • Register
  • Forgot password?

Company

  • About Us
  • Admin
  • Sitemap

Resources

  • Blog
  • Submit
  • API Documentation
All product names, logos, and brands are the property of their respective owners. All company, product, and service names used in this repository, related repositories, and associated websites are for identification purposes only. The use of these names, logos, and brands does not imply endorsement, affiliation, or sponsorship. This directory may include content generated by artificial intelligence.
Copyright © 2025 Acme. All rights reserved.·Terms of Service·Privacy Policy·Cookies