What is an array?

An array stores a fixed sequence of values contiguously in memory with instant access by position, the natural structure for storing a single vector's own list of numbers.
Created: Updated: 3 min read

An array is a data structure that stores a fixed sequence of values one after another in contiguous memory, letting any individual value be accessed instantly just by knowing its position, and this simple, predictable layout makes arrays the natural way to store a single vector‘s own list of numbers.

What does it actually mean for an array’s values to be stored contiguously, and why does that matter?

Storing values contiguously means placing them directly next to each other in memory, in order, rather than scattering them around and connecting them through separate references the way some other data structures do. Because every value sits at a predictable, evenly-spaced position, accessing any specific element by its index takes exactly the same, small, constant amount of work no matter how large the array is or which position is being accessed — there’s no need to walk through the array searching for it, since its exact memory location can be calculated directly from its position. This predictable, instant access is precisely what makes arrays such a fast and efficient choice whenever a fixed-size sequence of values needs to be stored and read frequently.

Why is an array specifically the natural way to represent a single vector’s own data?

A vector, covered elsewhere in this glossary, is fundamentally an ordered list of numbers, and that description matches an array’s own structure almost exactly: a fixed-length sequence of values, each one directly reachable by its position. Storing a vector’s dimension values in an array means that computing a distance function, covered throughout this glossary, which requires visiting each dimension of both vectors in order, can proceed efficiently and predictably, stepping through both arrays’ matching positions one after another without any extra overhead for locating each value. This tight, predictable memory layout is a large part of why distance calculations, covered in this site’s coverage of how distance calculations affect index performance, can be made so fast in practice.

Where else in HNSW’s own structure does an array-like storage layout show up, beyond individual vectors?

Beyond storing each vector’s own values, HNSW‘s implementations frequently rely on array-like storage for holding the full collection of vectors together, and for storing the neighbor lists that make up the graph‘s actual connections at each layer, covered in this site’s coverage of how HNSW‘s data structures should be laid out in memory for performance. Keeping these collections in contiguous, array-like storage rather than scattering them across memory tends to improve real-world performance meaningfully, since it makes better use of a computer’s memory caching behavior, which rewards accessing nearby memory locations in sequence rather than jumping unpredictably between distant ones.

An array’s simple, contiguous layout is what makes both individual vectors and larger collections of them fast and predictable to work with, a foundation the rest of HNSW’s more elaborate data structures are ultimately built on top of. From here, the pages on vector and on how HNSW’s data structures should be laid out in memory for performance dig further into how this simple structure gets put to work in practice.