search

package
v0.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTestSize = 1000
	DefaultMaxIter  = 100
)

Variables

This section is empty.

Functions

func EstimateHNSWBuilderComplexity added in v0.4.5

func EstimateHNSWBuilderComplexity(dataSize, trials int) int

func EstimateIVFBuilderComplexity added in v0.4.5

func EstimateIVFBuilderComplexity(num, numEpoch int) int

Types

type Bruteforce

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

Bruteforce is a naive implementation of vector index.

func NewBruteforce

func NewBruteforce(vectors []Vector) *Bruteforce

NewBruteforce creates a Bruteforce vector index.

func (*Bruteforce) Build

func (b *Bruteforce) Build()

Build a vector index on data.

func (*Bruteforce) MultiSearch

func (b *Bruteforce) MultiSearch(q Vector, terms []string, n int, prune0 bool) (values map[string][]int32, scores map[string][]float32)

func (*Bruteforce) Search

func (b *Bruteforce) Search(q Vector, n int, prune0 bool) (values []int32, scores []float32)

Search top-k similar vectors.

type CentroidVector added in v0.4.2

type CentroidVector interface {
	Distance(vector Vector) float32
}

type DenseVector

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

func NewDenseVector

func NewDenseVector(data []float32, terms []string, isHidden bool) *DenseVector

func (*DenseVector) Centroid added in v0.4.2

func (v *DenseVector) Centroid(_ []Vector, _ []int32) CentroidVector

func (*DenseVector) Distance

func (v *DenseVector) Distance(vector Vector) float32

func (*DenseVector) IsHidden

func (v *DenseVector) IsHidden() bool

func (*DenseVector) Terms

func (v *DenseVector) Terms() []string

type DictionaryCentroidVector added in v0.4.2

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

func (*DictionaryCentroidVector) Distance added in v0.4.2

func (v *DictionaryCentroidVector) Distance(vector Vector) float32

type DictionaryVector

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

func NewDictionaryVector

func NewDictionaryVector(indices []int32, values []float32, terms []string, isHidden bool) *DictionaryVector

func (DictionaryVector) Centroid added in v0.4.2

func (v DictionaryVector) Centroid(vectors []Vector, indices []int32) CentroidVector

func (*DictionaryVector) Distance

func (v *DictionaryVector) Distance(vector Vector) float32

func (*DictionaryVector) Dot

func (v *DictionaryVector) Dot(vector *DictionaryVector) (float32, float32)

func (*DictionaryVector) IsHidden

func (v *DictionaryVector) IsHidden() bool

func (*DictionaryVector) Terms

func (v *DictionaryVector) Terms() []string

type HNSW

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

HNSW is a vector index based on Hierarchical Navigable Small Worlds.

func NewHNSW

func NewHNSW(vectors []Vector, configs ...HNSWConfig) *HNSW

NewHNSW builds a vector index based on Hierarchical Navigable Small Worlds.

func (*HNSW) Build

func (h *HNSW) Build()

Build a vector index on data.

func (*HNSW) MultiSearch

func (h *HNSW) MultiSearch(q Vector, terms []string, n int, prune0 bool) (values map[string][]int32, scores map[string][]float32)

func (*HNSW) Search

func (h *HNSW) Search(q Vector, n int, prune0 bool) (values []int32, scores []float32)

Search a vector in Hierarchical Navigable Small Worlds.

type HNSWBuilder

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

func NewHNSWBuilder

func NewHNSWBuilder(data []Vector, k, numJobs int) *HNSWBuilder

func (*HNSWBuilder) Build

func (b *HNSWBuilder) Build(recall float32, trials int, prune0 bool, t *task.Task) (idx *HNSW, score float32)

type HNSWConfig

type HNSWConfig func(*HNSW)

HNSWConfig is the configuration function for HNSW.

func SetEFConstruction

func SetEFConstruction(efConstruction int) HNSWConfig

SetEFConstruction sets efConstruction in HNSW.

func SetHNSWNumJobs

func SetHNSWNumJobs(numJobs int) HNSWConfig

SetHNSWNumJobs sets the number of jobs for building index.

func SetMaxConnection

func SetMaxConnection(maxConnection int) HNSWConfig

SetMaxConnection sets the number of connections in HNSW.

type IVF

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

func NewIVF

func NewIVF(vectors []Vector, configs ...IVFConfig) *IVF

func (*IVF) Build

func (idx *IVF) Build()

func (*IVF) MultiSearch

func (idx *IVF) MultiSearch(q Vector, terms []string, n int, prune0 bool) (values map[string][]int32, scores map[string][]float32)

func (*IVF) Search

func (idx *IVF) Search(q Vector, n int, prune0 bool) (values []int32, scores []float32)

type IVFBuilder

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

func NewIVFBuilder

func NewIVFBuilder(data []Vector, k int, configs ...IVFConfig) *IVFBuilder

func (*IVFBuilder) Build

func (b *IVFBuilder) Build(recall float32, numEpoch int, prune0 bool, t *task.Task) (idx *IVF, score float32)

type IVFConfig

type IVFConfig func(ivf *IVF)

func SetClusterErrorRate

func SetClusterErrorRate(errorRate float32) IVFConfig

func SetIVFNumJobs

func SetIVFNumJobs(numJobs int) IVFConfig

func SetMaxIteration added in v0.4.5

func SetMaxIteration(maxIter int) IVFConfig

func SetNumProbe

func SetNumProbe(numProbe int) IVFConfig

type Vector

type Vector interface {
	Distance(vector Vector) float32
	Terms() []string
	IsHidden() bool
	Centroid(vectors []Vector, indices []int32) CentroidVector
}

type VectorIndex

type VectorIndex interface {
	Build()
	Search(q Vector, n int, prune0 bool) ([]int32, []float32)
	MultiSearch(q Vector, terms []string, n int, prune0 bool) (map[string][]int32, map[string][]float32)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL