gongt

package module
v0.0.0-...-966dcc7 Latest Latest
Warning

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

Go to latest
Published: May 17, 2019 License: Apache-2.0 Imports: 6 Imported by: 7

README

gongt release CircleCI codecov Go Report Card GoDoc

Description

gongt provides Go API for NGT.

NGT is Neighborhood Graph and Tree for Indexing High-dimensional Data. If you want more information, please read NGT repository.

Dependency

Installation

$ go get -u github.com/yahoojapan/gongt

Example

package main

import (
	"fmt"

	"github.com/yahoojapan/gongt"
)

func main() {
	defer gongt.Get().SetIndexPath("assets/example").Open().Close()
	if errs := gongt.GetErrors(); len(errs) > 0 {
		panic(errs)
	}

	fmt.Printf("Dimension: %d\n", gongt.GetDim())

	query := []float64{12, 17, 21, 18, 17, 31, 33, 25, 26, 19, 42, 31, 25, 26, 49, 30, 19, 23, 29, 29, 22, 19, 28, 27, 28, 19, 13, 12, 25, 21, 25, 21, 35, 12, 44, 36, 19, 49, 104, 33, 29, 77, 43, 36, 28, 44, 90, 46, 52, 37, 65, 42, 33, 40, 104, 103, 44, 26, 50, 43, 18, 20, 48, 68, 28, 16, 104, 27, 6, 36, 98, 327, 53, 81, 40, 36, 61, 104, 44, 27, 42, 84, 55, 54, 49, 53, 28, 27, 103, 42, 27, 28, 24, 53, 60, 66, 7, 42, 14, 6, 32, 69, 15, 3, 4, 79, 27, 7, 30, 82, 26, 3, 15, 27, 18, 6, 19, 52, 21, 16, 104, 72, 30, 40, 22, 36, 19, 22}

	results, err := gongt.Search(query, 10, gongt.DefaultEpsilon)

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	for i, r := range results {
		fmt.Printf("Rank %d\n", i+1)
		fmt.Printf("  ID: %d\n", r.ID)
		fmt.Printf("  Distance: %f\n", r.Distance)
	}
}
result
$ go run example.go
Dimension: 128
Rank 1
  ID: 2892
  Distance: 273.355072
Rank 2
  ID: 2138
  Distance: 274.874512
Rank 3
  ID: 2422
  Distance: 276.372925
Rank 4
  ID: 1586
  Distance: 277.263428
Rank 5
  ID: 679
  Distance: 277.564392
Rank 6
  ID: 1564
  Distance: 278.792023
Rank 7
  ID: 2594
  Distance: 281.176086
Rank 8
  ID: 2159
  Distance: 281.895386
Rank 9
  ID: 2738
  Distance: 282.876312
Rank 10
  ID: 318
  Distance: 283.339020

License

Copyright (C) 2017 Yahoo Japan Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributor License Agreement

This project requires contributors to agree to a Contributor License Agreement (CLA).

Note that only for contributions to the gongt repository on the GitHub (https://github.com/yahoojapan/gongt), the contributors of them shall be deemed to have agreed to the CLA without individual written agreements.

Authors

Kosuke Morimoto
kpango

Documentation

Overview

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

Index

Examples

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

	// DefaultDimension is 0
	DefaultDimension = 0
	// DefaultCreationEdgeSize is 10
	DefaultCreationEdgeSize = 10
	// DefaultSearchEdgeSize is 10
	DefaultSearchEdgeSize = 40
	// DefaultObjectType is Float
	DefaultObjectType = Float
	// DefaultDistanceType is L2
	DefaultDistanceType = L2
	// DefaultEpsilon is 0.01
	DefaultEpsilon = 0.01
	// DefaultBulkInsertChunkSize is 100
	DefaultBulkInsertChunkSize = 100
	// DefaultPoolSize is 1
	DefaultPoolSize = 1

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

Variables

View Source
var (

	// ErrCAPINotImplemented raises using not implemented function in C API
	ErrCAPINotImplemented = errors.New("Not implemented in C API")
)

Functions

func BulkInsert

func BulkInsert(vecs [][]float64) ([]int, []error)

BulkInsert returns NGT object ids. This only stores not indexing, you must call CreateIndex and SaveIndex.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Bulk Insert
	vectors := [][]float64{
		{1, 0, 0, 0, 0, 0},
		{0, 1, 0, 0, 0, 0},
		{0, 0, 1, 0, 0, 0},
		{0, 0, 0, 1, 0, 0},
		{0, 0, 0, 0, 1, 0},
		{0, 0, 0, 0, 0, 1},
		{1, 1, 0, 0, 0, 0},
	}
	ids, errs := gongt.BulkInsert(vectors)

	_, _ = ids, errs
}
Output:

