Server module

The server class is used to predict triples or statements, or find similar entities on the model.

Server class

Here is shown all the different methods to use with Server class

class kgeserver.server.Server(search_index)[source]

The server can perform prediction operations

distance_between_entities(entity_x, entity_y)[source]

Gives the distance between two different elements

Parameters:
  • entity_x (integer) – One entity to be compared
  • entity_y (integer) – Other entity to be compared
Returns:

The distance between two elements

Return type:

float

similarity_by_embedding(embedd, k, search_k=-1)[source]

For a given embedding, return most similar id’s

Parameters:
  • embedd (list) – An embedding vector
  • k (int) – The similar entities shown for each entity
Returns:

A list with k id’s, which are the most similar entities

Return type:

list

similarity_by_id(id, k, search_k=-1)[source]

Given an entity id, return the k’th most similar entities

Returns a list of pairs, where the first item is the entity and the second item is the distance to entity.

Parameters:
  • id (int) – The entity id
  • k (int) – The entities to show
Returns:

A list with k id’s, which are the most similar entities

Return type:

list of pairs

similarity_by_vector(vector, k)[source]

For each id in vector, return a list with k similar entities

Parameters:
  • vector (list) – A list with entity id’s
  • k (int) – The similar entities shown for each entity
Returns:

a matrix array [][]

Return type:

list

SearchIndex Class

This class is used to provide an extra layer to the server. Can perform loads and savings to disk of the index.

Here is shown all the different methods to use with SearchIndex class

class kgeserver.server.SearchIndex[source]

The search index manages search indexes on disk

This support creating indexes and operations to save/load to/from disk

build_from_trained_model(trained_model, depth)[source]

Creates an index from a trained model

Parameters:
  • trained_model (TrainedModel) – The trained model
  • depth (int) – The depth desired to generate the search index
load_from_file(filepath, emb_size)[source]

Load the search tree from a file on disk

Parameters:
  • filepath (string) – The path where the file will be saved
  • emb_size (int) – The size of embedding vector used
Returns:

If operations had or not errors

Return type:

boolean

save_to_binary(filepath)[source]

Dump the search tree on a file on disk

Parameters:filepath (string) – The path where the file will be saved
Returns:If operations had or not errors
Return type:boolean