Documentation
¶
Index ¶
- func Normalize(vector []float32)
- type Index
- func (i *Index) DeleteVector(label uint64) error
- func (i *Index) Free()
- func (i *Index) GetVector(label uint64) ([]float32, error)
- func (i *Index) InsertVector(vector []float32, label uint64) error
- func (i *Index) ReplaceVector(label uint64, newVector []float32) error
- func (i *Index) SaveToDisk(location string) error
- func (i *Index) SearchKNN(vector []float32, k int) ([]uint64, []float32, error)
- func (i *Index) SetEfConstruction(efConstruction int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func LoadIndex ¶ added in v2.1.0
Loads a saved index and returns a reference to it.
- location: the file path of the saved index
- dim: dimension of the vector space
- spaceType: similarity metric to use in the index ("ip", "cosine", "l2". default: "l2")
- maxElements: index's vector storage capacity
Returns an instance of the saved HNSW index, or an error if there was a problem.
func New ¶
func New(dim int, m int, efConstruction int, randSeed int, maxElements uint32, spaceType string) (*Index, error)
Returns a reference to an instance of an HNSW index.
- dim: dimension of the vector space
- maxElements: index's vector storage capacity
- m: `m` parameter in the HNSW algorithm
- efConstruction: `efConstruction` parameter in the HNSW algorithm
- randSeed: random seed
- spaceType: similarity metric to use in the index ("ip", "cosine", "l2". default: "l2")
Returns an instance of an HNSW index, or an error if there was a problem initializing the index.
func (*Index) DeleteVector ¶
Marks a vector with the specified label as deleted, which omits it from KNN search.
- label: the vector's label
Returns an error if one occured.
func (*Index) GetVector ¶
Returns a vector's components using its label
- label: the vector's label
Returns the vector's components with specified label
func (*Index) InsertVector ¶
Adds a vector to the HNSW index. If the a vector with the same label already exists, the function returns an error
- vector: the vector to add to the index
- label: the vector's label
Returns an error if one occured.
func (*Index) ReplaceVector ¶ added in v2.2.0
Replaces an existing vector in the HNSW index.
- label: the vector's label
- newVector: the new vector used to replace the old vector
Returns an error if one occured.
func (*Index) SaveToDisk ¶ added in v2.1.0
Saves the index to the disk.
- location: the file path in which to save the index
Returns an error if there was a problem.
func (*Index) SearchKNN ¶
Performs similarity search on the HNSW index.
- vector: the query vector
- k: the k value
Returns the labels and distances of each of the nearest neighbors, and an error if one occured. Note: the size of both arrays can be < k if k > num of vectors in the index
func (*Index) SetEfConstruction ¶
Set's the efConstruction parameter in the HNSW index.
- efConstruction: the new efConstruction parameter
Returns an error if one occured.