func BulkInsertCommit

func BulkInsertCommit(vecs [][]float64, poolSize int) ([]int, []error)

BulkInsertCommit returns NGT object ids. This stores and indexes at the same time.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Bulk Insert And Commit
	vectors := [][]float64{
		{1, 0, 0, 0, 0, 0},
		{0, 1, 0, 0, 0, 0},
		{0, 0, 1, 0, 0, 0},
		{0, 0, 0, 1, 0, 0},
		{0, 0, 0, 0, 1, 0},
		{0, 0, 0, 0, 0, 1},
		{1, 1, 0, 0, 0, 0},
	}
	ids, errs := gongt.BulkInsertCommit(vectors, gongt.DefaultPoolSize)

	_, _ = ids, errs
}
Output:

func Close

func Close()

Close NGT index.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Close NGT
	gongt.Close()
}
Output:

func CreateAndSaveIndex

func CreateAndSaveIndex(poolSize int) error

CreateAndSaveIndex call CreateIndex and SaveIndex in a row.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Create And Save Index
	gongt.CreateAndSaveIndex(10)
}
Output:

func CreateIndex

func CreateIndex(poolSize int) error

CreateIndex creates NGT index.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Create Index
	gongt.CreateIndex(10)
}
Output:

func GetDim

func GetDim() int

GetDim returns NGT dimension

dimension := gongt.GetDim()
Example
package main

import (
	"fmt"

	"github.com/yahoojapan/gongt"
)

func main() {
	// Fetch Dimension Size
	gongt.SetIndexPath("assets/example").Open()
	dim := gongt.GetDim()
	fmt.Println(dim)
}
Output:

128

func GetErrors

func GetErrors() []error

GetErrors returns errors

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Close NGT
	errs := gongt.GetErrors()

	_ = errs
}
Output:

func GetPath

func GetPath() string

GetPath returns path to index directory

indexPath := gongt.GetPath()
Example
package main

import (
	"fmt"

	"github.com/yahoojapan/gongt"
)

func main() {
	// Fetch Path Location
	gongt.SetIndexPath("assets/example").Open()
	path := gongt.GetPath()
	fmt.Println(path)
}
Output:

assets/example

func GetStrictVector

func GetStrictVector(id uint) ([]float32, error)

GetStrictVector is C type stricted GetVector function.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Get Vector
	vec, err := gongt.GetStrictVector(1)

	_, _ = vec, err
}
Output:

func GetVector

func GetVector(id int) ([]float64, error)

GetVector returns vector stored in NGT index.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Get Vector
	vec, err := gongt.GetVector(1)

	_, _ = vec, err
}
Output:

func Insert

func Insert(vec []float64) (int, error)

Insert returns NGT object id. This only stores not indexing, must execute CreateIndex and SaveIndex.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Insert
	vector := []float64{1, 0, 0, 0, 0, 0}
	id, err := gongt.Insert(vector)

	_, _ = id, err
}
Output:

func InsertCommit

func InsertCommit(vec []float64, poolSize int) (int, error)

InsertCommit returns NGT object id. This stores and indexes at the same time.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Insert
	vector := []float64{1, 0, 0, 0, 0, 0}
	id, err := gongt.InsertCommit(vector, 10)

	_, _ = id, err
}
Output:

func Remove

func Remove(id int) error

Remove removes from NGT index.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Remove Vector
	gongt.Remove(8)
}
Output:

func SaveIndex

func SaveIndex() error

SaveIndex stores NGT index to storage.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Save Index
	gongt.SaveIndex()
}
Output:

func StrictInsert

func StrictInsert(vec []float64) (uint, error)

StrictInsert is C type stricted insert function

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Strict Vector Insert
	vector := []float64{1, 0, 0, 0, 0, 0}
	id, err := gongt.StrictInsert(vector)

	_, _ = id, err
}
Output:

func StrictRemove

func StrictRemove(id uint) error

StrictRemove is C type stricted remove function

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Remove Vector
	gongt.StrictRemove(8)
}
Output:

Types

type DistanceType

type DistanceType int

DistanceType is alias of distance type in NGT

type NGT

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

NGT is gongt base struct

func Get

func Get() *NGT

Get returns singleton instance NGT

ngt := gongt.Get()
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Fetch Singleton GoNGT instance
	ngt := gongt.Get()

	_ = ngt
}
Output:

func New

func New(indexPath string) *NGT

New returns NGT instance

