Cross-Platform DiskANN in Zvec for Lower-Memory Local Search

DiskANN in Zvec 0.8.1 is now available on Linux, Windows, macOS, Android, and iOS.

DiskANN supports Linux on servers, Windows and macOS on desktops, and Android and iOS through native SDKs

Why Use DiskANN?

A local knowledge base may start with a few hundred or a few thousand documents. As more material accumulates, the vector count can grow from tens of thousands to tens or even hundreds of millions. Search still works, but memory gets tight. Model inference, the application itself, and the vector index all compete for RAM on the same device.

This can happen on cloud servers, laptops, and phones.

DiskANN keeps full vectors and most of the graph on disk. RAM mainly holds product quantization (PQ) codes and query workspace. During a search, DiskANN uses the codes to estimate distances to candidate nodes, then reads node data from disk as needed. For the same number of new vectors, resident memory typically grows less with DiskANN than with HNSW.

Query memory and index read paths for HNSW and DiskANN

Memory Usage

HNSW is a straightforward, efficient choice when memory is plentiful. If the index starts to strain the application's or model's memory budget, DiskANN lowers resident memory usage by reading from disk on demand.

We compared query memory for HNSW and DiskANN across platforms using SIFT-100K, a dataset of 100,000 128-dimensional FP32 vectors. Query memory is the difference between the process memory immediately before Zvec opens the index and the peak process memory measured from index opening through the end of the query run.

PlatformHNSW query memoryDiskANN query memoryMemory saved
Linux87.96 MiB8.91 MiB79.05 MiB
Windows88.11 MiB11.71 MiB76.40 MiB
macOS92.11 MiB11.05 MiB81.06 MiB
Android87.35 MiB7.94 MiB79.41 MiB
iOS91.68 MiB11.22 MiB80.46 MiB

The raw vectors in this test take up about 49 MiB. DiskANN used about 76–81 MiB less query memory than HNSW.

Recall and Query Performance

DiskANN maintained high recall while using less memory. We tested it with the default build settings max_degree=100 and list_size=50 and the default query setting list_size=300.

On SIFT-100K, DiskANN achieved 99.990% Recall@50 with these defaults, which we use throughout the results below. HNSW achieved about 99.980% Recall@50 with its defaults of m=50 and ef_construction=500 for construction and ef_search=300 for queries.

Under the same SIFT-100K query workload, DiskANN delivered approximately 37–39 QPS on Linux, Windows, macOS, and mobile simulators when random-read rates were close to 2,000 IOPS.

Measured IOPS on LinuxDiskANN QPS
1,90137.1
3,82174.6
7,504146.5
16,659325.2

Desktop. On a Mac with an Apple M3, DiskANN ran single-threaded queries against SIFT-100K on macOS with a P95 latency of approximately 5.23 ms.

Mobile. On a physical iPhone 17, DiskANN ran single-threaded queries against the same dataset with a P95 latency of approximately 4.6 ms during repeated queries.

I/O Across Platforms

Operating systems offer different I/O capabilities. Kernel versions, container configuration, and runtime dependencies can also affect which read methods are available. Zvec adapts its read backend to each platform.

In each search round, DiskANN may need to read several candidate nodes from different locations on disk. An asynchronous backend can submit multiple reads at once so the storage device can handle them concurrently. When disk reads dominate query time and the device supports concurrent reads, this can improve QPS and reduce latency. Synchronous pread issues reads one at a time, has few deployment dependencies, and works in environments where asynchronous I/O is unavailable.

On Linux, Zvec detects available read backends automatically and tries io_uring, libaio, and synchronous pread, in that order. The io_uring backend uses kernel system calls directly and requires no separate liburing installation. Zvec loads libaio at runtime.

Automatic fallback reduces deployment setup and lets DiskANN query the index even when an asynchronous backend is unavailable. Performance depends on the backend selected.

On Windows, Zvec uses native overlapped I/O and manages asynchronous requests through I/O completion ports. macOS, Android, and iOS use the portable pread backend.

Server SSDs, laptop storage, and mobile flash have different random-read performance. Synchronous and asynchronous backends also differ in the concurrency they support. Developers can use the SDK for their platform to evaluate DiskANN on the target device.

Getting Started with DiskANN

In the Python SDK, set DiskAnnIndexParam on the vector field when creating the collection. After batch insertion, call optimize() to seal the current write segment and build the index using the collection configuration. The following example generates 512 128-dimensional vectors and queries for the 10 records closest to the first vector.

from random import Random

import zvec

schema = zvec.CollectionSchema(
    name="local_search",
    vectors=[
        zvec.VectorSchema(
            "embedding",
            zvec.DataType.VECTOR_FP32,
            dimension=128,
            index_param=zvec.DiskAnnIndexParam(metric_type=zvec.MetricType.L2),
        )
    ],
)
collection = zvec.create_and_open("./local_search", schema=schema)

rng = Random(42)
embeddings = [[rng.random() for _ in range(128)] for _ in range(512)]
statuses = collection.insert([
    zvec.Doc(id=f"doc-{i}", vectors={"embedding": vector})
    for i, vector in enumerate(embeddings)
])
if not all(status.ok() for status in statuses):
    raise RuntimeError("Failed to insert vectors")

collection.optimize()

hits = collection.query(
    queries=zvec.Query(
        field_name="embedding",
        vector=embeddings[0],
        param=zvec.DiskAnnQueryParam(list_size=300),
    ),
    topk=10,
)
for hit in hits:
    print(hit.id, hit.score)

collection.close()

Common Parameters

StageParameterPython SDK defaultHow to choose
Buildmetric_typeIPUse the metric recommended by your embedding model. Common options include inner product (IP), cosine (COSINE), and Euclidean distance (L2).
Buildmax_degree100Maximum neighbors per graph node. Higher values can improve recall and increase index size and build time.
Buildlist_size50Number of candidates considered during graph construction. Higher values can improve graph quality and increase build time.
Buildpq_chunk_num0, selected automatically based on vector dimensionControls the length of the PQ codes kept in memory. More chunks usually yield more precise distance estimates and use more memory.
Querylist_size300Number of candidates kept during search. Higher values can improve recall and increase disk reads and query latency.

Start with the default build parameters, then tune query list_size on the target device and compare recall and P95 latency. topk controls how many results are returned. Query list_size controls how many candidates are kept during search.

For more parameters, see the DiskANN index documentation and the Python API reference.

For more on algorithm design, index construction, and optimizations, see the earlier DiskANN article.

Try Zvec 0.8.1 and share your device details and feedback on GitHub.