Back to main page

How to define Aito schema?

API:Schema

Concept

Aito's schema is similar to SQL's schema. The schema contains the tables' name, columns' name and values' type. It also contains additional meta-information about linking and the analysis of column values. This is important in order for Aito to perform well. These meta-information will be further explained in the sections below.

API endpoint

/api/v1/_schema

Structure

Available operations:

  1. Populate a new schema
  2. Delete an existing schema
  3. Delete an existing table (delete both information from the schema and data content from the database)

Aito's schema structure

  1. Example: { "schema": {

         "customers": {
           "type":"table",
           "columns": {
             "id"   : {"type": "Int" },
             "name" : {"type": "String" },
             "tags" : {"type": "Text", "analyzer": "Whitespace" }
           }
         },
    
         "products": {
           "type":"table",
           "columns": {
             "id"          : { "type": "Int" },
             "name"        : { "type": "String" },
             "title"       : { "type": "Text",  "analyzer": "English" },
             "tags"        : { "type": "Text",  "analyzer": "English" },
             "price"       : { "type": "Decimal"},
             "description" : { "type": "Text",  "analyzer": "English" }
           }
         },
    
         "messages": {
           "type":"table",
           "columns": {
             "id"         : { "type" : "Int" },
             "user"       : { "type" : "Int", "link":"customers.id" },
             "prev"       : { "type" : "Int", "nullable": true, "link":"this.id" },
             "message"    : { "type" : "Text", "analyzer": "English" },
             "operation"  : { "type" : "String" },
    
             "product"    : { "type" : "String", "nullable": true, "link":"products.name" },
             "tags"       : { "type" : "Text", "nullable":true, "analyzer": "English" },
             "response"   : { "type" : "String", "nullable":true, "analyzer": "English" }
           }
         },
    
         "impressions": {
           "type":"table",
           "columns": {
             "messageContext" : { "type": "Int", "nullable":true, "link": "messages.id" },
             "prevProduct" :    { "type": "Int", "nullable":true, "link": "products.id" },
             "customer" :       { "type": "Int", "link": "customers.id" },
             "product" :        { "type": "Int", "link": "products.id" },
             "query" :          { "type": "Text", "analyzer": "English" },
             "queryPhrase" :    { "type": "String" },
             "click" :          { "type": "Boolean" }
           }
         }
    
       }
     }
    
  2. Explanation:

    • The above schema defines 4 tables: customers, products, messages and impressions
    • "schema" : a map from table names to table definitions.
      • "type": the type of the schema object. Must be 'table', as only 'table' is currently supported.
      • "columns": a map from column names to column defitions
        • "type": type of variable in this column ("Int", "String", "Decimal", "Boolean" or "Text")
        • "nullable": true, if the column value can be 'null'
        • "analyzer": type of support analyzer to split values into features ("Default", "No", "Whitespace", "Standard", "Finnish", "English", "Swedish", "German")
          • Only supported for columns of type "Text".
          • E.g: the product description is in English and can use the English analyzer
      • "link": link this column to another column (can be from this table or another table). This helps Aito to take linked columns into consideration when performing smart operations
        • E.g: the customer in the impressions table can be linked to 'id' in customers table so when you perform smart operations in the impressions table, Aito takes into account the customers' information

Populate a new schema

To populate a new schema into Aito, send a PUT request to

<_your_env_url_>/api/v1/schema/

with the provided read-write api_key and the schema in json format as the content of the request

The training environment has already been populated with the schema

Delete an existing schema

Note: This will delete the entire database as well To delete an existing schema in Aito, send a DELETE request to

<_your_env_url_>/api/v1/schema/

with the provided read-write api_key and empty content

Delete an existing table

To delete an existing table from Aito's schema and from Aito's database, send a DELETE request to

<_your_env_url_>/api/v1/schema/<_table_name_>

with the provided read-write api_key and empty content

Repopulate a deleted table

After deleting the table, you can repopulate a new schema with the deleted table and repopulate the deleted table to recover it

NOTE: Current version of Aito does not support editing schema (E.g: update new link, update column type). Also, populating a new schema without table(s) does not delete the table(s) from the database The best practice is to delete the whole database (by delete schema), repopulate the updated schema, and repopulate the data content This will be improved soon in the near future