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 ¶
- func Validate(field string, query []float32, k int, metric vec.Metric) error
- type ApproximateVectorReader
- type Searcher
- func (s *Searcher) Advance(ctx *search.Context, number uint64) (*search.DocumentMatch, error)
- func (s *Searcher) Close() error
- func (s *Searcher) Count() uint64
- func (s *Searcher) DocumentMatchPoolSize() int
- func (s *Searcher) Min() int
- func (s *Searcher) Next(ctx *search.Context) (*search.DocumentMatch, error)
- func (s *Searcher) Size() int
- type VectorReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) DocumentMatchPoolSize ¶
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.