Have you ever considered where the border between program code and processed data is? Let's resolve this boundary by building a logic graph!
In the last articles you have learned what a graph is, how a chatbot can store knowledge inside it and how to read it out again. Today you will learn that a graph can do even more.
If you have already programmed something, you will know that a program code usually processes data in some form. The program receives data, processes it by using fixed procedures and then returns some new data. We can simply store such data as knowledge in form of nodes and edges in a graph. But a graph can do much more. It can also contain the program code itself. Just the connections between individual nodes are sufficient to describe a major part of the program. I call such a structure a logic graph. Because it contains not only knowledge data but also logical information on the graph level. This makes our program flexible and adaptive. It can even be easily built and customized visually.
What is a program actually?
To explain why data and program logic are not so easy to separate from another, let me first define the term "program":
A program is knowledge that describes when other data is valid and how it should be processed.
In other words this means that the instructions of a program ultimately consist only of knowledge or data. More precisely it's the knowledge about processing other data and when it is TRUE. At this point, the boundary between data and logic blurs. Because both are forms of knowledge, which can be described in a graph by simply using nodes and edges.
Logic gates in graph databases
The main part of a logic graph are logic gates. Look at the following graphic. You recognize three questions. Together with their possible answers, these represent static knowledge in the form of expertise. The connections between the answers and the next question at the bottom already define a part of the stored logic. In this case, either two answer options of the left question OR an answer possibility of the right question in the conversation must have been fulfilled, so that the third question makes sense at all.
By the way, we have defined a logical OR which is stored in the graph together with the expert data. Such a logical OR is a variant of a logic gate. Of course also AND gates are possible in which all incoming items are fulfilled or must be true.
In the course of this series, I will show you how far more complex but easy maintainable logical structures can be created by outsourcing the logic into separate nodes. That may look like this:
The processing of data is theoretically possible, too. For that, it’s quite enough to integrate tiny programs into our nodes. At this point, there is a huge overlap with the flow-based programming paradigm. In this domain, a program is described of nodes which contain program code and receive data via input edges and pass it via output edges.
Why not just separate program and data as before? As you now know, the program that processes the data is just a special kind of expert knowledge. By putting this together with the data to be processed in a database, new fascinating possibilities open up. The program becomes flexible. Not only data can be learned. Even the logic itself becomes flexible and can be learned. It also opens up a whole new way to make program code visible and designable. In addition, expert knowledge and logic are strongly interconnected in many cases. So in a classic program code, logic often only adapts to specific data formats or prepared patterns.
This article is one of a series of articles describing the construction of an open source chatbot builder. Because of the high complexity of possible conversational courses, chatbots, among many other technologies, are very well suited for mapping into logic graphs. Often you have to do cumbersome programming to create complex logic. Here the logic graph opens an elegant solution.
A logic graph makes sense wherever complex contexts need to be processed and where knowledge and logical structures need to be stored and maintained together. So a logic graph has many AI-related use cases in addition to chatbots.
In the next article, you'll learn how to execute the logic in your graph using logic graph traversal.