Application And Benchmark Queries

We have demonstrated the basic pattern match syntax. You should have mastered the basics by this point. The next step is to see more examples and practice more.

A Recommendation Application

In this example, we want to recommend some messages (comments or posts) to the person Viktor Akhiezer.

How do we do this?

One way is to find Others who likes the same messages Viktor likes. And then recommend the messages that Others like but Viktor have not seen. The pattern is roughly like below

  • Viktor - (Likes>) - Message - (<Likes) - Others

  • Others - (Likes>) - NewMessage

  • Recommend NewMessage to Viktor

However, this is too fine granularity, and we are overfitting the message level data with a collaborative filtering algorithm. The intuition is that two persons are similar to each other when their "liked" messages fall into the same category (tag). This makes more sense and common than finding two persons that "likes" the same set of messages. As a result, one way to avoid this overfitting is to go one level above. That is, instead of finding common messages as a similarity base, we find common messages' tags as a similarity base. Person A and Person B are similar if they like messages that belong to the same tag. This scheme fixes the overfitting problem. In pattern match vocabulary, we have

  • Viktor - (Likes>) - Message - (Has>) - Tag - (<Has) - Message - (<Likes) - Others

  • Others - (Likes>) - NewMessage

  • Recommend NewMessage to Viktor

GSQL. RecommendMessage Application.

This time, we create the query first, and interpret the query by calling the query name with parameters. If we are satisfied with this query, we can use "install query queryName" to get the compiled query installed which has the best performance.

You can copy the above GSQL script to a file named app1.gsql, and invoke this script file in linux command line.

Install the query

When you are satisfied with your query in the GSQL interpret mode, you can now install it as a generic service which has a much faster speed. Since we have been using "CREATE QUERY .." syntax, the query is added into the catalog, we can set the syntax version and install it.

The above use log-cosine as a similarity measurement. We can also use cosine similarity by using two persons liked messages.

LDBC SNB Benchmark Queries

We have made available all LDBC SNB benchmark queries translated into GSQL pattern matching syntax. The benchmark queries are described in Sections 4 and 5 of the LDBC Social Network Benchmark Reference.

You can find our GSQL pattern match translations of these queries on Github: https://github.com/tigergraph/ecosys/tree/ldbc/ldbc_benchmark/tigergraph/queries_pattern_match

Note we use CREATE/INSTALL/RUN QUERY instead of INTERPRET QUERY so that these queries can be optimized and installed as REST services. There are three sets of queries:

Also, you may want to use the GraphStudio UI to help you visualize and explore the graph and to try your hand at writing your own queries.