ngt := gongt.New("index Path")
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Instantiate GoNGT
	ngt := gongt.New("assets/example")

	_ = ngt
}
Output:

func Open

func Open() *NGT

Open configures using Property and returns NGT instance

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Bulk Insert Chunk Size
	ngt := gongt.Open()

	_ = ngt
}
Output:

func SetBulkInsertChunkSize

func SetBulkInsertChunkSize(size int) *NGT

SetBulkInsertChunkSize sets insert chunk size

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Bulk Insert Chunk Size
	gongt.SetBulkInsertChunkSize(5)
}
Output:

func SetCreationEdgeSize

func SetCreationEdgeSize(size int) *NGT

SetCreationEdgeSize sets creation edge size

gongt.SetCreationEdgeSize(10) // CreationEdgeSize Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Creation Edge Size
	gongt.SetCreationEdgeSize(30)
}
Output:

func SetDimension

func SetDimension(dimension int) *NGT

SetDimension sets NGT feature dimension

gongt.SetDimension(10) // Dimension Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Dimension
	gongt.SetDimension(128)
}
Output:

func SetDistanceType

func SetDistanceType(dt DistanceType) *NGT

SetDistanceType sets distanc

gongt.SetDistanceType(gongt.L1) // DistanceType Setting
gongt.SetDistanceType(gongt.L2) // DistanceType Setting
gongt.SetDistanceType(gongt.Hamming) // DistanceType Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Distance Type
	gongt.SetDistanceType(gongt.L2)
}
Output:

func SetIndexPath

func SetIndexPath(path string) *NGT

SetIndexPath sets path to index directory

gongt.SetIndexPath("index Path")
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Fetch Path Location
	gongt.SetIndexPath("/tmp/index-path")
}
Output:

func SetObjectType

func SetObjectType(ot ObjectType) *NGT

SetObjectType sets object type

gongt.SetObjectType(gongt.Float) // ObjectType Setting
gongt.SetObjectType(gongt.Uint8) // ObjectType Setting
gongt.SetObjectType(gongt.ObjectNone) // ObjectType Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Object Type
	// gongt.SetObjectType(gongt.Uint8) // ObjectType Setting
	// gongt.SetObjectType(gongt.ObjectNone) // ObjectType Setting
	gongt.SetObjectType(gongt.Float)
}
Output:

func SetSearchEdgeSize

func SetSearchEdgeSize(size int) *NGT

SetSearchEdgeSize sets search edge size

gongt.SetSearchEdgeSize(10) // SearchEdgeSize Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Search Edge Size
	gongt.SetSearchEdgeSize(10)
}
Output:

func (*NGT) BulkInsert

func (n *NGT) BulkInsert(vecs [][]float64) ([]int, []error)

BulkInsert returns NGT object ids. This only stores not indexing, you must call CreateIndex and SaveIndex.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Bulk Insert
	vectors := [][]float64{
		{1, 0, 0, 0, 0, 0},
		{0, 1, 0, 0, 0, 0},
		{0, 0, 1, 0, 0, 0},
		{0, 0, 0, 1, 0, 0},
		{0, 0, 0, 0, 1, 0},
		{0, 0, 0, 0, 0, 1},
		{1, 1, 0, 0, 0, 0},
	}
	ids, errs := gongt.Get().BulkInsert(vectors)

	_, _ = ids, errs
}
Output:

func (*NGT) BulkInsertCommit

func (n *NGT) BulkInsertCommit(vecs [][]float64, poolSize int) ([]int, []error)

BulkInsertCommit returns NGT object ids. This stores and indexes at the same time.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Bulk Insert And Commit
	vectors := [][]float64{
		{1, 0, 0, 0, 0, 0},
		{0, 1, 0, 0, 0, 0},
		{0, 0, 1, 0, 0, 0},
		{0, 0, 0, 1, 0, 0},
		{0, 0, 0, 0, 1, 0},
		{0, 0, 0, 0, 0, 1},
		{1, 1, 0, 0, 0, 0},
	}
	ids, errs := gongt.Get().BulkInsertCommit(vectors, gongt.DefaultPoolSize)

	_, _ = ids, errs
}
Output:

func (*NGT) Close

func (n *NGT) Close()

Close NGT index.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Close NGT
	gongt.Get().Close()
}
Output:

func (*NGT) CreateAndSaveIndex

func (n *NGT) CreateAndSaveIndex(poolSize int) error

CreateAndSaveIndex call CreateIndex and SaveIndex in a row.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Create And Save Index
	gongt.Get().CreateAndSaveIndex(10)
}
Output:

func (*NGT) CreateIndex

