hnswgo

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2021 License: Apache-2.0, Apache-2.0 Imports: 12 Imported by: 0

README

HNSWGO

This is a Go interface of hnswlib. For more information, please follow hnswlib and Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs..

Credits

This is a derivative work of https://github.com/evan176/hnswgo.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	SpaceType      SpaceType
	Dim            int
	MaxElements    int
	M              int
	EfConstruction int
	RandSeed       int
	AutoIDEnabled  bool
}

Config provides configuration parameters for HNSW.

type HNSW

type HNSW struct {
	// contains filtered or unexported fields
}

HNSW is an interface to HNSW C code.

func Load

func Load(dir string, logger zerolog.Logger) (*HNSW, error)

Load loads an HNSW index from file.

func New

func New(dir string, config Config, logger zerolog.Logger) *HNSW

New creates a new HNSW index.

func (*HNSW) AddPoint

func (h *HNSW) AddPoint(vector []float32, id uint32) error

AddPoint adds a new vector to the index.

func (*HNSW) AddPointAutoID

func (h *HNSW) AddPointAutoID(vector []float32) (uint32, error)

AddPointAutoID adds a new vector to the index.

func (*HNSW) MarkDelete

func (h *HNSW) MarkDelete(id uint32) error

MarkDelete marks an element with the given ID deleted. It does not really change the current graph.

func (*HNSW) Save

func (h *HNSW) Save() error

Save saves the HNSW index to file.

func (*HNSW) SearchKNN

func (h *HNSW) SearchKNN(vector []float32, N int) []KNNResult

SearchKNN performs KNN search.

func (*HNSW) SetEf

func (h *HNSW) SetEf(ef int) error

SetEf sets the "ef" parameter.

type KNNResult

type KNNResult struct {
	ID       uint32
	Distance float32
}

KNNResult is an ID/Distance pair, which is a single result item of HNSW.SearchKNN.

type SpaceType

type SpaceType string

SpaceType identifies a space type to be used by HNSW algorithm.

const (
	// IPSpace identifies an Inner Product space.
	IPSpace SpaceType = "ip"
	// CosineSpace identifies a Cosine space.
	CosineSpace SpaceType = "cosine"
	// L2Space identifies an L2 space.
	L2Space SpaceType = "l2"
)

func SpaceTypeFromString

func SpaceTypeFromString(s string) (SpaceType, error)

SpaceTypeFromString makes a SpaceType value from string. Valid string values are: "ip", "cosine", or "l2".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL