Skip to content

Instantly share code, notes, and snippets.

@bobvanluijt
Created May 8, 2020 14:36
Show Gist options
  • Save bobvanluijt/51e5d392ece3ff29fbf8561a08d2aff9 to your computer and use it in GitHub Desktop.
Save bobvanluijt/51e5d392ece3ff29fbf8561a08d2aff9 to your computer and use it in GitHub Desktop.
Example of Weaviate vector generator
// takes an array of vectors and outputs a single mean vector
function meanVector(inputVectors) {
// sum up each dimension in a single “sum” vector
sums = new Array(dimensions(inputVectors))
for i = 0; i < dimensions(inputVectors); i ++ {
for j = 0; j < inputVectors.length(); j ++ {
sums[i] += inputVectors[j][i]
}
}
// divide sum by amount of vectors to get mean value
// for each dimension
return sums.map(sum => sum/inputVectors.length())
}
inputParts = input.splitOnNonAlphaNumericCharacters()
vectors = inputParts.map(word => getVectorForWord(word))
combinedVector = meanVector(vectors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment