ngt

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package ngt provides implementation of Go API for https://github.com/yahoojapan/NGT

Package ngt provides implementation of Go API for https://github.com/yahoojapan/NGT

Package ngt provides implementation of Go API for https://github.com/yahoojapan/NGT

Package ngt provides implementation of Go API for https://github.com/yahoojapan/NGT

Index

Constants

View Source
const (
	// ObjectNone is unknown object type
	ObjectNone objectType = iota
	// Uint8 is 8bit unsigned integer
	Uint8
	// Float is 32bit floating point number
	Float

	// DistanceNone is unknown distance type
	DistanceNone distanceType = iota - 1
	// L1 is l1 norm
	L1
	// L2 is l2 norm
	L2
	// Angle is angle distance
	Angle
	// Hamming is hamming distance
	Hamming
	// Cosine is cosine distance
	Cosine
	// NormalizedAngle is angle distance with normalization
	NormalizedAngle
	// NormalizedCosine is cosine distance with normalization
	NormalizedCosine

	// ErrorCode is false
	ErrorCode = C._Bool(false)
)

Variables

View Source
var (
	DefaultPoolSize = uint32(10000)
	DefaultRadius   = float32(-1.0)
	DefaultEpsilon  = float32(0.01)
)

Functions

This section is empty.

Types

type NGT

type NGT interface {
	// Search returns search result as []SearchResult
	Search(vec []float32, size int, epsilon, radius float32) ([]SearchResult, error)

	// Insert returns NGT object id.
	// This only stores not indexing, you must call CreateIndex and SaveIndex.
	Insert(vec []float32) (uint, error)

	// InsertCommit returns NGT object id.
	// This stores and indexes at the same time.
	InsertCommit(vec []float32, poolSize uint32) (uint, error)

	// BulkInsert returns NGT object ids.
	// This only stores not indexing, you must call CreateIndex and SaveIndex.
	BulkInsert(vecs [][]float32) ([]uint, []error)

	// BulkInsertCommit returns NGT object ids.
	// This stores and indexes at the same time.
	BulkInsertCommit(vecs [][]float32, poolSize uint32) ([]uint, []error)

	// CreateAndSaveIndex call  CreateIndex and SaveIndex in a row.
	CreateAndSaveIndex(poolSize uint32) error

	// CreateIndex creates NGT index.
	CreateIndex(poolSize uint32) error

	// SaveIndex stores NGT index to storage.
	SaveIndex() error

	// Remove removes from NGT index.
	Remove(id uint) error

	// BulkRemove removes multiple NGT index
	BulkRemove(ids ...uint) error

	// GetVector returns vector stored in NGT index.
	GetVector(id uint) ([]float32, error)

	// Close NGT index.
	Close()
}

NGT is core interface

func Load

func Load(opts ...Option) (NGT, error)

Load returns NGT instance from existing index file

func New

func New(opts ...Option) (NGT, error)

New returns NGT instance with recreating empty index file

type Option

type Option func(*ngt) error

func WithBulkInsertChunkSize

func WithBulkInsertChunkSize(size int) Option

func WithCreationEdgeSize

func WithCreationEdgeSize(size int) Option

func WithDefaultEpsilon

func WithDefaultEpsilon(epsilon float32) Option

func WithDefaultPoolSize

func WithDefaultPoolSize(poolSize uint32) Option

func WithDefaultRadius

func WithDefaultRadius(radius float32) Option

func WithDimension

func WithDimension(size int) Option

func WithDistanceType

func WithDistanceType(t distanceType) Option

func WithDistanceTypeByString

func WithDistanceTypeByString(dt string) Option

func WithInMemoryMode

func WithInMemoryMode(flg bool) Option

func WithIndexPath

func WithIndexPath(path string) Option

func WithObjectType

func WithObjectType(t objectType) Option

func WithObjectTypeByString

func WithObjectTypeByString(ot string) Option

func WithSearchEdgeSize

func WithSearchEdgeSize(size int) Option

type SearchResult

type SearchResult struct {
	ID       uint32
	Distance float32
	Error    error
}

SearchResult is struct for comfortable use in Go

Jump to

Keyboard shortcuts

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