Documentation
¶
Overview ¶
Package vector stores embeddings by ID and answers nearest-neighbour queries. Small indexes are searched exactly; past Params.Threshold vectors an HNSW graph answers approximately (see hnsw.go and index.go).
Index ¶
- Variables
- type Index
- func (x *Index) Add(id string, v []float32, attr string) (bool, error)
- func (x *Index) Dim() int
- func (x *Index) Get(id string) ([]float32, string, bool)
- func (x *Index) IDs() []string
- func (x *Index) Len() int
- func (x *Index) MemSize() int64
- func (x *Index) Remove(id string) bool
- func (x *Index) Search(q []float32, k int, filter func(id, attr string) bool) ([]Result, error)
- type Params
- type Result
Constants ¶
This section is empty.
Variables ¶
var DefaultParams = Params{M: 16, EfConstruction: 200, EfSearch: 64, Threshold: 1000}
var ErrEmpty = errors.New("ERR zero-length vector")
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index struct {
Params Params
// contains filtered or unexported fields
}
func (*Index) Add ¶
Add inserts or replaces a vector. The first vector fixes the dimension. Returns true if id is new.
func (*Index) Search ¶
Search returns the k most similar vectors to q, best first. filter, if non-nil, skips ids for which it returns false; it is called at most once per id.
Below Params.Threshold vectors (or when k covers the whole index) the scan is exact. Otherwise the HNSW graph, which Add keeps up to date, answers approximately; if it finds fewer than k matches passing the filter, Search falls back to the exact scan so a selective filter never loses results.
type Params ¶
type Params struct {
M int // links per node above layer 0; layer 0 allows 2M
EfConstruction int // candidate list size while inserting
EfSearch int // minimum candidate list size while querying (x2 with a filter)
Threshold int // below this many vectors Search is exact
}
Params tunes the HNSW graph. Changes apply the next time the graph is started.