index

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package index provides interfaces and types for vector search indexes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistanceFunc

type DistanceFunc func(v1, v2 []float32) (float32, error)

DistanceFunc represents a function for calculating the distance between two vectors

func NewDistanceFunc

func NewDistanceFunc(distanceType DistanceType) DistanceFunc

NewDistanceFunc returns a distance function based on the specified distance type.

type DistanceType

type DistanceType int

DistanceType represents the type of distance function used for calculating distances between vectors.

const (
	DistanceTypeSquaredL2 DistanceType = iota
	DistanceTypeCosineSimilarity
)

Constants representing different types of distance functions.

func (DistanceType) String

func (dt DistanceType) String() string

String returns a string representation of the DistanceType.

type ErrDimensionMismatch

type ErrDimensionMismatch struct {
	Expected int // Expected dimensions
	Actual   int // Actual dimensions
}

ErrDimensionMismatch is a named error type for dimension mismatch

func (*ErrDimensionMismatch) Error

func (e *ErrDimensionMismatch) Error() string

Error returns the error message for dimension mismatch

type Index

type Index interface {
	gob.GobEncoder
	gob.GobDecoder

	// Insert adds a vector to the index
	Insert(v []float32) (uint32, error)

	// KNNSearch performs a K-nearest neighbor search
	KNNSearch(q []float32, k int, efSearch int, filter func(id uint32) bool) ([]SearchResult, error)

	// BruteSearch performs a brute-force search
	BruteSearch(query []float32, k int, filter func(id uint32) bool) ([]SearchResult, error)

	// Stats prints statistics about the index
	Stats()
}

Index represents an index for vector search

type SearchResult added in v0.0.10

type SearchResult struct {
	// ID is the identifier of the search result.
	ID uint32

	// Distance is the distance between the query vector and the result vector.
	Distance float32
}

SearchResult represents a search result.

Directories

Path Synopsis
Package flat provides an implementation of a flat index for vector storage and search.
Package flat provides an implementation of a flat index for vector storage and search.
Package hnsw implements the Hierarchical Navigable Small World (HNSW) graph for approximate nearest neighbor search.
Package hnsw implements the Hierarchical Navigable Small World (HNSW) graph for approximate nearest neighbor search.

Jump to

Keyboard shortcuts

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