Skip to navigation

Cagra Package

View as Markdown

Go package: cagra

Sources: go/cagra

Constants

BuildAlgo Constants

const (
IvfPq BuildAlgo = iota
NnDescent
AutoSelect
)

Source: go/cagra/index_params.go:18

HashmapMode Constants

const (
HashmapModeHash HashmapMode = iota
HashmapModeSmall
HashmapModeAuto
)

Source: go/cagra/search_params.go:28

SearchAlgo Constants

const (
SearchAlgoSingleCta SearchAlgo = iota
SearchAlgoMultiCta
SearchAlgoMultiKernel
SearchAlgoAuto
)

Source: go/cagra/search_params.go:19

Types

BuildAlgo

type BuildAlgo int

Source: go/cagra/index_params.go:16

CagraIndex

type CagraIndex struct {
// contains filtered or unexported fields
}

Cagra ANN Index

Source: go/cagra/cagra.go:14

ExtendParams

type ExtendParams struct {
// contains filtered or unexported fields
}

Parameters to extend CAGRA Index

Source: go/cagra/extend_params.go:11

HashmapMode

type HashmapMode int

Source: go/cagra/search_params.go:26

IndexParams

type IndexParams struct {
// contains filtered or unexported fields
}

Source: go/cagra/index_params.go:12

PaddedDataset

type PaddedDataset struct {
// contains filtered or unexported fields
}

Owning padded dataset handle for explicit CAGRA dataset management.

Source: go/cagra/cagra.go:20

PaddedDatasetHandle

type PaddedDatasetHandle interface {
datasetHandle() C.cuvsDataset_t
}

PaddedDatasetHandle is an owning padded dataset or non-owning padded dataset view.

Source: go/cagra/cagra.go:25

PaddedDatasetView

type PaddedDatasetView struct {
// contains filtered or unexported fields
}

Non-owning padded dataset view handle.

Source: go/cagra/cagra.go:30

SearchAlgo

type SearchAlgo int

Source: go/cagra/search_params.go:17

SearchParams

type SearchParams struct {
// contains filtered or unexported fields
}

Supplemental parameters to search CAGRA Index

Source: go/cagra/search_params.go:13

StandardDatasetView

type StandardDatasetView struct {
// contains filtered or unexported fields
}

Non-owning standard dataset view handle.

Source: go/cagra/cagra.go:35

Functions

BuildIndex

func BuildIndex[T any](Resources cuvs.Resource, params *IndexParams, dataset *cuvs.Tensor[T], index *CagraIndex) error

Builds a new Index from the dataset for efficient search.

Arguments

  • Resources - Resources to use
  • params - Parameters for building the index
  • dataset - A row-major Tensor on either the host or device to index
  • index - CagraIndex to build

Source: go/cagra/cagra.go:226

CreateExtendParams

func CreateExtendParams() (*ExtendParams, error)

Creates a new ExtendParams

Source: go/cagra/extend_params.go:16

CreateIndex

func CreateIndex() (*CagraIndex, error)

Creates a new empty Cagra Index

Source: go/cagra/cagra.go:208

CreateIndexParams

func CreateIndexParams() (*IndexParams, error)

Creates a new IndexParams

Source: go/cagra/index_params.go:31

CreateSearchParams

func CreateSearchParams() (*SearchParams, error)

Creates a new SearchParams

Source: go/cagra/search_params.go:35

ExtendIndex

func ExtendIndex(Resources cuvs.Resource, params *ExtendParams, extended_dataset PaddedDatasetHandle, newStartRow int64, index *CagraIndex) error

Extends the index with a caller-owned pre-concatenated padded dataset.

Arguments

  • Resources - Resources to use
  • params - Parameters for extending the index
  • extended_dataset - Caller-owned padded dataset already containing old || new rows
  • newStartRow - Row index where the additional vectors begin (must equal current index size)
  • index - CagraIndex to extend

Source: go/cagra/cagra.go:277

MakePaddedDataset

func MakePaddedDataset[T any](Resources cuvs.Resource, dataset *cuvs.Tensor[T]) (*PaddedDataset, error)

MakePaddedDataset creates an owning padded dataset from a tensor. Memory residency is inferred from the tensor device type.

Source: go/cagra/cagra.go:84

MakePaddedDatasetView

func MakePaddedDatasetView[T any](Resources cuvs.Resource, dataset *cuvs.Tensor[T]) (*PaddedDatasetView, error)

MakePaddedDatasetView creates a non-owning padded dataset view from a tensor. Memory residency is inferred from the tensor.

Source: go/cagra/cagra.go:109

MakeStandardDatasetView

func MakeStandardDatasetView[T any](Resources cuvs.Resource, dataset *cuvs.Tensor[T]) (*StandardDatasetView, error)

MakeStandardDatasetView creates a non-owning standard dataset view from a tensor. Memory residency is inferred from the tensor.

Source: go/cagra/cagra.go:159

SearchIndex

func SearchIndex[T any](Resources cuvs.Resource, params *SearchParams, index *CagraIndex, queries *cuvs.Tensor[T], neighbors *cuvs.Tensor[uint32], distances *cuvs.Tensor[T], allowList []uint32) error

Perform a Approximate Nearest Neighbors search on the Index

Arguments

  • Resources - Resources to use
  • params - Parameters to use in searching the index
  • queries - A tensor in device memory to query for
  • neighbors - Tensor in device memory that receives the indices of the nearest neighbors
  • distances - Tensor in device memory that receives the distances of the nearest neighbors
  • allowList - List of indices to allow in the search, if nil, no filtering is applied

Source: go/cagra/cagra.go:317

UpdateDataset

func UpdateDataset(Resources cuvs.Resource, paddedDataset PaddedDatasetHandle, index *CagraIndex) error

