XVector
xvec_hnsw_flat.h File Reference

HNSW-Flat (Hierarchical Navigable Small World) index interface. More...

Include dependency graph for xvec_hnsw_flat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  xvecHnswFlatDescriptor
 FAISS-free description of an HNSW-Flat index. More...
 

Typedefs

typedef struct xvecHnswFlatSearchTiming xvecHnswFlatSearchTiming
 
typedef struct xvecHnswFlatDescriptor xvecHnswFlatDescriptor
 FAISS-free description of an HNSW-Flat index. More...
 

Functions

xvecStatus xvecHnswFlatSearch (xvecExecutionContextTag *context, xvecHnswFlatIndexTag *indexHandle, xvecHnswFlatSearchQueryFloat32 *searchQuery, xvecBufferTag *resultsBufferHandle, xvecHnswFlatSearchTiming *outTiming)
 Performs an HNSW-Flat search. More...
 
xvecStatus xvecHnswFlatPrepareKernel (xvecExecutionContextTag *context)
 Warm-starts the HNSW-Flat search kernels on a context (optional). More...
 
xvecStatus xvecHnswFlatLoadIndexFromFaissFile (xvecExecutionContextTag *context, const char *indexFilePath, xvecHnswFlatIndexTag **outIndexHandle)
 Loads an HNSW-Flat index from a Faiss index file and uploads it to the device. More...
 
xvecStatus xvecHnswFlatLoadIndexFromDescriptor (xvecExecutionContextTag *context, const xvecHnswFlatDescriptor *descriptor, xvecHnswFlatIndexTag **outIndexHandle)
 Loads an HNSW-Flat index from a FAISS-free descriptor and uploads it to the device. More...
 
xvecStatus xvecHnswFlatDestroyIndex (xvecExecutionContextTag *context, xvecHnswFlatIndexTag *indexHandle)
 Destroys an HNSW-Flat index handle and releases its host-side data. More...
 

Detailed Description

HNSW-Flat (Hierarchical Navigable Small World) index interface.

This header provides the public API for loading, searching, and managing HNSW-Flat indices. HNSW is a graph-based approximate nearest neighbor algorithm that provides excellent search performance with a controllable accuracy/speed trade-off (efSearch).

Definition in file xvec_hnsw_flat.h.

Typedef Documentation

◆ xvecHnswFlatDescriptor

FAISS-free description of an HNSW-Flat index.

Fully describes the hierarchical graph so an index can be built with no FAISS dependency. The neighbor layout mirrors FAISS's HNSW storage: per node, a contiguous slice of neighbors holds all of that node's levels – level 0 first (M0 slots) then each higher level (M slots) – with empty slots set to -1. neighborOffsets gives each node's start into that flat array, so node i occupies [neighborOffsets[i], neighborOffsets[i + 1]), which must equal M0 + nodeLevels[i] * M.

◆ xvecHnswFlatSearchTiming

Definition at line 1 of file xvec_hnsw_flat.h.

Function Documentation

◆ xvecHnswFlatDestroyIndex()

xvecStatus xvecHnswFlatDestroyIndex ( xvecExecutionContextTag *  context,
xvecHnswFlatIndexTag *  indexHandle 
)

Destroys an HNSW-Flat index handle and releases its host-side data.

Note
Current limitation: device buffers allocated for the index remain owned by the execution context and are released by xvecDestroyContext(). Destroying the index does not yet reclaim its device memory.
See also
Index resource lifetime for destruction order and C++ wrapper behavior.
Parameters
[in]contextExecution context for device operations
[in]indexHandleHandle to the index to destroy
Returns
XVEC_SUCCESS on success, error code otherwise

◆ xvecHnswFlatLoadIndexFromDescriptor()

xvecStatus xvecHnswFlatLoadIndexFromDescriptor ( xvecExecutionContextTag *  context,
const xvecHnswFlatDescriptor *  descriptor,
xvecHnswFlatIndexTag **  outIndexHandle 
)

