rpt

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RPTIndex

type RPTIndex struct {
	Distance                core.DistanceFunc // function to compute distance between vectors
	DistanceName            string            // name of the distance metric
	LeafCapacity            int               // maximum number of points in a leaf
	CandidateProjections    int               // number of random projections to try when splitting
	ParallelThreshold       int               // threshold to trigger parallel tree building
	ProbeMargin             float64           // margin for multi-probe search
	AllowBruteForceFallback bool              // whether to allow falling back to a full brute-force scan
	// contains filtered or unexported fields
}

RPTIndex is the main structure for the random projection tree index. It holds all points, the tree root, and configuration parameters.

func NewRPTIndex

func NewRPTIndex(
	dimension int,
	leafCapacity int,
	candidateProjections int,
	parallelThreshold int,
	probeMargin float64,
) *RPTIndex

NewRPTIndex creates a new RPT (Random Projection Tree) index. It initializes parameters like dimension, leaf capacity, candidate projections, parallel threshold, and probe margin.

func (*RPTIndex) Add

func (r *RPTIndex) Add(id int, vector []float32) error

Add inserts a new point with the given id and vector into the index. It marks the tree as dirty so it will be rebuilt.

func (*RPTIndex) BulkAdd

func (r *RPTIndex) BulkAdd(vectors map[int][]float32) error

BulkAdd inserts multiple points into the index and marks the tree as dirty.

func (*RPTIndex) BulkDelete

func (r *RPTIndex) BulkDelete(ids []int) error

BulkDelete removes multiple points from the index and marks the tree as dirty.

func (*RPTIndex) BulkUpdate

func (r *RPTIndex) BulkUpdate(updates map[int][]float32) error

BulkUpdate updates multiple points in the index.

func (*RPTIndex) Delete

func (r *RPTIndex) Delete(id int) error

Delete removes a point by its id and marks the tree as dirty.

func (*RPTIndex) GobDecode

func (r *RPTIndex) GobDecode(data []byte) error

GobDecode deserializes the index from gob data.

func (*RPTIndex) GobEncode

func (r *RPTIndex) GobEncode() ([]byte, error)

GobEncode serializes the index to bytes using gob.

func (*RPTIndex) Load

func (r *RPTIndex) Load(rdr io.Reader) error

Load reads the index from the given reader using gob encoding.

func (*RPTIndex) Save

func (r *RPTIndex) Save(w io.Writer) error

Save writes the index to the given writer using gob encoding.

func (*RPTIndex) Search

func (r *RPTIndex) Search(query []float32, k int) ([]core.Neighbor, error)

Search returns the k nearest neighbors to the query vector. It rebuilds the tree if needed and uses multi-probe search to get candidate ids.

func (*RPTIndex) Stats

func (r *RPTIndex) Stats() core.IndexStats

Stats returns some basic statistics about the index.

func (*RPTIndex) Update

func (r *RPTIndex) Update(id int, vector []float32) error

Update changes the vector of an existing point and marks the tree as dirty.

Jump to

Keyboard shortcuts

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