index

package
v0.0.0-...-d52f0d6 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultBuckets = 10.0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DataPoint

type DataPoint[T comparable] struct {
	ID        T
	Embedding []float64
}

func NewDataPoint

func NewDataPoint[T comparable](id T, embedding []float64) *DataPoint[T]

type DistanceMeasure

type DistanceMeasure interface {
	CalcDistance(v1, v2 []float64) float64
}

func NewCosineDistanceMeasure

func NewCosineDistanceMeasure() DistanceMeasure

func NewEuclideanDistanceMeasure

func NewEuclideanDistanceMeasure() DistanceMeasure

type SearchResult

type SearchResult[T comparable] struct {
	ID       T
	Distance float64
	Vector   []float64
}

type VectorIndex

type VectorIndex[T comparable] struct {
	NumberOfRoots        int
	NumberOfDimensions   int
	MaxItemsPerLeafNode  int
	Roots                []*treeNode[T]
	IDToTreeNodeMapping  map[string]*treeNode[T]
	IDToDataPointMapping map[T]*DataPoint[T]
	DataPoints           []*DataPoint[T]
	DistanceMeasure      DistanceMeasure
	Mutex                *sync.Mutex
}

T is the type of the identifier used to identify data points

func NewVectorIndex

func NewVectorIndex[T comparable](numberOfRoots int, numberOfDimensions int, maxIetmsPerLeafNode int, dataPoints []*DataPoint[T], distanceMeasure DistanceMeasure) (*VectorIndex[T], error)

func (*VectorIndex[T]) AddDataPoint

func (vi *VectorIndex[T]) AddDataPoint(dataPoint *DataPoint[T]) error

func (*VectorIndex[T]) Build

func (vi *VectorIndex[T]) Build()

func (*VectorIndex[T]) GetNormalVector

func (vi *VectorIndex[T]) GetNormalVector(dataPoints []*DataPoint[T]) []float64

GetNormalVector calculates the normal vector of a hyperplane that separates the two clusters of data points. nolint: funlen, gocognit, cyclop, gosec

func (*VectorIndex[T]) SearchByItem

func (vi *VectorIndex[T]) SearchByItem() ([]int, error)

func (*VectorIndex[T]) SearchByVector

func (vi *VectorIndex[T]) SearchByVector(input []float64, searchNum int, numberOfBuckets float64) (*[]SearchResult[T], error)

nolint: funlen, cyclop

Jump to

Keyboard shortcuts

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