XVector
xvec_hnsw_flat.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2026 XCENA Inc.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
27 #pragma once
28 
29 #include "xvector/xvec_types.h"
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
36 
37  // =============================================================================
38  // Search APIs
39  // =============================================================================
40 
61  xvecStatus xvecHnswFlatSearch(xvecExecutionContextTag* context,
62  xvecHnswFlatIndexTag* indexHandle,
63  xvecHnswFlatSearchQueryFloat32* searchQuery,
64  xvecBufferTag* resultsBufferHandle,
65  xvecHnswFlatSearchTiming* outTiming);
66 
84  xvecStatus xvecHnswFlatPrepareKernel(xvecExecutionContextTag* context);
85 
86  // =============================================================================
87  // Index Loading and Management
88  // =============================================================================
89 
104  xvecStatus xvecHnswFlatLoadIndexFromFaissFile(xvecExecutionContextTag* context,
105  const char* indexFilePath,
106  xvecHnswFlatIndexTag** outIndexHandle);
107 
119  typedef struct xvecHnswFlatDescriptor
120  {
124  uint32_t M;
125  uint32_t M0;
126  uint32_t maxLevel;
129  const uint32_t* nodeLevels;
130  const uint64_t* neighborOffsets;
134 
154  xvecStatus xvecHnswFlatLoadIndexFromDescriptor(xvecExecutionContextTag* context,
155  const xvecHnswFlatDescriptor* descriptor,
156  xvecHnswFlatIndexTag** outIndexHandle);
157 
171  xvecStatus xvecHnswFlatDestroyIndex(xvecExecutionContextTag* context,
172  xvecHnswFlatIndexTag* indexHandle);
173 
174 #ifdef __cplusplus
175 }
176 #endif
FAISS-free description of an HNSW-Flat index.
const uint64_t * neighborOffsets
Per-node start offset into neighbors [numVectors + 1].
uint32_t M
Max neighbors per node at levels >= 1.
uint32_t maxLevel
Highest level in the hierarchy.
xvecVectorIdType numVectors
Total number of graph nodes / vectors.
const uint32_t * nodeLevels
Top level (0-based) of each node [numVectors].
const xvecVectorIdType * neighbors
Flat neighbor ids; per node level 0 (M0 slots) then each higher level (M slots); empty slots are -1.
xvecDistanceType distanceType
Distance metric the graph was built under.
uint32_t M0
Max neighbors per node at level 0 (usually 2*M).
const xvecFloat32 * vectors
Vectors, row-major by node id [numVectors * dimension].
xvecVectorIdType entryPointId
Graph entry-point node id; must be < numVectors.
xvecDimensionType dimension
Dimension of each vector (d).
Search query parameters for HNSW-Flat index search.
Definition: xvec_types.h:298
struct xvecHnswFlatSearchTiming xvecHnswFlatSearchTiming
xvecStatus xvecHnswFlatPrepareKernel(xvecExecutionContextTag *context)
Warm-starts the HNSW-Flat search kernels on a context (optional).
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.
struct xvecHnswFlatDescriptor xvecHnswFlatDescriptor
FAISS-free description of an HNSW-Flat index.
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.
xvecStatus xvecHnswFlatSearch(xvecExecutionContextTag *context, xvecHnswFlatIndexTag *indexHandle, xvecHnswFlatSearchQueryFloat32 *searchQuery, xvecBufferTag *resultsBufferHandle, xvecHnswFlatSearchTiming *outTiming)
Performs an HNSW-Flat search.
xvecStatus xvecHnswFlatDestroyIndex(xvecExecutionContextTag *context, xvecHnswFlatIndexTag *indexHandle)
Destroys an HNSW-Flat index handle and releases its host-side data.
Core types, enums, and structures for the XVector library.
uint32_t xvecDimensionType
Type for vector dimension.
Definition: xvec_types.h:194
xvecStatus
Status codes returned by XVector API functions.
Definition: xvec_types.h:133
xvecDistanceType
Distance/similarity metrics for vector search.
Definition: xvec_types.h:172
float xvecFloat32
32-bit floating point type for vector components.
Definition: xvec_types.h:111
uint64_t xvecVectorIdType
Type for vector identifiers.
Definition: xvec_types.h:209