Skip to main content
    listerineh.dev
    • About
    • Experience
    • Projects
    • Skills
    • Blog
    • Talks
    • Contact
    • Why
    • About
    • Experience
    • Projects
    • Skills
    • Blog
    • Talks
    • Contact
    • Why

    © 2026 Sebastian Alvarez

    All projects

    Vector Search in Go

    An HNSW vector index in pure Go, with a parallel graph build and lock-free search on every core.
    Source Code
    Vector Search in Go
    Role
    Backend Engineer
    Timeline
    November 2026
    Status
    Completed

    In numbers

    Queries per second on 12 goroutines, recall@10 0.985
    118,993118,993
    Throughput of 12 goroutines against one, with no locks
    8.75×8.75×
    Graph build on 8 workers, down from 0.79 s on one
    0.110.11s
    Throughput of an exact scan, on 100,000 vectors
    41×41×

    About the Project

    Vector Search in Go is the index behind semantic search, written from scratch to show where concurrency pays off and where it does not. It is HNSW, the graph that most vector databases use, in pure Go with nothing outside the standard library.

    The build inserts vectors from several goroutines at once, with one mutex per node and an exclusive lock only when the top layer of the graph grows. Once the build ends, the index freezes: searches take no locks at all, and any later insert panics, so a reader can never meet a writer. Each search borrows its scratch space from a sync.Pool, and a small HTTP server answers POST /search behind a semaphore sized to the number of cores. Exact search sits next to it, as ground truth and as the baseline.

    On BEIR SciFact, 5,183 abstracts embedded with bge-small at 384 dimensions, search throughput grew 8.75 times from 1 goroutine to 12, and 8 workers built the graph in 0.11 seconds instead of 0.79 with almost the same recall. Splitting one query across 8 graphs made it slower, so the index parallelizes between queries, not inside one. I built it in November 2026 as the Go concurrency counterpart to RAG Evals, which searches the same corpus with pgvector. The tests run with the race detector, including inserts and searches on the same index at the same time.

    Technologies
    1. API & backend

      • Go
      • Concurrency
    2. Data

      • HNSW
    3. Tooling

      • Benchmarks

    Relevance

    Concurrency measured, not assumed: lock-free reads that scale with cores, a parallel build that keeps recall, and a benchmark that also shows where parallelism hurts.

    How it works

    The path a request takes, step by step.

    1. 01 · AI modelEmbeddings5,183 SciFact abstracts, bge-small, 384 dims
    2. 02 · ServiceParallel buildGoroutines insert with one mutex per node
    3. 03 · DataFreezeThe graph stops changing; later inserts panic
    4. 04 · ServiceSearchConcurrent and lock-free, scratch from a sync.Pool
    5. 05 · ResultHTTP APIPOST /search behind a semaphore
    Every run checks HNSW against exact search on the same queries, so each throughput figure comes with its recall@10.

    Decisions

    The choices that shaped it, and what each one cost.

    1. 01

      Freeze the index instead of locking reads

      Why
      A built graph never changes, and even a read lock writes to a shared cache line. Freezing it lets every search run without locks.
      What it cost
      No inserts after the build; new vectors mean a rebuild.
    2. 02

      Parallelize between queries, not inside one

      Why
      Splitting one query over 8 graphs made it slower (71 → 93 µs) and lowered recall, because each shard repeats the beam search.
      What it cost
      One query is no faster on more cores; only throughput grows.
    3. 03

      Pure Go float32, no SIMD

      Why
      The code stays readable and portable; the dot product is unrolled by eight instead.
      What it cost
      Quantizing to int8 would cut memory traffic 4×, and it is not measured yet.
    4. 04

      Clustered synthetic data, not uniform

      Why
      Real embeddings cluster, and uniform random vectors make every index look worse than it is.
      What it cost
      The 100k figures are still synthetic and were run on a busy machine, so they are a lower bound.

    Next project

    Football Data PipelineA scheduled pipeline that turns Copa Libertadores and Sudamericana pages into quality-checked Parquet with DuckDB and serves it through an API, with its AWS infrastructure in Terraform.Next project
    listerineh.dev

    Full-stack engineer building AI agents, cloud platforms and web products. Based in Quito, working remotely.

    Open to new projects

    Work

    • Projects
    • Experience
    • Skills
    • Blog
    • Talks

    About me

    • About
    • Why Listerineh?
    • Contact

    Connect

    • GitHub
    • LinkedIn
    • Instagram
    • Email

    © 2026 Sebastian Alvarez · All rights reserved.

    • Privacy Policy
    • Terms of Use
    • Unsubscribe from the newsletter
    • Component Library