UpdateDataset updates any CAGRA index layout with a caller-provided padded dataset or view and leaves the same handle search-ready.

Source: go/cagra/cagra.go:189

Methods

CagraIndex.Close

func (index *CagraIndex) Close() error

Destroys the Cagra Index

Source: go/cagra/cagra.go:299

ExtendParams.Close

func (p *ExtendParams) Close() error

Source: go/cagra/extend_params.go:40

ExtendParams.SetMaxChunkSize

func (p *ExtendParams) SetMaxChunkSize(max_chunk_size uint32) (*ExtendParams, error)

The additional dataset is divided into chunks and added to the graph. This is the knob to adjust the tradeoff between the recall and operation throughput. Large chunk sizes can result in high throughput, but use more working memory (O(max_chunk_size*degree^2)). This can also degrade recall because no edges are added between the nodes in the same chunk. Auto select when 0.

Source: go/cagra/extend_params.go:35

IndexParams.Close

func (p *IndexParams) Close() error

Destroys IndexParams

Source: go/cagra/index_params.go:77

IndexParams.SetBuildAlgo

func (p *IndexParams) SetBuildAlgo(build_algo BuildAlgo) (*IndexParams, error)

ANN algorithm to build knn graph

Source: go/cagra/index_params.go:58

IndexParams.SetGraphDegree

func (p *IndexParams) SetGraphDegree(intermediate_graph_degree uintptr) (*IndexParams, error)

Degree of output graph

Source: go/cagra/index_params.go:51

IndexParams.SetIntermediateGraphDegree

func (p *IndexParams) SetIntermediateGraphDegree(intermediate_graph_degree uintptr) (*IndexParams, error)

Degree of input graph for pruning

Source: go/cagra/index_params.go:45

IndexParams.SetNNDescentNiter

func (p *IndexParams) SetNNDescentNiter(nn_descent_niter uint32) (*IndexParams, error)

Number of iterations to run if building with NN_DESCENT

Source: go/cagra/index_params.go:70

PaddedDataset.Close

func (dataset *PaddedDataset) Close() error

Destroys an owning padded dataset handle.

Source: go/cagra/cagra.go:132

PaddedDatasetView.Close

func (view *PaddedDatasetView) Close() error

Destroys a padded dataset view handle.

Source: go/cagra/cagra.go:145

SearchParams.Close

func (p *SearchParams) Close() error

Destroys SearchParams

Source: go/cagra/search_params.go:157

SearchParams.SetAlgo

func (p *SearchParams) SetAlgo(algo SearchAlgo) (*SearchParams, error)

Which search implementation to use.

Source: go/cagra/search_params.go:67

SearchParams.SetHashmapMaxFillRate

func (p *SearchParams) SetHashmapMaxFillRate(hashmap_max_fill_rate float32) (*SearchParams, error)

Upper limit of hashmap fill rate. More than 0.1, less than 0.9.

Source: go/cagra/search_params.go:139

SearchParams.SetHashmapMinBitlen

func (p *SearchParams) SetHashmapMinBitlen(hashmap_min_bitlen uintptr) (*SearchParams, error)

Lower limit of hashmap bit length. More than 8.

Source: go/cagra/search_params.go:133

SearchParams.SetHashmapMode

func (p *SearchParams) SetHashmapMode(hashmap_mode HashmapMode) (*SearchParams, error)

Hashmap type. Auto selection when AUTO.

Source: go/cagra/search_params.go:113

SearchParams.SetItopkSize

func (p *SearchParams) SetItopkSize(itopk_size uintptr) (*SearchParams, error)

Number of intermediate search results retained during the search. This is the main knob to adjust trade off between accuracy and search speed. Higher values improve the search accuracy

Source: go/cagra/search_params.go:55

SearchParams.SetMaxIterations

func (p *SearchParams) SetMaxIterations(max_iterations uintptr) (*SearchParams, error)

Upper limit of search iterations. Auto select when 0.

Source: go/cagra/search_params.go:61

SearchParams.SetMaxQueries

func (p *SearchParams) SetMaxQueries(max_queries uintptr) (*SearchParams, error)

Maximum number of queries to search at the same time (batch size). Auto select when 0

Source: go/cagra/search_params.go:47

SearchParams.SetMinIterations

func (p *SearchParams) SetMinIterations(min_iterations uintptr) (*SearchParams, error)

Lower limit of search iterations.

Source: go/cagra/search_params.go:95

SearchParams.SetNumRandomSamplings

func (p *SearchParams) SetNumRandomSamplings(num_random_samplings uint32) (*SearchParams, error)

Number of iterations of initial random seed node selection. 1 or more.

Source: go/cagra/search_params.go:145

SearchParams.SetRandXorMask

func (p *SearchParams) SetRandXorMask(rand_xor_mask uint64) (*SearchParams, error)

Bit mask used for initial random seed node selection.

Source: go/cagra/search_params.go:151

SearchParams.SetSearchWidth

func (p *SearchParams) SetSearchWidth(search_width uintptr) (*SearchParams, error)

How many nodes to search at once. Auto select when 0.

Source: go/cagra/search_params.go:101

SearchParams.SetTeamSize

func (p *SearchParams) SetTeamSize(team_size uintptr) (*SearchParams, error)

Number of threads used to calculate a single distance. 4, 8, 16, or 32.

Source: go/cagra/search_params.go:89

SearchParams.SetThreadBlockSize

func (p *SearchParams) SetThreadBlockSize(thread_block_size uintptr) (*SearchParams, error)

Thread block size. 0, 64, 128, 256, 512, 1024. Auto selection when 0.

Source: go/cagra/search_params.go:107

StandardDatasetView.Close

func (view *StandardDatasetView) Close() error

Destroys a standard dataset view handle.

Source: go/cagra/cagra.go:175