Loads an HNSW-Flat index from a FAISS-free descriptor and uploads it to the device.

Builds an HNSW-Flat index directly from caller-supplied arrays, with no FAISS dependency. This is the recommended way to construct an index from a custom or pre-extracted source (e.g. XFaiss). See xvecHnswFlatDescriptor for the required memory layout. The graph and vectors are packed and transferred to device memory once here, like xvecHnswFlatLoadIndexFromFaissFile.

Parameters
[in]contextExecution context for device operations
[in]descriptorFully-populated index descriptor (borrowed for the call)
[out]outIndexHandleReceives the loaded index handle; destroy with xvecHnswFlatDestroyIndex.
Returns
XVEC_SUCCESS on success, XVEC_ERROR_INVALID_PARAMETER for null/zero inputs, XVEC_ERROR_INVALID_HEADER if the layout is inconsistent (e.g. a node's neighbor span != M0 + level*M, or entryPointId out of range), or other error code otherwise

◆ xvecHnswFlatLoadIndexFromFaissFile()

xvecStatus xvecHnswFlatLoadIndexFromFaissFile ( xvecExecutionContextTag *  context,
const char *  indexFilePath,
xvecHnswFlatIndexTag **  outIndexHandle 
)

Loads an HNSW-Flat index from a Faiss index file and uploads it to the device.

The graph and vectors are packed and transferred to device memory once here (via the context), so subsequent xvecHnswFlatSearch calls reuse them without re-uploading.

Parameters
[in]contextExecution context for device operations
[in]indexFilePathPath to the Faiss (.faiss) index file
[out]outIndexHandleReceives the loaded index handle; destroy with xvecHnswFlatDestroyIndex.
Returns
XVEC_SUCCESS on success, error code otherwise

◆ xvecHnswFlatPrepareKernel()

xvecStatus xvecHnswFlatPrepareKernel ( xvecExecutionContextTag *  context)

Warm-starts the HNSW-Flat search kernels on a context (optional).

Pre-resolves the device kernel functions so the first xvecHnswFlatSearch() call does not pay the one-time module/function resolution cost. The single search kernel selects its layout (regular vs channel-striped gather) at runtime from the loaded index. xvecHnswFlatSearch() still resolves lazily if this is not called.

Fails with XVEC_ERROR_DEVICE_NOT_SUPPORTED on a device that has no search path, rather than reserving Subs for a search that would then be refused. Fails with XVEC_ERROR_PXL_JOB_CREATE_FAILED when the device has fewer free Subs than the Job needs, because another process or context holds them.

Parameters
[in]contextExecution context for device operations
Returns
XVEC_SUCCESS on success, error code otherwise

◆ xvecHnswFlatSearch()

xvecStatus xvecHnswFlatSearch ( xvecExecutionContextTag *  context,
xvecHnswFlatIndexTag *  indexHandle,
xvecHnswFlatSearchQueryFloat32 *  searchQuery,
xvecBufferTag *  resultsBufferHandle,
xvecHnswFlatSearchTiming *  outTiming 
)

Performs an HNSW-Flat search.

Searches the index for the top-K nearest neighbors of each query vector, navigating the hierarchical graph from the entry point.

Parameters
[in]contextExecution context for device operations
[in]indexHandleHandle to the HNSW-Flat index
[in]searchQueryQuery vectors + parameters (efSearch controls accuracy/speed)
[out]resultsBufferHandleCaller-preallocated buffer, size queryVectorCount * topK * sizeof(xvecHnswFlatSearchResultFloat32)
[out]outTimingPointer to receive timing information (can be NULL)
Note
efSearch and topK are currently capped at 256 (the device kernel's fixed-size candidate/result trackers). A search with efSearch > 256 or topK > 256 returns XVEC_ERROR_INVALID_PARAMETER; this cap is temporary.
Returns
XVEC_SUCCESS on success, XVEC_ERROR_OUT_OF_MEMORY_PXL when the per-search device buffers cannot be allocated (the search is not started), or other error code otherwise