Awesome Open Source
Awesome Open Source

GitHub release Discord Discussion Forum Stack Overflow Stack Overflow

TypeDB KGLIB (Knowledge Graph Library)

KGLIB provides tools to enable machine learning with TypeDB.

This library is under development and will henceforth be transformed into primarily infrastructure tools and integrations between TypeDB and machine learning libraries.

Machine Learning Pipeline

Flow Diagram

The pipeline provided helps by allowing us to extract subgraphs from TypeDB. Each subgraph is a training example, which are sent to the learner in batches. Algorithms using this approach are scalable since they do not need to hold the whole graph in memory for training.

The pipeline is as follows:

  1. Extract data from TypeDB into Python NetworkX in-memory subgraphs by specifying multiple TypeQL queries.
  2. Encode the nodes and edges of the NetworkX graphs
  3. Either (a) transform the encoded values into features, ready for input into a graph/geometric learning pipeline (for example the upcoming PyTorch implementation); or (b) Embed the encoded values according to the Types present in your database (TensorFlow only, PyTorch coming soon). This type-centric embedding is crucial to extracting the context explicitly captured in TypeDB's Type System.
  4. Feed the features to a learning algorithm (see below)
  5. Optionally, store the predictions made by the learner in TypeDB. These predictions can then be queried using TypeQL. This means we can trivially run more learning tasks over the knowledge base, including the newly made predictions. This is knowledge graph completion.

Learning Algorithms

This repo contains one algorithmic implementation: Knowledge Graph Convolutional Network (KGCN). This is a generic method for relation predication over any TypeDB database. There is a full worked example and an explanation of how the approach works.

You are encouraged to use the tools available in KGLIB to interface TypeDB to your own algorithmic implementations, or to use/leverage prebuilt implementations available from popular libraries such as PyTorch Geometric or Graph Nets (TensorFlow/Sonnet).


You may find the following resources useful:



  • Python >= 3.6, <= 3.7.x (TensorFlow 1.14.0 doesn't support later Python versions).

  • KGLIB installed via pip: pip install typedb-kglib.

  • TypeDB 2.1.1 running in the background.

  • typedb-client-python 2.1.0 (PyPi, GitHub release). This should be installed automatically when you pip install typedb-kglib.

Run the Example

Take a look at Knowledge Graph Convolutional Networks (KGCNs) to see a walkthrough of how to use the library.

Building from source

It's expected that you will use Pip to install, but should you need to make your own changes to the library, and import it into your project, you can build from source as follows.

Clone KGLIB:

git clone [email protected]:vaticle/kglib.git

Go into the project directory:

cd kglib

Build all targets:

bazel build //...

Run all tests. Requires Python 3.6+ on your PATH. Test dependencies are for Linux since that is the CI environment:

bazel test //kglib/... --test_output=streamed --spawn_strategy=standalone --action_env=PATH

Build the pip distribution. Outputs to bazel-bin:

bazel build //:assemble-pip


To follow the development conversation, please join the Vaticle Discord, and join the #kglib channel. Alternatively, start a new topic on the Vaticle Discussion Forum.

KGLIB requires that you have migrated your data into a TypeDB or TypeDB Cluster instance. There is an official examples repo for how to go about this, and information available on migration in the docs. Alternatively, there are fantastic community-led projects growing in the TypeDB OSI to facilitate fast and easy data loading.

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Python (809,126
Machine Learning (37,207
Graph (24,367
Tensorflow (22,362
Artificial Intelligence (18,924
Neural Network (15,534
Knowledge Base (997
Knowledge Graph (949
Graph Convolutional Networks (223
Link Prediction (103
Geometric Deep Learning (85
Knowledge Graph Completion (37
Graph Networks (33
Relational Learning (20
Grakn (10
Graql (4