knn

package
v1.80.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package knn adapts exact and approximate top-k vector search to the search.Searcher interface so it composes with boolean, sort, collector and aggregation code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(field string, query []float32, k int, metric vec.Metric) error

Validate reports whether the parameters describe a runnable KNN search.

Types

type ApproximateVectorReader added in v1.30.0

type ApproximateVectorReader interface {
	SearchVectorsANN(ctx context.Context, field string, query []float32, k int,
		metric vec.Metric, params hnsw.Params, accept func(uint64) bool) ([]vec.Match, error)
}

ApproximateVectorReader is the optional capability a search.Reader must provide for ANN search. *index.Snapshot implements it.

type Searcher

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

Searcher yields the k nearest documents in ascending document number order, scored by boost * similarity. The vector scan is deferred to the first Next or Advance so it runs after search admission (Config.SearchStartFunc) and under the collector's search.Context.Ctx for cancellation.

func NewApproximateSearcher added in v1.30.0

func NewApproximateSearcher(indexReader search.Reader, field string, query []float32, k int,
	metric vec.Metric, params hnsw.Params, boost float64, accept func(uint64) bool,
	options search.SearcherOptions) (*Searcher, error)

NewApproximateSearcher is like NewSearcher but searches per-segment HNSW graphs tuned by params. indexReader must implement ApproximateVectorReader.

func NewSearcher

func NewSearcher(indexReader search.Reader, field string, query []float32, k int,
	metric vec.Metric, boost float64, accept func(uint64) bool, options search.SearcherOptions) (*Searcher, error)

NewSearcher validates the parameters without scanning. indexReader must implement VectorReader. accept may be nil; otherwise it prefilters document numbers.

func (*Searcher) Advance

func (s *Searcher) Advance(ctx *search.Context, number uint64) (*search.DocumentMatch, error)

func (*Searcher) Close

func (s *Searcher) Close() error

func (*Searcher) Count

func (s *Searcher) Count() uint64

Count returns k until the scan has run, then the number of matches.

func (*Searcher) DocumentMatchPoolSize

func (s *Searcher) DocumentMatchPoolSize() int

func (*Searcher) Min

func (s *Searcher) Min() int

func (*Searcher) Next

func (s *Searcher) Next(ctx *search.Context) (*search.DocumentMatch, error)

func (*Searcher) Size

func (s *Searcher) Size() int

Size estimates memory for k matches; it is used for admission before the scan runs.

type VectorReader

type VectorReader interface {
	SearchVectors(ctx context.Context, field string, query []float32, k int,
		metric vec.Metric, accept func(uint64) bool) ([]vec.Match, error)
}

VectorReader is the optional capability a search.Reader must provide for KNN search. *index.Snapshot implements it.

Jump to

Keyboard shortcuts

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