cover

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cover provides a cover-tree adapter that currently delegates to a brute-force implementation. It preserves a stable API so the internals can be switched to a real cover tree without changing callers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoundStrategy

type BoundStrategy int

BoundStrategy exposes the pruning strategy knobs for cover-tree searches.

const (
	// BoundPerNode caches subtree radii per node (tighter pruning, more bookkeeping).
	BoundPerNode BoundStrategy = iota
	// BoundLevel uses level-derived bounds (looser but cheaper to evaluate).
	BoundLevel
)

type DistanceFunction

type DistanceFunction = ctree.DistanceFunction

DistanceFunction re-exports cover-tree distance identifiers for callers.

const (
	// DistanceFunctionCosine uses cosine distance (default).
	DistanceFunctionCosine DistanceFunction = ctree.DistanceFunctionCosine
	// DistanceFunctionEuclidean uses Euclidean distance.
	DistanceFunctionEuclidean DistanceFunction = ctree.DistanceFunctionEuclidean
)

type Index

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

Index wraps a cover tree (adapted from viant/gds) behind the sqlite-vec index API.

func New

func New(opts ...Option) *Index

New constructs an Index with optional tuning knobs.

func (*Index) Build

func (i *Index) Build(ids []string, vectors [][]float32) error

Build constructs the cover tree from ids/vectors using cosine distance.

func (*Index) MarshalBinary

func (i *Index) MarshalBinary() ([]byte, error)

MarshalBinary persists the cover tree along with document values.

func (*Index) Query

func (i *Index) Query(query []float32, k int) ([]string, []float64, error)

Query performs a cosine kNN search using the underlying cover tree.

func (*Index) UnmarshalBinary

func (i *Index) UnmarshalBinary(data []byte) error

UnmarshalBinary restores the index from the cover-tree format or the legacy brute format.

type Option

type Option func(*Index)

Option configures a cover Index instance.

func WithBase

func WithBase(base float32) Option

WithBase overrides the geometric base used by the cover tree (default 1.3).

func WithBoundStrategy

func WithBoundStrategy(strategy BoundStrategy) Option

WithBoundStrategy selects the pruning strategy used during queries.

func WithBuildParallelism

func WithBuildParallelism(workers int) Option

WithBuildParallelism sets the number of workers used to clone vectors/magnitudes during Build. Zero/negative values fall back to GOMAXPROCS with automatic throttling for small datasets.

func WithDistance

func WithDistance(distance DistanceFunction) Option

WithDistance switches the cover-tree distance metric (default cosine).

Jump to

Keyboard shortcuts

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