Ivf Flat Package

View as Markdown

Go package: ivf_flat

Sources: go/ivf_flat

Types

IndexParams

1type IndexParams struct { ... }

Supplemental parameters to build IVF Flat Index

Source: go/ivf_flat/index_params.go:13

IvfFlatIndex

1type IvfFlatIndex struct { ... }

IVF Flat Index

Source: go/ivf_flat/ivf_flat.go:14

SearchParams

1type SearchParams struct { ... }

Source: go/ivf_flat/search_params.go:10

Functions

BuildIndex

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

Builds an IvfFlatIndex 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 - IvfFlatIndex to build

Source: go/ivf_flat/ivf_flat.go:38

CreateIndex

1func CreateIndex[T any](params *IndexParams, dataset *cuvs.Tensor[T]) (*IvfFlatIndex, error)

Creates a new empty IvfFlatIndex

Source: go/ivf_flat/ivf_flat.go:20

CreateIndexParams

1func CreateIndexParams() (*IndexParams, error)

Creates a new IndexParams

Source: go/ivf_flat/index_params.go:18

CreateSearchParams

1func CreateSearchParams() (*SearchParams, error)

Creates a new SearchParams

Source: go/ivf_flat/search_params.go:15

GetCenters

1func GetCenters[T any](index *IvfFlatIndex, centers *cuvs.Tensor[T]) error

Source: go/ivf_flat/ivf_flat.go:108

GetDim

1func GetDim(index *IvfFlatIndex) (dim int64, err error)

Source: go/ivf_flat/ivf_flat.go:93

GetNLists

1func GetNLists(index *IvfFlatIndex) (nlist int64, err error)

Source: go/ivf_flat/ivf_flat.go:78

SearchIndex

1func SearchIndex[T any](Resources cuvs.Resource, params *SearchParams, index *IvfFlatIndex, queries *cuvs.Tensor[T], neighbors *cuvs.Tensor[int64], distances *cuvs.Tensor[T]) error

Perform a Approximate Nearest Neighbors search on the Index

Arguments

  • Resources - Resources to use
  • params - Parameters to use in searching the index
  • index - IvfFlatIndex to search
  • 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

Source: go/ivf_flat/ivf_flat.go:66

Methods

IndexParams.Close

1func (p *IndexParams) Close() error

Destroys IndexParams

Source: go/ivf_flat/index_params.go:81

IndexParams.SetAddDataOnBuild

1func (p *IndexParams) SetAddDataOnBuild(add_data_on_build bool) (*IndexParams, error)

After training the coarse and fine quantizers, we will populate the index with the dataset if add_data_on_build == true, otherwise the index is left empty, and the extend method can be used to add new vectors to the index.

Source: go/ivf_flat/index_params.go:71

IndexParams.SetKMeansNIters

1func (p *IndexParams) SetKMeansNIters(kmeans_n_iters uint32) (*IndexParams, error)

The number of iterations searching for kmeans centers during index building.

Source: go/ivf_flat/index_params.go:54

IndexParams.SetKMeansTrainsetFraction

1func (p *IndexParams) SetKMeansTrainsetFraction(kmeans_trainset_fraction float64) (*IndexParams, error)

If kmeans_trainset_fraction is less than 1, then the dataset is subsampled, and only n_samples * kmeans_trainset_fraction rows are used for training.

Source: go/ivf_flat/index_params.go:62

IndexParams.SetMetric

1func (p *IndexParams) SetMetric(metric cuvs.Distance) (*IndexParams, error)

Distance Type to use for building the index

Source: go/ivf_flat/index_params.go:36

IndexParams.SetMetricArg

1func (p *IndexParams) SetMetricArg(metric_arg float32) (*IndexParams, error)

Metric argument for Minkowski distances - set to 2.0 if not applicable

Source: go/ivf_flat/index_params.go:48

IndexParams.SetNLists

1func (p *IndexParams) SetNLists(n_lists uint32) (*IndexParams, error)

The number of clusters used in the coarse quantizer.

Source: go/ivf_flat/index_params.go:30

IvfFlatIndex.Close

1func (index *IvfFlatIndex) Close() error

Destroys the IvfFlatIndex

Source: go/ivf_flat/ivf_flat.go:48

SearchParams.Close

1func (p *SearchParams) Close() error

Destroy SearchParams

Source: go/ivf_flat/search_params.go:33

SearchParams.SetNProbes

1func (p *SearchParams) SetNProbes(n_probes uint32) (*SearchParams, error)

The number of clusters to search.

Source: go/ivf_flat/search_params.go:27