XVector
xvec_ivf_flat.h File Reference

IVF-Flat (Inverted File with Flat vectors) index interface. More...

#include "xvec_types.h"
Include dependency graph for xvec_ivf_flat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  xvecIvfFlatDescriptor
 FAISS-free description of an IVF-Flat index. More...
 

Typedefs

typedef struct xvecIvfFlatSearchTiming xvecIvfFlatSearchTiming
 
typedef struct xvecIvfFlatDescriptor xvecIvfFlatDescriptor
 FAISS-free description of an IVF-Flat index. More...
 

Functions

xvecStatus xvecIvfFlatLoadIndexFromFaissFile (xvecExecutionContextTag *context, const char *indexFilePath, xvecIvfFlatIndexTag **outIndexHandle)
 Loads an IVF-Flat index from a Faiss index file. More...
 
xvecStatus xvecIvfFlatLoadIndexFromDescriptor (xvecExecutionContextTag *context, const xvecIvfFlatDescriptor *descriptor, xvecIvfFlatIndexTag **outIndexHandle)
 Loads an IVF-Flat index from a FAISS-free descriptor. More...
 
xvecStatus xvecIvfFlatDestroyIndex (xvecExecutionContextTag *context, xvecIvfFlatIndexTag *indexHandle)
 Destroys an IVF-Flat index handle and releases its host-side data. More...
 
xvecStatus xvecIvfFlatPrepareKernel (xvecExecutionContextTag *context)
 Pre-initializes PXL resources (Job, Module, Function) for IVF-Flat search. More...
 
xvecStatus xvecIvfFlatSearchFineSearchOnly (xvecExecutionContextTag *context, xvecIvfFlatIndexTag *indexHandle, xvecIvfFlatFineSearchQueryFloat32 *fineSearchQuery, xvecBufferTag *resultsBufferHandle, xvecIvfFlatSearchTiming *outTiming)
 Performs an IVF-Flat fine search only (skips coarse search). More...
 

Detailed Description

IVF-Flat (Inverted File with Flat vectors) index interface.

This header provides the API for loading, saving, and searching IVF-Flat indices. IVF-Flat uses inverted file indexing with exact distance computation within clusters, providing a good balance of speed and accuracy.

See Optional IVF-Flat L2 optimization for QUERY_FIXED L2 searches, configured through xvecSetContextProperty().

Definition in file xvec_ivf_flat.h.

Typedef Documentation

◆ xvecIvfFlatDescriptor

FAISS-free description of an IVF-Flat index.

Fully describes an IVF-Flat index using plain C arrays, with no dependency on FAISS types or ABI. Vectors are grouped by cluster: the first listSizes[0] vectors belong to cluster 0, the next listSizes[1] to cluster 1, and so on.

All pointers are borrowed for the duration of the load call only; the caller retains ownership and may free them once the call returns.

◆ xvecIvfFlatSearchTiming

Definition at line 1 of file xvec_ivf_flat.h.

Function Documentation

◆ xvecIvfFlatDestroyIndex()

xvecStatus xvecIvfFlatDestroyIndex ( xvecExecutionContextTag *  context,
xvecIvfFlatIndexTag *  indexHandle 
)

Destroys an IVF-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

◆ xvecIvfFlatLoadIndexFromDescriptor()

xvecStatus xvecIvfFlatLoadIndexFromDescriptor ( xvecExecutionContextTag *  context,
const xvecIvfFlatDescriptor *  descriptor,
xvecIvfFlatIndexTag **  outIndexHandle 
)

Loads an IVF-Flat index from a FAISS-free descriptor.

Builds an IVF-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. See xvecIvfFlatDescriptor for the required memory layout.

Parameters
[in]contextExecution context for device operations
[in]descriptorFully-populated index descriptor (borrowed for the call)
[out]outIndexHandlePointer to receive the handle to the loaded index. The caller is responsible for destroying this index using xvecIvfFlatDestroyIndex.
Returns
XVEC_SUCCESS on success, XVEC_ERROR_INVALID_PARAMETER for null/zero inputs, XVEC_ERROR_INVALID_HEADER if the layout is inconsistent (e.g. listSizes do not sum to numVectors), XVEC_ERROR_OUT_OF_MEMORY_PXL when the device memory for the index cannot be allocated (for example while another process holds most of the card's memory), or other error code otherwise

◆ xvecIvfFlatLoadIndexFromFaissFile()

xvecStatus xvecIvfFlatLoadIndexFromFaissFile ( xvecExecutionContextTag *  context,
const char *  indexFilePath,
xvecIvfFlatIndexTag **  outIndexHandle 
)

Loads an IVF-Flat index from a Faiss index file.

Loads an IndexIVFFlat from a Faiss .faiss file, extracting vectors, cluster centroids, and inverted list structure.

Parameters
[in]contextExecution context for device operations
[in]indexFilePathPath to the Faiss index file (.faiss)
[out]outIndexHandlePointer to receive the handle to the loaded index. The caller is responsible for destroying this index using xvecIvfFlatDestroyIndex.
Returns
XVEC_SUCCESS on success, XVEC_ERROR_OUT_OF_MEMORY_PXL when the device memory for the index cannot be allocated (for example while another process holds most of the card's memory), or other error code otherwise

◆ xvecIvfFlatPrepareKernel()

xvecStatus xvecIvfFlatPrepareKernel ( xvecExecutionContextTag *  context)

Pre-initializes PXL resources (Job, Module, Function) for IVF-Flat search.

Eagerly creates and caches the PXL Job and Function objects so that the first search call does not pay the lazy-initialization cost. Uses the same Sub count a search would: the "numSub" property if set, else whatever the device reports. 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. Safe to call more than once; subsequent calls are no-ops if numSub has not changed.

Parameters
[in]contextExecution context. Setting "numSub" is optional.
Returns
XVEC_SUCCESS on success, error code otherwise

◆ xvecIvfFlatSearchFineSearchOnly()

xvecStatus xvecIvfFlatSearchFineSearchOnly ( xvecExecutionContextTag *  context,
xvecIvfFlatIndexTag *  indexHandle,
xvecIvfFlatFineSearchQueryFloat32 *  fineSearchQuery,
xvecBufferTag *  resultsBufferHandle,
xvecIvfFlatSearchTiming *  outTiming 
)

Performs an IVF-Flat fine search only (skips coarse search).

This function performs only the fine search phase using pre-computed nearest cluster IDs. Use this when the coarse search has already been performed externally (e.g., by FAISS) and only the fine search needs to be offloaded to XVector.

The typical use case is XFaiss integration where:

  1. FAISS performs coarse search on CPU to find nearest clusters
  2. XVector performs fine search on accelerator using the cluster IDs from step 1
See also
Optional IVF-Flat L2 optimization for QUERY_FIXED L2 searches.
Search scores for result ordering and unfilled result slots.
Parameters
[in]contextExecution context for device operations
[in]indexHandleHandle to the IVF-Flat index containing inverted lists
[in]fineSearchQueryFine search query containing query vectors and pre-computed nearest cluster IDs (from external coarse search)
[out]resultsBufferHandleBuffer to receive search results. Must be pre-allocated with size: queryVectorCount * topK * sizeof(xvecIvfFlatSearchResultFloat32)
[out]outTimingPointer to receive timing information (can be NULL)
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