About the Semantic Graph Index Data Model

The Semantic Graph Index has an object-oriented data model. Unlike an SQL database, which uses tables, the Semantic Graph Index uses classes like object-oriented programming languages. It supports inheritance between classes and references between objects.

This page discusses:

See Also
Configuring an Index Unit Storage

Classes and Attributes

Being object-oriented the Semantic Graph Index data model uses classes. A class can inherit from one or more classes. Use a single inheritance when possible. A class is made of attributes.

Example:

class Person {
    firstName : String
    lastName : String
    size : Integer
}

As you can see in this example, attributes have types. The supported types are:

Primitive type Collection type
  • Binary
  • Boolean
  • Date
  • DateTime
  • Decimal
  • Float
  • Geo
  • Integer
  • HierarchicalString
  • LocalDateTime
  • String
  • Text
  • TimeSeries - For more information, see Time Series.
  • Reference - For more information, see Reference Type.
  • Embedding - For more information, see Embedding.

Default Class

The default class is Item. This type is the equivalent of Object in Java. When you declare a class without a parent, it inherits from the Item class.

class Item {
    @RootClass
    uri: ItemUri
    class: ItemClass
    self: Binary
    text: FullTextSearch
    source: String
    stamp: String
}

The most important element in this class is the uri attribute. Fill this attribute (with a string) when pushing the item. It identifies the Item uniquely within an index unit.

Reference Type

The Reference type allows you to connect objects together.

Important: Use Reference attributes as much as possible to connect objects. Joins on string, integer, etc. are possible but slower. Yet, the Semantic Graph Index limits references to the scope of one index unit. Cross index unit references are impossible. Use traditional JOIN in that case.

Example:

class Company {
    name : String
    description : Text
}

class Employee : Person {
    employeeId : Integer
    company : Reference<Company>
}

In this example, the Reference type has a parameter, which is the Item type that the Reference targets. When pushing the items, you must use the uri of the targeted item.

Important: The Semantic Graph Index indexes Reference attributes, which means that the query engine can traverse and reverse references efficiently.

In our example, it means that from a Company, you can efficiently retrieve all the employees of the company, even if the Reference is in the Employee class.

Standard graph traversal is faster than reverse traversal, but with this ability to traverse the Reference both ways, you can put the Reference attribute in the type that fits the best.

In our example, the Reference is in the Employee class to simplify the update. There is no need to repush the Company class every time an employee is added or deleted.

Structure Attributes (Collection, List, and Map Types)

The data model supports several "structure" attribute types: Collection, List, and Map.

The List type is an ordered collection. You can access elements by their index.

The Collection type is like a List type but it does not necessarily conserve the order for optimization reasons.

class Factory {
    name : String
    location : Geo
}

class Company {
    name : String
    description : Text
    factories : Collection<Factory>
}

The Map type is similar to a Map in Java or javascript. It is a key / value structure. As the key must be a string, you can configure the Map type according to the value only.

Use the Map type when you cannot create an attribute per key. This can occur when you define the data model but do not know what is the set of keys, or if the set of keys is open. For example, pictures captured by digital devices (scanner, camera) often contain EXIF or IPTC metadata. These formats are open and require a Map.

class Photo {
    filename : String
    content : Binary
    exif : Map<String>
}
Important: You cannot mix the use of primitive types (for example, integers and strings) in Map values.

However, you can specify advanced attribute types, like:

class Person {
    firstName : String
    lastName : String
    size : Integer
    relationships : Map<List<Reference<Person>>>
}

Packages

A class is part of a package. Packages are similar to Java packages, and used as namespaces. The pair made of the package name and the class name identifies the class. It is therefore possible to have 2 classes with the same name in 2 different packages. When referencing a class outside of the current package, you must use its full name.

class Company {
    name : String
    description : Text
    factories : Collection<manufacturing.Factory>
}

Embedding

The Semantic Graph Index can store embeddings, using the Embedding data model type.

Technically, an embedding is an array of float32, generated by transforming data (text, images, etc.) into vectors. The goal of embedding models is to return vectors "close to each other" for two objects that carry the same semantics. A similarity function gives the proximity between two vectors. The Semantic Graph Index includes 3 built-in similarity functions: cosine dot product, and euclidian.

To get good performance when searching vectors, it is better to build a vector index. To build such an index, you must annotate the Embedding attribute with one of the following annotations: Index Cosine Similarity, Index Dot Product Similarity, or Index Euclidian Similarity. These annotations define the similarity function to use.

Time Series

A time series is a series of data points. Each data point is the association of a timestamp with an Integer, Float, Decimal, String, or a Boolean value, in time order.

String and Boolean time series are useful to display more explicit labels than numerical values. For example, displaying enumerated strings with low, medium, and high is more explicit than displaying 0, 1, and 2. Similarly, displaying Boolean values with true or false is more readable than 0 or 1.

To display string values, you can define properties of type StringTimeSeries:

  • With an enumeration annotation (for example, low, medium, high) to both restrain the possible values and keep the order defined specified in the annotation. It can be useful to display values in a specific order on charts.
  • Without an enumeration annotation if you do not want to restrain the possible values and show values alphabetically.