Documentation
¶
Index ¶
- Variables
- type Flat
- func (f *Flat[ID]) Add(id ID, vector ...float32) error
- func (f *Flat[ID]) BatchUpsert(ids []ID, vectors [][]float32) error
- func (f *Flat[ID]) Clear(keepCapacity bool)
- func (f *Flat[ID]) ColumnName(dim int) (string, bool)
- func (f *Flat[ID]) ColumnNames() []string
- func (f *Flat[ID]) Delete(id ID) bool
- func (f *Flat[ID]) Dim() int
- func (f *Flat[ID]) Len() int
- func (f *Flat[ID]) Load(r io.Reader, opts ...PersistOption[ID]) error
- func (f *Flat[ID]) Metric() Metric
- func (f *Flat[ID]) Save(w io.Writer, opts ...PersistOption[ID]) error
- func (f *Flat[ID]) Search(k int, query ...float32) []Result[ID]
- func (f *Flat[ID]) SearchWeighted(k int, queries ...WeightedQuery) []Result[ID]
- func (f *Flat[ID]) SearchWeightedWithOptions(k int, queries []WeightedQuery, opts ...SearchOption[ID]) []Result[ID]
- func (f *Flat[ID]) SearchWithOptions(k int, query []float32, opts ...SearchOption[ID]) []Result[ID]
- func (f *Flat[ID]) SetColumnName(dim int, name string) error
- func (f *Flat[ID]) SetColumnNames(names ...string) error
- func (f *Flat[ID]) Upsert(id ID, vector ...float32) error
- func (f *Flat[ID]) Vector(id ID) ([]float32, bool)
- type HNSW
- func (h *HNSW[ID]) Add(id ID, vector ...float32) error
- func (h *HNSW[ID]) BatchUpsert(ids []ID, vectors [][]float32) error
- func (h *HNSW[ID]) Clear(keepCapacity bool)
- func (h *HNSW[ID]) ColumnName(dim int) (string, bool)
- func (h *HNSW[ID]) ColumnNames() []string
- func (h *HNSW[ID]) Delete(id ID) bool
- func (h *HNSW[ID]) Dim() int
- func (h *HNSW[ID]) Len() int
- func (h *HNSW[ID]) Load(r io.Reader, opts ...PersistOption[ID]) error
- func (h *HNSW[ID]) Metric() Metric
- func (h *HNSW[ID]) Save(w io.Writer, opts ...PersistOption[ID]) error
- func (h *HNSW[ID]) Search(k int, query ...float32) []Result[ID]
- func (h *HNSW[ID]) SearchWeighted(k int, queries ...WeightedQuery) []Result[ID]
- func (h *HNSW[ID]) SearchWeightedWithOptions(k int, queries []WeightedQuery, opts ...SearchOption[ID]) []Result[ID]
- func (h *HNSW[ID]) SearchWithOptions(k int, query []float32, opts ...SearchOption[ID]) []Result[ID]
- func (h *HNSW[ID]) SetColumnName(dim int, name string) error
- func (h *HNSW[ID]) SetColumnNames(names ...string) error
- func (h *HNSW[ID]) Upsert(id ID, vector ...float32) error
- func (h *HNSW[ID]) Vector(id ID) ([]float32, bool)
- type IDCodec
- type Metric
- type Option
- type PersistOption
- type Result
- type SearchOption
- type WeightedQuery
Constants ¶
This section is empty.
Variables ¶
var ( ErrIDExists = errors.New("vecdb: id already exists") ErrBatchSizeMismatch = errors.New("vecdb: batch length mismatch") ErrDimMismatch = errors.New("vecdb: dimension mismatch") ErrEmptyVector = errors.New("vecdb: empty vector") ErrInvalidFormat = errors.New("vecdb: invalid persistence format") ErrInvalidColumnIndex = errors.New("vecdb: invalid column index") ErrColumnNamesMismatch = errors.New("vecdb: column names length mismatch") ErrUnsupportedIDType = errors.New("vecdb: unsupported id type for persistence") ErrUnsupportedVersion = errors.New("vecdb: unsupported persistence version") )
Functions ¶
This section is empty.
Types ¶
type Flat ¶
type Flat[ID comparable] struct { // contains filtered or unexported fields }
Flat is a brute-force in-memory vector index.
func NewFlat ¶
func NewFlat[ID comparable](dim int, opts ...Option) *Flat[ID]
NewFlat creates a flat index. If dim is zero, the first insert sets the dimension.
func (*Flat[ID]) BatchUpsert ¶ added in v0.8.7
BatchUpsert inserts or updates multiple vectors.
func (*Flat[ID]) Clear ¶ added in v0.8.3
Clear removes all vectors from the index. If keepCapacity is true, backing storage is retained for reuse.
func (*Flat[ID]) ColumnName ¶ added in v0.8.5
ColumnName returns the associated column name for the given dimension (0-based).
func (*Flat[ID]) ColumnNames ¶ added in v0.8.6
ColumnNames returns a copy of the associated column names, indexed by dimension (0-based). Unset names are returned as empty strings.
func (*Flat[ID]) Load ¶ added in v0.8.4
func (f *Flat[ID]) Load(r io.Reader, opts ...PersistOption[ID]) error
Load replaces the flat index with data read from r.
func (*Flat[ID]) Save ¶ added in v0.8.4
func (f *Flat[ID]) Save(w io.Writer, opts ...PersistOption[ID]) error
Save writes the flat index to w.
func (*Flat[ID]) SearchWeighted ¶
func (f *Flat[ID]) SearchWeighted(k int, queries ...WeightedQuery) []Result[ID]
SearchWeighted returns the k closest vectors to the weighted query sum, normalizing weights by the sum of absolute weights.
func (*Flat[ID]) SearchWeightedWithOptions ¶
func (f *Flat[ID]) SearchWeightedWithOptions(k int, queries []WeightedQuery, opts ...SearchOption[ID]) []Result[ID]
SearchWeightedWithOptions returns the k closest vectors to the weighted query sum with options applied.
func (*Flat[ID]) SearchWithOptions ¶
func (f *Flat[ID]) SearchWithOptions(k int, query []float32, opts ...SearchOption[ID]) []Result[ID]
SearchWithOptions returns the k closest vectors to query with options applied.
func (*Flat[ID]) SetColumnName ¶ added in v0.8.5
SetColumnName sets the associated column name for the given dimension (0-based).
func (*Flat[ID]) SetColumnNames ¶ added in v0.8.7
SetColumnNames replaces all associated column names, indexed by dimension (0-based).
type HNSW ¶
type HNSW[ID comparable] struct { // contains filtered or unexported fields }
HNSW is an approximate in-memory vector index.
func NewHNSW ¶
func NewHNSW[ID comparable](dim int, opts ...Option) *HNSW[ID]
NewHNSW creates a new HNSW index. If dim is zero, the first insert sets the dimension. Type parameters:
- ID: a comparable identifier used as the primary key for update/delete/lookup.
func (*HNSW[ID]) BatchUpsert ¶ added in v0.8.7
BatchUpsert inserts or updates multiple vectors. Updates are implemented as delete + add.
func (*HNSW[ID]) Clear ¶ added in v0.8.3
Clear removes all vectors from the index. If keepCapacity is true, backing storage is retained for reuse.
func (*HNSW[ID]) ColumnName ¶ added in v0.8.5
ColumnName returns the associated column name for the given dimension (0-based).
func (*HNSW[ID]) ColumnNames ¶ added in v0.8.6
ColumnNames returns a copy of the associated column names, indexed by dimension (0-based). Unset names are returned as empty strings.
func (*HNSW[ID]) Load ¶ added in v0.8.4
func (h *HNSW[ID]) Load(r io.Reader, opts ...PersistOption[ID]) error
Load replaces the HNSW index with data read from r.
func (*HNSW[ID]) Save ¶ added in v0.8.4
func (h *HNSW[ID]) Save(w io.Writer, opts ...PersistOption[ID]) error
Save writes the HNSW index to w, preserving graph structure.
func (*HNSW[ID]) SearchWeighted ¶
func (h *HNSW[ID]) SearchWeighted(k int, queries ...WeightedQuery) []Result[ID]
SearchWeighted returns the k closest vectors to the weighted query sum, normalizing weights by the sum of absolute weights.
func (*HNSW[ID]) SearchWeightedWithOptions ¶
func (h *HNSW[ID]) SearchWeightedWithOptions(k int, queries []WeightedQuery, opts ...SearchOption[ID]) []Result[ID]
SearchWeightedWithOptions returns the k closest vectors to the weighted query sum with options applied.
func (*HNSW[ID]) SearchWithOptions ¶
func (h *HNSW[ID]) SearchWithOptions(k int, query []float32, opts ...SearchOption[ID]) []Result[ID]
SearchWithOptions returns the k closest vectors to query with options applied.
func (*HNSW[ID]) SetColumnName ¶ added in v0.8.5
SetColumnName sets the associated column name for the given dimension (0-based).
func (*HNSW[ID]) SetColumnNames ¶ added in v0.8.7
SetColumnNames replaces all associated column names, indexed by dimension (0-based).
type IDCodec ¶ added in v0.8.4
type IDCodec[ID comparable] interface { Encode(w io.Writer, id ID) error Decode(r io.Reader) (ID, error) }
IDCodec handles serialization of ID values.
type Option ¶
type Option func(*config)
Option configures an index at construction time.
func WithColumnNames ¶ added in v0.8.5
WithColumnNames sets the associated vector column names by dimension (0-based).
func WithEFConstruction ¶
WithEFConstruction sets the efConstruction parameter for HNSW insertions.
func WithEFSearch ¶
WithEFSearch sets the default efSearch parameter for HNSW queries.
type PersistOption ¶ added in v0.8.4
type PersistOption[ID comparable] func(*persistOptions[ID])
PersistOption configures Save/Load behavior.
func WithIDCodec ¶ added in v0.8.4
func WithIDCodec[ID comparable](codec IDCodec[ID]) PersistOption[ID]
WithIDCodec overrides ID encoding/decoding for persistence.
type Result ¶
type Result[ID comparable] struct { ID ID Score float32 }
Result is a nearest-neighbor search result.
type SearchOption ¶
type SearchOption[ID comparable] func(*searchOptions[ID])
SearchOption configures search behavior.
func WithEF ¶
func WithEF[ID comparable](ef int) SearchOption[ID]
WithEF overrides efSearch for a single HNSW query.
func WithFilter ¶
func WithFilter[ID comparable](filter func(id ID) bool) SearchOption[ID]
WithFilter filters candidates by ID.
type WeightedQuery ¶
WeightedQuery is a query vector scaled by Weight. SearchWeighted normalizes weights by the sum of absolute weights. Negative weights are allowed.