hnsw

package
v25.0.0-split-vector3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Euclidean          = "euclidean"
	Cosine             = "cosine"
	DotProd            = "dotproduct"
	EmptyHNSWTreeError = "HNSW tree has no elements"
	VecKeyword         = "__vector_"

	VecEntry             = "__vector_entry"
	VecDead              = "__vector_dead"
	VectorIndexMaxLevels = 5
	EfConstruction       = 16
	EfSearch             = 12

	// ByteData indicates the key stores data.
	ByteData = byte(0x00)
	// DefaultPrefix is the prefix used for data, index and reverse keys so that relative
	DefaultPrefix = byte(0x00)
	// NsSeparator is the separator between the namespace and attribute.
	NsSeparator = "-"
)
View Source
const (
	ExponentOpt       string = "exponent"
	MaxLevelsOpt      string = "maxLevels"
	EfConstructionOpt string = "efConstruction"
	EfSearchOpt       string = "efSearch"
	MetricOpt         string = "metric"
	Hnsw              string = "hnsw"
)

Variables

This section is empty.

Functions

func AssertTrue

func AssertTrue(b bool)

AssertTrue asserts that b is true. Otherwise, it would log fatal.

func BytesToUint64

func BytesToUint64(bytes []byte) uint64

func Check

func Check(err error)

Check logs fatal if err != nil.

func ConcatStrings

func ConcatStrings(strs ...string) string

func CreateFactory

func CreateFactory[T c.Float](floatBits int) index.IndexFactory[T]

CreateFactory creates an instance of the private struct persistentIndexFactory. NOTE: if T and floatBits do not match in # of bits, there will be consequences.

func DataKey

func DataKey(attr string, uid uint64) []byte

DataKey generates a data key with the given attribute and UID. The structure of a data key is as follows:

byte 0: key type prefix (set to DefaultPrefix or ByteSplit if part of a multi-part list) byte 1-2: length of attr next len(attr) bytes: value of attr next byte: data type prefix (set to ByteData) next eight bytes: value of uid next eight bytes (optional): if the key corresponds to a split list, the startUid of the split stored in this key and the first byte will be sets to ByteSplit.

func EuclideanDistanceSq

func EuclideanDistanceSq[T c.Float](a, b []T, floatBits int) (T, error)

func GetPersistantOptions

func GetPersistantOptions[T c.Float](o opt.Options) string

func ParseEdges

func ParseEdges(s string) ([]uint64, error)

func ParseNamespaceBytes

func ParseNamespaceBytes(attr string) ([]byte, string)

func Uint64ToBytes

func Uint64ToBytes(key uint64) []byte

func UpdateIndexSplit

func UpdateIndexSplit[T c.Float](vi index.VectorIndex[T], split int) error

Types

type HeapDataHolder

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

func (HeapDataHolder) Len

func (h HeapDataHolder) Len() int

Len is the number of elements in the collection.

func (HeapDataHolder) Less

func (h HeapDataHolder) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (*HeapDataHolder) Pop

func (h *HeapDataHolder) Pop() interface{}

Pop removes and returns the maximum element from the heap.

func (*HeapDataHolder) Push

func (h *HeapDataHolder) Push(x interface{})

Push adds an element to the heap.

func (HeapDataHolder) Swap

func (h HeapDataHolder) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type QueryCache

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

QueryCache implements index.CacheType interface

func NewQueryCache

func NewQueryCache(cache index.LocalCache, readTs uint64) *QueryCache

func (*QueryCache) Find

func (qc *QueryCache) Find(prefix []byte, filter func([]byte) bool) (uint64, error)

func (*QueryCache) Get

func (qc *QueryCache) Get(key []byte) (rval []byte, rerr error)

func (*QueryCache) Ts

func (qc *QueryCache) Ts() uint64

type SearchResult

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

func (*SearchResult) GetExtraMetrics

func (s *SearchResult) GetExtraMetrics() map[string]uint64

func (*SearchResult) GetNnUids

func (s *SearchResult) GetNnUids() []uint64

func (*SearchResult) GetTraversalPath

func (s *SearchResult) GetTraversalPath() []uint64

type SimilarityType

type SimilarityType[T c.Float] struct {
	// contains filtered or unexported fields
}

TODO: Move SimilarityType to index package.

Remove "hnsw-isms".

func GetSimType

func GetSimType[T c.Float](indexType string, floatBits int) SimilarityType[T]

type TxnCache

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

TxnCache implements CacheType interface

func NewTxnCache

func NewTxnCache(txn index.Txn, startTs uint64) *TxnCache

func (*TxnCache) Find

func (tc *TxnCache) Find(prefix []byte, filter func([]byte) bool) (uint64, error)

func (*TxnCache) Get

func (tc *TxnCache) Get(key []byte) (rval []byte, rerr error)

func (*TxnCache) Ts

func (tc *TxnCache) Ts() uint64

Jump to

Keyboard shortcuts

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