ngt

package
v1.7.16 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 16 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

Index

Constants

View Source
const (
	// -------------------------------------------------------------
	// Object Type Definition
	// -------------------------------------------------------------
	// ObjectNone is unknown object type.
	ObjectNone objectType = iota
	// Uint8 is 8bit unsigned integer.
	Uint8
	// Float is 32bit floating point number.
	Float
	// HalfFloat is 16bit floating point number.
	HalfFloat
)
View Source
const (
	// -------------------------------------------------------------
	// Distance Type Definition
	// -------------------------------------------------------------
	// 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
	// Poincare is poincare distance.
	Poincare
	// Lorentz is lorenz distance.
	Lorentz
	// Jaccard is jaccard distance.
	Jaccard
	// SparseJaccard is sparse jaccard distance.
	SparseJaccard
	// NormalizedL2 is l2 distance with normalization.
	NormalizedL2
	// NormalizedAngle is angle distance with normalization.
	NormalizedAngle
	// NormalizedCosine is cosine distance with normalization.
	NormalizedCosine
	// InnerProduct is inner product distance.
	InnerProduct
)
View Source
const (
	// -------------------------------------------------------------
	// IndexType Definition
	// -------------------------------------------------------------
	IndexTypeNone indexType = iota
	GraphAndTree
	Graph
)
View Source
const (
	// -------------------------------------------------------------
	// DatabaseType Definition
	// -------------------------------------------------------------
	DatabaseTypeNone databaseType = iota
	Memory
	MemoryMappedFile
)
View Source
const (
	// -------------------------------------------------------------
	// ObjectAlignment Definition
	// -------------------------------------------------------------
	ObjectAlignmentNone objectAlignment = iota
	ObjectAlignmentTrue
	ObjectAlignmentFalse
)
View Source
const (
	// -------------------------------------------------------------
	// SeedType Definition
	// -------------------------------------------------------------
	// SeedTypeNone is unknown seed type.
	SeedTypeNone seedType = iota
	RandomNodes
	FixedNodes
	FirstNode
	AllLeafNodes
)
View Source
const (
	// -------------------------------------------------------------
	// GraphType Definition
	// -------------------------------------------------------------
	GraphTypeNone graphType = iota
	ANNG
	KNNG
	BKNNG
	ONNG
	IANNG
	DNNG
	RANNG
	RIANNG
)
View Source
const (
	// -------------------------------------------------------------
	// ErrorCode is false
	// -------------------------------------------------------------.
	ErrorCode = C._Bool(false)

	NormalStatistics statisticsType = iota - 1
	AdditionalStatistics
)

Variables

View Source
var (
	DefaultPoolSize         = uint32(10000)
	DefaultRadius           = float32(-1.0)
	DefaultEpsilon          = float32(0.1)
	DefaultErrorBufferLimit = uint64(10)
)

Functions

This section is empty.

Types

type GraphStatistics added in v1.7.13

type GraphStatistics struct {
	Valid                            bool
	MedianIndegree                   int32
	MedianOutdegree                  int32
	MaxNumberOfIndegree              uint64
	MaxNumberOfOutdegree             uint64
	MinNumberOfIndegree              uint64
	MinNumberOfOutdegree             uint64
	ModeIndegree                     uint64
	ModeOutdegree                    uint64
	NodesSkippedFor10Edges           uint64
	NodesSkippedForIndegreeDistance  uint64
	NumberOfEdges                    uint64
	NumberOfIndexedObjects           uint64
	NumberOfNodes                    uint64
	NumberOfNodesWithoutEdges        uint64
	NumberOfNodesWithoutIndegree     uint64
	NumberOfObjects                  uint64
	NumberOfRemovedObjects           uint64
	SizeOfObjectRepository           uint64
	SizeOfRefinementObjectRepository uint64
	VarianceOfIndegree               float64
	VarianceOfOutdegree              float64
	MeanEdgeLength                   float64
	MeanEdgeLengthFor10Edges         float64
	MeanIndegreeDistanceFor10Edges   float64
	MeanNumberOfEdgesPerNode         float64
	C1Indegree                       float64
	C5Indegree                       float64
	C95Outdegree                     float64
	C99Outdegree                     float64
	IndegreeCount                    []int64
	OutdegreeHistogram               []uint64
	IndegreeHistogram                []uint64
}

