Class Guardiann
Architecture
Vectors are partitioned into clusters. Each cluster stores a set of primary vector references (the authoritative copies) and replicated references (copies from neighboring clusters kept for improved search recall). Cluster centroids are indexed in an HNSW graph so that the nearest clusters to a query vector can be found efficiently.
Operations
- Insert (
insert()) — finds the nearest cluster(s) for a new vector, writes primary and replicated references, and triggers deferred maintenance tasks (split/merge/reassign) if cluster size invariants are violated. - Search (
kNearestNeighborsSearch(com.apple.foundationdb.ReadTransaction, int, com.apple.foundationdb.async.guardiann.SearchConfig, boolean, com.apple.foundationdb.linear.RealVector)) — probes the nearest cluster centroids, scans their vector references, and returns the top-k closest vectors. Supports distance-ratio pruning and centroid-ball pruning viamaxEverbounds. - Delete (
delete()) — locates and removes vector references from clusters, updates metadata, and handles collapsed (deduplicated) vectors.
Maintenance
Structural maintenance is performed lazily via deferred tasks that are executed piggy-backed on insert and delete operations:
- Split/Merge — when a cluster grows beyond
Config.primaryClusterMax()or shrinks belowConfig.primaryClusterMin(), aSplitMergeTaskrepartitions the affected clusters using bounded k-means and updates the HNSW centroid index. - Reassign — a
ReassignTaskrecomputes vector assignments and replication for a cluster, fixing underreplicated vectors and cleaning up excess replicas. - Collapse — a
CollapseTaskdetects large groups of identical vectors and replaces them with a single collapsed representative to reduce storage. - Bounce — a
BounceTaskcoordinates execution order between dependent tasks, ensuring prerequisite tasks complete before follow-up tasks are created.
Usage
This class is the primary entry point for interacting with the Guardiann vector structure. It
delegates to specialized operation classes (Insert, Search, Delete) which
implement the respective algorithms. All operations are asynchronous and designed for use within
FoundationDB transactions.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGuardiann(Subspace subspace, Executor executor, Config config, OnWriteListener onWriteListener, OnReadListener onReadListener) Constructs a new Guardiann vector structure instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigdefaultConfig(int numDimensions) Returns a defaultConfig.delete(Transaction transaction, Tuple primaryKey, RealVector vector) Deletes a vector identified by its primary key from the Guardiann index.Get this object's configuration.Get the executor used by this object.Get the on-read listener.Get the on-write listener.Gets the subspace associated with this object.insert(Transaction transaction, Tuple newPrimaryKey, RealVector newVector, Tuple additionalValues) Inserts a new vector with its associated primary key into the vector structure.CompletableFuture<List<? extends ResultEntry>> kNearestNeighborsSearch(ReadTransaction readTransaction, int k, SearchConfig searchConfig, boolean includeVectors, RealVector queryVector) Performs a search for the k-nearest neighbors for a given query vector.static Config.ConfigBuilderStart building aConfig.
-
Constructor Details
-
Guardiann
public Guardiann(@Nonnull Subspace subspace, @Nonnull Executor executor, @Nonnull Config config, @Nonnull OnWriteListener onWriteListener, @Nonnull OnReadListener onReadListener) Constructs a new Guardiann vector structure instance.Initializes the structure with the necessary components for storage, execution, configuration, and event handling. All parameters are mandatory and must not be null.
- Parameters:
subspace- theSubspacewhere the vector structure data is storedexecutor- theExecutorservice to use for concurrent operationsconfig- theConfigobject containing algorithm and storage parametersonWriteListener- a listener to be notified of write eventsonReadListener- a listener to be notified of read events
-
-
Method Details
-
newConfigBuilder
Start building aConfig.- Returns:
- a new
Configthat can be altered and then built for use with aGuardiann - See Also:
-
defaultConfig
Returns a defaultConfig.- Parameters:
numDimensions- number of dimensions- Returns:
- a new default
Config. - See Also:
-
getLocator
-
getSubspace
Gets the subspace associated with this object.- Returns:
- the non-null subspace
-
getExecutor
Get the executor used by this object.- Returns:
- executor used when running asynchronous tasks
-
getConfig
Get this object's configuration.- Returns:
- the configuration
-
getOnWriteListener
Get the on-write listener.- Returns:
- the on-write listener
-
getOnReadListener
Get the on-read listener.- Returns:
- the on-read listener
-
kNearestNeighborsSearch
@Nonnull public CompletableFuture<List<? extends ResultEntry>> kNearestNeighborsSearch(@Nonnull ReadTransaction readTransaction, int k, @Nonnull SearchConfig searchConfig, boolean includeVectors, @Nonnull RealVector queryVector) Performs a search for the k-nearest neighbors for a given query vector.- Parameters:
readTransaction- the transaction to use for reading from the databasek- the number of nearest neighbors to returnsearchConfig- the performance/recall tuning knobs for this search (seeSearchConfig)includeVectors- indicator if the caller would like the search to also include vectors in the result setqueryVector- the vector to find the nearest neighbors of- Returns:
- a
CompletableFuturethat will complete with a list of theknearest neighbors, sorted by distance in ascending order.
-
insert
@Nonnull public CompletableFuture<Void> insert(@Nonnull Transaction transaction, @Nonnull Tuple newPrimaryKey, @Nonnull RealVector newVector, @Nullable Tuple additionalValues) Inserts a new vector with its associated primary key into the vector structure.Finds the nearest cluster(s) for the new vector by querying the HNSW centroid index, then writes a primary vector reference to the nearest cluster and replicated references to neighboring clusters based on replication priority scoring. Updates cluster metadata and enqueues deferred maintenance tasks (split, merge, reassign) if cluster size invariants are violated.
- Parameters:
transaction- theTransactioncontext for all database operationsnewPrimaryKey- the uniqueTupleprimary key for the new vector being insertednewVector- theRealVectordata to be insertedadditionalValues- additional values to be associated with the new vector/record, ornull- Returns:
- a
CompletableFuturethat completes when the insertion operation is finished
-
delete
@Nonnull public CompletableFuture<Void> delete(@Nonnull Transaction transaction, @Nonnull Tuple primaryKey, @Nonnull RealVector vector) Deletes a vector identified by its primary key from the Guardiann index.Removes the vector's references from all clusters it belongs to (primary and replicated), updates cluster metadata, and enqueues maintenance tasks if needed. The caller must provide the vector data to locate which clusters contain the vector.
- Parameters:
transaction- theTransactioncontext for all database operationsprimaryKey- the uniqueTupleprimary key of the vector to deletevector- theRealVectordata of the vector being deleted- Returns:
- a
CompletableFuturethat completes when the deletion is finished
-