Skip to content

feat: native Windows HNSW support (replace renameio with natefinch/atomic) #174

@nvandessel

Description

@nvandessel

Problem

coder/hnsw depends on google/renameio which does not compile on Windows. Currently, Windows builds fall back to BruteForceIndex (O(n) search, no persistence) via build tags (hnsw_windows.go).

Root Cause

The renameio dependency is used in exactly one function: SavedGraph.Save() in encode.go for atomic file writes. google/renameio will never support Windows — this is a deliberate design decision.

Proposed Solution

Fork coder/hnsw and replace renameio with natefinch/atomic, which supports Windows via MoveFileExW. The change is ~20-30 lines in a single file.

The coder/hnsw maintainer has described exactly what he wants in a previous (closed) PR:

  1. Replace renameio.TempFile + CloseAtomicallyReplace with atomic.WriteFile
  2. Use io.Pipe + bufio buffering on both sides to avoid doubling peak memory
  3. g.Export(wr) writes into pipe writer, atomic.WriteFile(path, pipeReader) reads from pipe reader

Implementation Plan

  1. Fork coder/hnswnvandessel/hnsw
  2. Apply the natefinch/atomic + io.Pipe fix
  3. Add replace directive in go.mod
  4. Delete hnsw_windows.go and remove //go:build !windows tags from hnsw.go / hnsw_test.go
  5. Submit the same fix upstream as a PR to coder/hnsw (ref: issue #9)
  6. Once merged upstream, remove the replace directive

Context

  • coder/hnsw#9 — Windows Compatibility (closed without fix)
  • coder/hnsw#12 — Previous PR (closed due to tone, not approach)
  • google/renameio#1 — Windows will never be supported
  • Current workaround: internal/vectorindex/hnsw_windows.go (BruteForceIndex fallback)

Alternatives Considered

Option Verdict
google/renameio/v2 Does not support Windows either
fogfish/hnsw Different API, low adoption (18 stars), no built-in persistence
Bithack/go-hnsw Abandoned since 2017
Keep brute-force fallback Acceptable short-term but doesn't scale

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions