This page covers the conceptual storage model. For lower level details (
compression, quantization, exact byte-level encoding schemas, etc see the
RFCs on
GitHub
Stored Structures
| Structure | Purpose |
|---|---|
| Dictionary | Maps each record’s id to an internal id |
| Forward Index | Maps each record’s internal id to its attributes |
| Inverted Index | Maps indexed attribute key/value pairs to internal IDs for efficient attribute-based filtering |
| Centroids | Stores the current set of centroid vectors |
| Postings | Maps each centroid to the set of associated vectors |
Dictionary
The dictionary maps each record to its internal id. Records are written to Vector using a user-provided id that can be up to 64 bytes. Vector maps these to an internal 64-bit id for efficient storage and stores the mapping in this dictionary.Forward Index
The forward index maps each record’s internal id to the full set of record attributes, including the associated vector.Inverted Index
The inverted index maps a given attribute key-value pair to the set of internal ids of records that match that key-value pair. The set is stored as a bitmap for efficient inclusion/exclusion tests and set operations when evaluating attribute-based filters.Centroids
This is the current set of centroid vectors. When Vector is loaded, it reads the set of centroids to build the in-memory graph that enables it to efficiently find the closest centroids to a query vector.Postings
The postings map each centroid to the set of associated nearby vectors. Each posting entry is keyed by the centroid id and stores both the record id and the record’s vector.How a query uses the stored structures
To illustrate how Vector uses the stored structures, lets consider a few high-level flows. First, consider a query that searches for 10 records near vector[0.1, 0.2, 0.3] with attribute filter department="electronics":
- If not yet loaded, load the centroids and build the in-memory centroid graph.
- Search the centroid graph for centroids close to
[0.1, 0.2, 0.3]. - Load all vectors from postings mapped to the nearby centroids.
- Use the inverted index to filter the vectors that match
department="electronics". - Compute the distance of each vector to
[0.1, 0.2, 0.3]and sort-rank these. - Return the 10 closest records
How the database is maintained on an upsert
Now let’s take a look at how the database is maintained on an upsert. Consider an upsert of a record with id “calculator”, vector[0.1, 0.2, 0.3] with an
attribute department="electronics":
- Look up “calculator” in the dictionary. If it’s present, then mark its existing id as deleted in the forward index, inverted index, and postings.
- Assign a new internal id to the record.
- Update the dictionary to associate “calculator” with the new internal id.
- Write a mapping from the internal id to the record data in the forward index.
- Find the nearest centroid(s) and add the new internal id and
[0.1, 0.2, 0.3]to the postings. - Update the inverted index entry for
department="electronics"to include the new internal id.