Skip to content

Instantly share code, notes, and snippets.

@bobvanluijt
Created June 5, 2018 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobvanluijt/52d6ea01ccea7f36ffbd601855d1537a to your computer and use it in GitHub Desktop.
Save bobvanluijt/52d6ea01ccea7f36ffbd601855d1537a to your computer and use it in GitHub Desktop.
Example of additional functions
// Opaque type that models an index number used to identify a word.
type ItemIndex int
func (*ItemIndex i) IsPresent() {
return i >= 0
}
// Opque type that models a fixed-length vector.
type Vector {
vector []float32
}
// Map of structs with vectors and weights
type VectorWeightMap []struct {
weight float32
vectors Vector
}
// API to decouple the K-nn interface that is needed for Weaviate from a concrete implementation.
type VectorIndex interface {
// Return the number of items that is stored in the0
GetNumberOfItems() (int, err)
// Returns the length of the used vectors.
GetVectorLength() (int, err)
// Look up a word, return an index.
// Check for presence of the index with index.IsPresent()
WordToItemIndex(word string) (ItemIndex, err)
// Based on an index, return the assosiated word.
ItemIndexToWord(ItemIndex) (string, err)
// Get the vector of an item index.
GetVectorForItemIndex(item ItemIndex) (Vector, err)
// Compute the distance between two items.
GetDistance(a ItemIndex, b ItemIndex) (Vector, err)
// Get the n nearest neighbours of item, examining k trees.
// Returns an array of indices, and of distances between item and the n-nearest neighbors.
GetNnsByItem(item ItemIndex, n int, k int) ([]ItemIndex, []float32, err)
// Get the n nearest neighbours of item, examining k trees.
// Returns an array of indices, and of distances between item and the n-nearest neighbors.
GetNnsByVector(vector Vector, n int, k int) ([]ItemIndex, []float32, err),
// Get the centroid based on provided vectors and the weight.
// The a argument is used to choose a centroid calculation algorithm.
// https://en.wikipedia.org/wiki/Centroid#Locating_the_centroid
GetCentroidByVectorWeights(vectorWeightMap VectorWeightMap, a string) (Vector, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment