store

package
v0.0.0-...-fc3e3b3 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrToBytes

func ArrToBytes(arr []float64) []byte

transforms N floats into N*8 bytes

func BytesToArray

func BytesToArray(arr []byte) []float64

Transforms N*8 bytes into N floats

func EuclideanDistance

func EuclideanDistance(x Vector, y Vector) float64

*

  • EuclideanDistance
  • Distance between two vectors x= <x_1, x_2, x_3> and y= <y_1, y_2, y_3>
  • is defined as {(x_1-y_1)²+(x_2-y_2)²+(x_3-y_3)²\}^{1/2}.

func Float64bytes

func Float64bytes(float float64) []byte

Transforms 8 bytes into a float

func Float64frombytes

func Float64frombytes(bytes []byte) float64

Transforms a float64 into 8 bytes

Types

type BranchDistance

type BranchDistance struct {
	Target   *branch
	Distance float64 //Distance
}

type Distance

type Distance struct {
	Target   Vector
	Distance float64 //Distance
}

* * Return structure for the kNN algorithm * holding the string as key, the vector for corresponding key and the distance

type Index

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

func LoadIndex

func LoadIndex(db *leveldb.DB, s *PersistantStore) *Index

func NewIndex

func NewIndex(db *leveldb.DB, store Store) *Index

func (*Index) AddVector

func (index *Index) AddVector(v Vector)

func (*Index) IndexKNN

func (index *Index) IndexKNN(k int, v Vector) (*[]Distance, error)

type MemoryVector

type MemoryVector struct {
	ID    string
	Array []float64
}

Vector is the main storage unit

func Ones

func Ones(id string, size int) *MemoryVector

Ones will return a Vector where all the values are equal to 1.0

func Random

func Random(id string, size int) *MemoryVector

Random will create a Vector with values in range (0,1)

func Zeros

func Zeros(id string, size int) *MemoryVector

Zeros will return a Vector where all the values are equal to 0.0

func (*MemoryVector) Name

func (v *MemoryVector) Name() string

func (*MemoryVector) Values

func (v *MemoryVector) Values() *[]float64

type PersistantStore

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

func ConstructPersistantStore

func ConstructPersistantStore(dimension uint32, indexFile, vectorsFile, searchindexFile string) *PersistantStore

Creates a new persistant store

func LoadPersistantStore

func LoadPersistantStore(dimension uint32, indexFile, vectorsFile, searchindexFiles string) *PersistantStore

Loads an existing store

func NewPersitantStore

func NewPersitantStore(dimension uint32, indexFile, vectorsFile, searchindexFile string) (*PersistantStore, error)

func (*PersistantStore) Delete

func (s *PersistantStore) Delete(id string) error

func (*PersistantStore) Get

func (s *PersistantStore) Get(id string) (Vector, error)

func (*PersistantStore) KNN

func (s *PersistantStore) KNN(vector Vector, k int) (*[]Distance, error)

func (*PersistantStore) ReadVector

func (s *PersistantStore) ReadVector(id string) ([]float64, error)

Reads the values of a vector from a given position

func (*PersistantStore) Set

func (s *PersistantStore) Set(id string, vector Vector) error

func (*PersistantStore) WriteVector

func (s *PersistantStore) WriteVector(v *[]float64, id string)

Writes the values of a vector in a given position in the file

type PersistantVector

type PersistantVector struct {
	ID string
	// contains filtered or unexported fields
}

func (*PersistantVector) Name

func (v *PersistantVector) Name() string

func (*PersistantVector) Values

func (v *PersistantVector) Values() *[]float64

type SimpleMapStore

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

SimpleMapStore implements the Store interface using a Go map

func NewSimpleMapStore

func NewSimpleMapStore() *SimpleMapStore

NewSimpleMapStore returns a new map store

func (*SimpleMapStore) Delete

func (s *SimpleMapStore) Delete(id string) error

Delete a given value from the store

func (*SimpleMapStore) Get

func (s *SimpleMapStore) Get(id string) (Vector, error)

Get Vector pointer using a given id, returns error if not found

func (*SimpleMapStore) KNN

func (s *SimpleMapStore) KNN(vector Vector, k int) (*[]Distance, error)

KNN returns the K nearest neighbours to a given vector This vector does not have to be inside the store.

func (*SimpleMapStore) Set

func (s *SimpleMapStore) Set(id string, vector Vector) error

Set Vector for a given id

type Store

type Store interface {
	Get(id string) (Vector, error)
	Set(id string, vector Vector) error
	Delete(id string) error
	KNN(vector Vector, k int) (*[]Distance, error)
}

Store is the defintion for the storage implementation requirements

type Vector

type Vector interface {
	Values() *[]float64
	Name() string
}

Jump to

Keyboard shortcuts

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