XVector
xvec_knn_exact.h File Reference

Exact KNN (K-Nearest Neighbors) brute-force search interface. More...

#include "xvec_types.h"
Include dependency graph for xvec_knn_exact.h:

Go to the source code of this file.

Typedefs

typedef struct xvecKnnExactSearchTiming xvecKnnExactSearchTiming
 

Functions

xvecStatus xvecKnnExactLoadIndexFromRawVectors (xvecExecutionContextTag *context, const xvecFloat32 *vectors, xvecVectorIdType vectorCount, xvecDimensionType dimension, xvecDistanceType distanceType, xvecKnnExactIndexTag **outIndexHandle)
 Loads a KNN index from raw float32 vectors. More...
 
xvecStatus xvecKnnExactLoadIndexFromFaissFile (xvecExecutionContextTag *context, const char *indexFilePath, xvecKnnExactIndexTag **outIndexHandle)
 Loads a KNN index from a Faiss IndexFlat file. More...
 
xvecStatus xvecKnnExactDestroyIndex (xvecExecutionContextTag *context, xvecKnnExactIndexTag *indexHandle)
 Destroys a KNN index handle and releases its host-side data. More...
 
xvecStatus xvecKnnExactPrepareKernel (xvecExecutionContextTag *context)
 Pre-initializes PXL resources (Job, Module, Function) for KNN search. More...
 
xvecStatus xvecKnnExactSearch (xvecExecutionContextTag *context, xvecKnnExactIndexTag *indexHandle, xvecKnnExactSearchQueryFloat32 *searchQuery, xvecBufferTag *resultsBufferHandle, xvecKnnExactSearchTiming *outTiming)
 Performs a brute-force K-nearest neighbors search. More...
 

Detailed Description

Exact KNN (K-Nearest Neighbors) brute-force search interface.

This header provides the API for loading and searching datasets using exact brute-force nearest neighbor search. KNN computes distances between every query vector and every target vector, providing exact results.

The parallel execution mode is automatically selected:

  • When queryCount >= taskCount: queries are partitioned across workers
  • When queryCount < taskCount: the dataset is partitioned across workers

Definition in file xvec_knn_exact.h.

Typedef Documentation

◆ xvecKnnExactSearchTiming

Definition at line 1 of file xvec_knn_exact.h.

Function Documentation

◆ xvecKnnExactDestroyIndex()

xvecStatus xvecKnnExactDestroyIndex ( xvecExecutionContextTag *  context,
xvecKnnExactIndexTag *  indexHandle 
)

Destroys a KNN 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

◆ xvecKnnExactLoadIndexFromFaissFile()

xvecStatus xvecKnnExactLoadIndexFromFaissFile ( xvecExecutionContextTag *  context,
const char *  indexFilePath,
xvecKnnExactIndexTag **  outIndexHandle 
)

Loads a KNN index from a Faiss IndexFlat file.

Loads an IndexFlat (or IndexFlatL2/IndexFlatIP) from a Faiss .faiss file, extracting vectors and distance metric.

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 xvecKnnExactDestroyIndex.
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

◆ xvecKnnExactLoadIndexFromRawVectors()

xvecStatus xvecKnnExactLoadIndexFromRawVectors ( xvecExecutionContextTag *  context,
const xvecFloat32 *  vectors,
xvecVectorIdType  vectorCount,
xvecDimensionType  dimension,
xvecDistanceType  distanceType,
xvecKnnExactIndexTag **  outIndexHandle 
)

Loads a KNN index from raw float32 vectors.

This is the primary way to create a KNN index. The vectors are copied to device-accessible memory for accelerated search.

Parameters
[in]contextExecution context for device operations
[in]vectorsPointer to row-major float32 vectors [vectorCount * dimension]
[in]vectorCountNumber of vectors in the dataset
[in]dimensionDimension of each vector
[in]distanceTypeDistance metric (L2 or DOT_PRODUCT)
[out]outIndexHandlePointer to receive the handle to the loaded index. The caller is responsible for destroying this index using xvecKnnExactDestroyIndex.
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

◆ xvecKnnExactPrepareKernel()

xvecStatus xvecKnnExactPrepareKernel ( xvecExecutionContextTag *  context)

Pre-initializes PXL resources (Job, Module, Function) for KNN 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.

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

◆ xvecKnnExactSearch()

xvecStatus xvecKnnExactSearch ( xvecExecutionContextTag *  context,
xvecKnnExactIndexTag *  indexHandle,
xvecKnnExactSearchQueryFloat32 *  searchQuery,
xvecBufferTag *  resultsBufferHandle,
xvecKnnExactSearchTiming *  outTiming 
)

Performs a brute-force K-nearest neighbors search.

Computes exact distances between every query vector and every target vector in the index, returning the top-K nearest neighbors for each query.

The parallel execution mode is automatically selected based on the number of queries and the device task count.

Parameters
[in]contextExecution context for device operations
[in]indexHandleHandle to the KNN index containing target vectors
[in]searchQuerySearch query parameters (queries, topK)
[out]resultsBufferHandleBuffer to receive search results. Must be pre-allocated with size: queryVectorCount * topK * sizeof(xvecKnnExactSearchResultFloat32)
[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