func (n *NGT) CreateIndex(poolSize int) error

CreateIndex creates NGT index.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Create Index
	gongt.Get().CreateIndex(10)
}
Output:

func (NGT) GetDim

func (n NGT) GetDim() int

GetDim returns NGT dimension

dimension := gongt.Get().GetDim()
dimension := gongt.New("Index Path").GetDim()
Example
package main

import (
	"fmt"

	"github.com/yahoojapan/gongt"
)

func main() {
	// Fetch Dimension Size
	gongt.SetIndexPath("assets/example").Open()
	dim := gongt.Get().GetDim()
	fmt.Println(dim)
}
Output:

128

func (*NGT) GetErrors

func (n *NGT) GetErrors() []error

GetErrors returns errors

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Close NGT
	errs := gongt.Get().GetErrors()

	_ = errs
}
Output:

func (NGT) GetPath

func (n NGT) GetPath() string

GetPath returns path to index directory

indexPath := gongt.Get().GetPath()
indexPath := gongt.New("index path").GetPath()
Example
package main

import (
	"fmt"

	"github.com/yahoojapan/gongt"
)

func main() {
	// Fetch Path Location
	gongt.SetIndexPath("assets/example").Open()
	path := gongt.Get().GetPath()
	fmt.Println(path)
}
Output:

assets/example

func (*NGT) GetStrictVector

func (n *NGT) GetStrictVector(id uint) ([]float32, error)

GetStrictVector is C type stricted GetVector function.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Get Vector
	vec, err := gongt.Get().GetStrictVector(1)

	_, _ = vec, err
}
Output:

func (*NGT) GetVector

func (n *NGT) GetVector(id int) ([]float64, error)

GetVector returns vector stored in NGT index.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Get Vector
	vec, err := gongt.Get().GetVector(1)

	_, _ = vec, err
}
Output:

func (*NGT) Insert

func (n *NGT) Insert(vec []float64) (int, error)

Insert returns NGT object id. This only stores not indexing, you must call CreateIndex and SaveIndex.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Insert
	vector := []float64{1, 0, 0, 0, 0, 0}
	id, err := gongt.Get().Insert(vector)

	_, _ = id, err
}
Output:

func (*NGT) InsertCommit

func (n *NGT) InsertCommit(vec []float64, poolSize int) (int, error)

InsertCommit returns NGT object id. This stores and indexes at the same time.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Insert
	vector := []float64{1, 0, 0, 0, 0, 0}
	id, err := gongt.Get().InsertCommit(vector, 10)

	_, _ = id, err
}
Output:

func (*NGT) Open

func (n *NGT) Open() *NGT

Open configures using Property and returns NGT instance

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Bulk Insert Chunk Size
	ngt := gongt.Get().Open()

	_ = ngt
}
Output:

func (*NGT) Remove

func (n *NGT) Remove(id int) error

Remove removes from NGT index.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Remove Vector
	gongt.Get().Remove(8)
}
Output:

func (*NGT) SaveIndex

func (n *NGT) SaveIndex() error

SaveIndex stores NGT index to storage.

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Save Index
	gongt.Get().SaveIndex()
}
Output:

func (*NGT) Search

func (n *NGT) Search(vec []float64, size int, epsilon float64) ([]SearchResult, error)

Search returns search result as []SearchResult

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Vector Search
	vector := []float64{1, 0, 0, 0, 0, 0}
	res, err := gongt.Get().Search(vector, 1, gongt.DefaultEpsilon)

	_, _ = res, err
}
Output:

func (*NGT) SetBulkInsertChunkSize

func (n *NGT) SetBulkInsertChunkSize(size int) *NGT

SetBulkInsertChunkSize sets insert chunk size

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Bulk Insert Chunk Size
	gongt.Get().SetBulkInsertChunkSize(5)
}
Output:

func (*NGT) SetCreationEdgeSize

func (n *NGT) SetCreationEdgeSize(size int) *NGT

SetCreationEdgeSize sets creation edge size

gongt.Get().SetCreationEdgeSize(10) // CreationEdgeSize Setting
gongt.New("").SetCreationEdgeSize(10) // CreationEdgeSize Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Creation Edge Size
	gongt.Get().SetCreationEdgeSize(30)
}
Output:

func (*NGT) SetDimension

func (n *NGT) SetDimension(dimension int) *NGT

SetDimension sets NGT feature dimension

gongt.Get().SetDimension(10) // Dimension Setting
gongt.New("Index Path").SetDimension(10) // Dimension Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Dimension
	gongt.Get().SetDimension(128)
}
Output:

func (*NGT) SetDistanceType

