src.KNN.faissKNN module¶
-
class
src.KNN.faissKNN.KNNService¶ Bases:
PyQt5.QtCore.QObjectThe KNN microservice
- Parameters
QObject (QObject) – So that we can use QT signal/slots
-
calculateFinalVector(sentence)¶ Calculate the semantic request, for example king-man+woman
- Parameters
sentence (string) – the linalg expression (or single words)
- Returns
The calculated word vector
- Return type
resultedVector
-
checkWords(wordList, wordDict)¶ Check whether all words are found in the file in
- Parameters
wordList ([string]) – List of words used in the requested
wordDict (dict{string,[float]}) – List of words found in the file with corresponding vectors
- Returns
Whether all words have been found
- Return type
Bool
-
clearVariables()¶ Clear all the variables to default (TODO, find more clean way of doing this)
-
getAllDistances(request, context)¶
-
getKNNBatch(request, context)¶ Gets the kNN for a batch of vectors.
- Parameters
request (gRPC) – standard gRPC (contains the messages)
request.vectors ([Vector]) – the vectors of which the kNN must be returned
request.k (int) – number of nearest neighbours that should be returned per vector
context (gRPC) – standard gRPC
- Returns
- NeighboursBatch.neighbours contains Row objects with the nearest neighbours.
This is in order of the vectors given.
- Return type
-
getKNNRequest(request, context)¶ Implementation for gRPC message to connect to for the general requests
- Parameters
request (gRPC) – standard gRPC (contains the messages)
context (gRPC) – standard gRPC
- Returns
gRPC message containing the words and distances
- Return type
grpc Neighbours objects
-
getProgress(request, context)¶ Implementation for the getProgress gRPC requset
- Parameters
request (gRPC) – standard gRPC (contains the messages)
context (gRPC) – standard gRPC
- Returns
contains the integer of current progress
- Return type
grPC progressKNN
-
getVectors(wordList)¶ Find the vector per word in the given datafile
- Parameters
wordList ([word]) – List of used words
- Returns
The dictionary of word, wordVector combinations
- Return type
Dict
-
getWords(indicesSorted)¶ Searches and returns the words/labels of indices.
- Parameters
indicesSorted ([int]) – indices of vectors of which labels must be found in ascending order
- Raises
Exception – throws a exception when requested index was not found in file
- Returns
string}: contains the indices as key and requested labels as values
- Return type
{int
-
knnVector(vector, k)¶ Use the index object to extract closest words / distances and
- Parameters
vector ([float]) – The calculated word vector
k (int) – How many neighbours we want to
- Returns
gRPC message containing the words and distances
- Return type
neighbours
-
printClosest(indices, wordsDict, distances)¶ For debugging, print the results of the KNN request
- Parameters
indices ([[int]]) – 2d list of the closest indices
distances ([[float]]) – 2d list of distances to closest words (specified in indices)
-
progressSignal¶
-
startKNNService(request, context)¶ Setup the KNN serive
- Parameters
request (gRPC) – standard gRPC (contains the messages)
context (gRPC) – standard gRPC
- Returns
returns void
- Return type
gRPC empty
-
stopKNNService(request, context)¶ Stop the current service
- Parameters
request (gRPC) – standard gRPC (contains the messages)
context (gRPC) – standard gRPC
- Returns
grPC void
-
trainKNN()¶ Train the KNN with the given filePath
-
updatePercentage()¶ Recalculate the current percentage
-
src.KNN.faissKNN.printMessage(message)¶ Print the coloured message so that we can see in the output which microservice printed it
- Parameters
message (string) – The actual message
-
src.KNN.faissKNN.serveServer()¶ Setup the GRPC server