Register now: AI in Financial Services: Unlocking insights with Graph RAG webinar - April 24th

26: Improving the schema26: Improving the schema
Surrealist Placeholder
Surrealist Placeholder
Back to Courses

26: Improving the schema

The Designer view inside Surrealist is able to show the link between the town and place tables, but the other regular tables and graph tables are just floating around on top. You can experiment for yourself by pasting all of our queries so far into Surrealist, which should give you the following view.

The database schema so far which contains a number of new regular and graph tables that have not been defined yet and thus display as unconnected to the others

At the moment, the relation tables in particular are vulnerable because they have not been defined as relation tables. Without this definition, a regular works_at table could be created and the database would accept it.

CREATE works_at SET name = ...

This can be fixed by using DEFINE TABLE along with three clauses:

  • TYPE RELATION to ensure that it can only be used as a graph table,
  • IN record_name OUT record_name to set the record types that can be used, and
  • OVERWRITE after DEFINE TABLE , because currently the existing tables are defined as schemaless, non-relation tables. Without OVERWRITE , the database will return an error saying that the table already exists.

Since we have four graph relations set up, four DEFINE TABLE statements will be enough to improve the schema output.

DEFINE TABLE OVERWRITE works_at TYPE RELATION IN person OUT place; DEFINE TABLE OVERWRITE wrote TYPE RELATION IN person OUT book; DEFINE TABLE OVERWRITE has TYPE RELATION IN place OUT book; DEFINE TABLE OVERWRITE customer_of TYPE RELATION IN person OUT place;

Surrealist is now able to say for sure that these tables are used for relations, which allows all the types inside the schema to be joined together.

The database schema so far now that each table has been defined, allowing Surrealist to understand the connections between each one