func (n *NGT) SetDistanceType(dt DistanceType) *NGT

SetDistanceType sets distance type

gongt.Get().SetDistanceType(gongt.L1) // DistanceType Setting
gongt.Get().SetDistanceType(gongt.L2) // DistanceType Setting
gongt.Get().SetDistanceType(gongt.Hamming) // DistanceType Setting
gongt.New("").SetDistanceType(gongt.L1) // DistanceType Setting
gongt.New("").SetDistanceType(gongt.L2) // DistanceType Setting
gongt.New("").SetDistanceType(gongt.Hamming) // DistanceType Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Distance Type
	gongt.Get().SetDistanceType(gongt.Hamming)
}
Output:

func (*NGT) SetIndexPath

func (n *NGT) SetIndexPath(path string) *NGT

SetIndexPath sets path to index directory

gongt.Get().SetIndexPath("index Path")
gongt.New("").SetIndexPath("index Path")
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Fetch Path Location
	gongt.Get().SetIndexPath("/tmp/index-path")
}
Output:

func (*NGT) SetObjectType

func (n *NGT) SetObjectType(ot ObjectType) *NGT

SetObjectType sets object type

gongt.Get().SetObjectType(gongt.Float) // ObjectType Setting
gongt.Get().SetObjectType(gongt.Uint8) // ObjectType Setting
gongt.Get().SetObjectType(gongt.ObjectNone) // ObjectType Setting
gongt.New("").SetObjectType(gongt.Float) // ObjectType Setting
gongt.New("").SetObjectType(gongt.Uint8) // ObjectType Setting
gongt.New("").SetObjectType(gongt.ObjectNone) // ObjectType Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Object Type
	// gongt.Get().SetObjectType(gongt.Uint8) // ObjectType Setting
	// gongt.Get().SetObjectType(gongt.ObjectNone) // ObjectType Setting
	gongt.Get().SetObjectType(gongt.Float) // ObjectType Setting
}
Output:

func (*NGT) SetSearchEdgeSize

func (n *NGT) SetSearchEdgeSize(size int) *NGT

SetSearchEdgeSize sets search edge size

gongt.Get().SetSearchEdgeSize(10) // SearchEdgeSize Setting
gongt.New("").SetSearchEdgeSize(10) // SearchEdgeSize Setting
Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Set Search Edge Size
	gongt.Get().SetSearchEdgeSize(10)
}
Output:

func (*NGT) StrictInsert

func (n *NGT) StrictInsert(vec []float64) (uint, error)

StrictInsert is C type stricted insert function

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Strict Vector Insert
	vector := []float64{1, 0, 0, 0, 0, 0}
	id, err := gongt.Get().StrictInsert(vector)

	_, _ = id, err
}
Output:

func (*NGT) StrictRemove

func (n *NGT) StrictRemove(id uint) error

StrictRemove is C type stricted remove function

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Remove Vector
	gongt.Get().StrictRemove(8)
}
Output:

func (*NGT) StrictSearch

func (n *NGT) StrictSearch(vec []float64, size int, epsilon, radius float32) ([]StrictSearchResult, error)

StrictSearch is C type stricted search function

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Strict Vector Search
	vector := []float64{1, 0, 0, 0, 0, 0}
	res, err := gongt.Get().StrictSearch(vector, 1, gongt.DefaultEpsilon, 0.9)

	_, _ = res, err
}
Output:

type ObjectType

type ObjectType int

ObjectType is alias of object type in NGT

type Property

type Property struct {
	Dimension           int
	CreationEdgeSize    int
	SearchEdgeSize      int
	ObjectType          ObjectType
	DistanceType        DistanceType
	IndexPath           string
	BulkInsertChunkSize int
}

Property includes parameters for NGT

type SearchResult

type SearchResult struct {
	ID       int
	Distance float64
}

SearchResult is struct for comfortable use in Go

func Search(vec []float64, size int, epsilon float64) ([]SearchResult, error)

Search returns search result as []SearchResult

type StrictSearchResult

type StrictSearchResult struct {
	ID       uint32
	Distance float32
	Error    error
}

StrictSearchResult is struct with same type in NGT core

func StrictSearch

func StrictSearch(vec []float64, size int, epsilon, radius float32) ([]StrictSearchResult, error)

StrictSearch is C type stricted search function

Example
package main

import (
	"github.com/yahoojapan/gongt"
)

func main() {
	// Strict Vector Search
	vector := []float64{1, 0, 0, 0, 0, 0}
	res, err := gongt.StrictSearch(vector, 1, gongt.DefaultEpsilon, 1.1)

	_, _ = res, err
}
Output:

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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