type NGT

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

	// Linear Search returns linear search result as []algorithm.SearchResult
	LinearSearch(ctx context.Context, vec []float32, size int) ([]algorithm.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

	// SaveIndexWithPath stores NGT index to specified storage.
	SaveIndexWithPath(path string) 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)

	GetGraphStatistics(ctx context.Context, m statisticsType) (stats *GraphStatistics, err error)

	// GetProperty returns NGT Index Property.
	GetProperty() (*Property, error)

	// Close Without save index.
	CloseWithoutSaveIndex()

	// 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

Option represents the functional option for NGT.

func WithBulkInsertChunkSize

func WithBulkInsertChunkSize(size int) Option

WithBulkInsertChunkSize represents the option to set the bulk insert chunk size for NGT.

func WithCreationEdgeSize

func WithCreationEdgeSize(size int) Option

WithCreationEdgeSize represents the option to set the creation edge size for NGT.

func WithDefaultEpsilon

func WithDefaultEpsilon(epsilon float32) Option

WithDefaultEpsilon represents the option to set the default epsilon for NGT.

func WithDefaultPoolSize

func WithDefaultPoolSize(poolSize uint32) Option

WithDefaultPoolSize represents the option to set the default pool size for NGT.

func WithDefaultRadius

func WithDefaultRadius(radius float32) Option

WithDefaultRadius represents the option to set the default radius for NGT.

func WithDimension

func WithDimension(size int) Option

WithDimension represents the option to set the dimension for NGT.

func WithDistanceType

func WithDistanceType(t distanceType) Option

WithDistanceType represents the option to set the distance type for NGT.

func WithDistanceTypeByString

func WithDistanceTypeByString(dt string) Option

WithDistanceTypeByString represents the option to set the distance type for NGT.

func WithErrorBufferLimit added in v1.7.9

func WithErrorBufferLimit(limit uint64) Option

WithErrorBufferLimit represents the option to set the default error buffer pool size limit for NGT.

func WithInMemoryMode

func WithInMemoryMode(flg bool) Option

WithInMemoryMode represents the option to set to start in memory mode or not for NGT.

func WithIndexPath

func WithIndexPath(path string) Option

WithIndexPath represents the option to set the index path for NGT.

func WithObjectType

func WithObjectType(t objectType) Option

WithObjectType represents the option to set the object type for NGT.

func WithObjectTypeByString

func WithObjectTypeByString(ot string) Option

WithObjectTypeByString represents the option to set the object type by string for NGT.

func WithSearchEdgeSize

func WithSearchEdgeSize(size int) Option

WithSearchEdgeSize represents the option to set the search edge size for NGT.

type Property added in v1.7.14

type Property struct {
	Dimension                     int32
	ThreadPoolSize                int32
	ObjectType                    objectType
	DistanceType                  distanceType
	IndexType                     indexType
	DatabaseType                  databaseType
	ObjectAlignment               objectAlignment
	PathAdjustmentInterval        int32
	GraphSharedMemorySize         int32
	TreeSharedMemorySize          int32
	ObjectSharedMemorySize        int32
	PrefetchOffset                int32
	PrefetchSize                  int32
	AccuracyTable                 string
	SearchType                    string
	MaxMagnitude                  float32
	NOfNeighborsForInsertionOrder int32
	EpsilonForInsertionOrder      float32
	RefinementObjectType          objectType
	TruncationThreshold           int32
	EdgeSizeForCreation           int32
	EdgeSizeForSearch             int32
	EdgeSizeLimitForCreation      int32
	InsertionRadiusCoefficient    float64
	SeedSize                      int32
	SeedType                      seedType
	TruncationThreadPoolSize      int32
	BatchSizeForCreation          int32
	GraphType                     graphType
	DynamicEdgeSizeBase           int32
	DynamicEdgeSizeRate           int32
	BuildTimeLimit                float32
	OutgoingEdge                  int32
	IncomingEdge                  int32
}

Jump to

Keyboard shortcuts

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