Created
May 8, 2020 14:36
-
-
Save bobvanluijt/51e5d392ece3ff29fbf8561a08d2aff9 to your computer and use it in GitHub Desktop.
Example of Weaviate vector generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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