Documentation
¶
Index ¶
- Variables
- type HnswIndex
- func (idx *HnswIndex) AddPoints(vectors [][]float32, labels []uint64, concurrency int, replaceDeleted bool) error
- func (idx *HnswIndex) Free()
- func (idx *HnswIndex) GetAllowReplaceDeleted() (bool, error)
- func (idx *HnswIndex) GetCurrentCount() (uint64, error)
- func (idx *HnswIndex) GetDataByLabel(label uint64) ([]float32, error)
- func (idx *HnswIndex) GetMaxElements() (uint64, error)
- func (idx *HnswIndex) IndexFileSize() (uint64, error)
- func (idx *HnswIndex) MarkDeleted(label uint64) error
- func (idx *HnswIndex) ResizeIndex(newSize uint64) error
- func (idx *HnswIndex) Save(location string) error
- func (idx *HnswIndex) SearchKNN(vectors [][]float32, topK int, concurrency int) ([][]*SearchResult, error)
- func (idx *HnswIndex) SetEf(ef int) error
- func (idx *HnswIndex) UnmarkDeleted(label uint64) error
- type SearchResult
- type SpaceType
Constants ¶
This section is empty.
Variables ¶
var ErrIndexClosed = errors.New("index is closed")
ErrIndexClosed is returned when an operation is attempted on a freed index.
Functions ¶
This section is empty.
Types ¶
type HnswIndex ¶
type HnswIndex struct {
// contains filtered or unexported fields
}
HnswIndex wraps the C index type and provides a set of useful index manipulation methods. All methods are safe for concurrent use from multiple goroutines.
func Load ¶
func Load(location string, spaceType SpaceType, dim int, maxElements uint64, allowReplaceDeleted bool) (*HnswIndex, error)
Load loads data from an existing HNSW index file.
func New ¶
func New(dim, M, efConstruction, randSeed int, maxElements uint64, spaceType SpaceType, allowReplaceDeleted bool) (*HnswIndex, error)
New creates a new HnswIndex with the specified dimension and other parameters. For details please see hnswlib documents. When allowReplaceDeleted is set, deleted elements can be replaced with new added ones.
func (*HnswIndex) AddPoints ¶
func (idx *HnswIndex) AddPoints(vectors [][]float32, labels []uint64, concurrency int, replaceDeleted bool) error
AddPoints adds points. Updates the point if it is already in the index. If replacement of deleted elements is enabled: replaces previously deleted point if any, updating it with new point.
func (*HnswIndex) Free ¶
func (idx *HnswIndex) Free()
Free releases resources bound to the index. Should be called when index is destroyed on close. Safe to call multiple times.
func (*HnswIndex) GetAllowReplaceDeleted ¶
GetAllowReplaceDeleted returns the setting of allowReplaceDeleted.
func (*HnswIndex) GetCurrentCount ¶
GetCurrentCount returns the current number of elements stored in the index.
func (*HnswIndex) GetDataByLabel ¶
GetDataByLabel retrieves the stored vector for the given label. For Cosine space, the returned vector is the normalized version that was stored, not the original input vector.
func (*HnswIndex) GetMaxElements ¶
GetMaxElements returns the current capacity of the index.
func (*HnswIndex) IndexFileSize ¶
IndexFileSize returns the index file size in bytes.
func (*HnswIndex) MarkDeleted ¶
MarkDeleted marks the element as deleted, so it will be omitted from search results.
func (*HnswIndex) ResizeIndex ¶
ResizeIndex changes the maximum capacity of the index.
func (*HnswIndex) SearchKNN ¶
func (idx *HnswIndex) SearchKNN(vectors [][]float32, topK int, concurrency int) ([][]*SearchResult, error)
SearchKNN does a batch query against the index using the provided vectors. concurrency sets the threads to use for searching. For each of the queried vectors, topK SearchResults will be returned if no error occurred.
func (*HnswIndex) SetEf ¶
SetEf sets the query time accuracy/speed trade-off, defined by the ef parameter (see doc ALGO_PARAMS.md of hnswlib). Note that the parameter is currently not saved along with the index, so you need to set it manually after loading.
func (*HnswIndex) UnmarkDeleted ¶
UnmarkDeleted unmarks the element as deleted, so it will not be omitted from search results.
type SearchResult ¶
SearchResult is the result returned by search method. Field Distance may be of euclidean distance or inner product distance, or cosine distance, depending on the chosen space type.