SQL Data Query


⚠️ Outdated or Deprecated Documentation ⚠️

This documentation is outdated and may not reflect the current state of the SymbolicAI library. This page might be revived or deleted entirely as we continue our development. We recommend using more modern tools that infer the documentation from the code itself, such as DeepWiki. This will ensure you have the most accurate and up-to-date information and give you a better picture of the current state of the library.


Click here for interactive notebook

import os
import warnings
warnings.filterwarnings('ignore')
print(os.getcwd())
from symai import *
from IPython.display import display
from examples.sql import SQL
sql = SQL()

The SQL expression is defined and passes as a global context the syntax of the SQL language. The SQL expression is then used to generate queries based on the given context. We can then use the generated queries to get data from a database. The following query is sent to the neural computation engine and creates a query based on the given context:

val = None
def _fun(x):
    global val
    val = x
Symbol._metadata.input_handler = _fun

We can now try to further manipulate the result by asking the model to incorporate additional information, such as filtering to a specific time range:

We can also try to remove unwanted fields from the generated query. Notice how the model tries to remove not only the given statement but attributes associated with them:

And we can now even convert our query to other familiar domain specific languages, such as SQL or ActiveRecord:

To wrap things up, we might want to go back full circle and ask the model to generate again the explanation based on the given query:

Ask it in natural language to modify the query:

Even translate the explanation to a different language on the fly:

Fixing the query on the fly if something goes wrong or the user quickly wants to adapt a query:

Last updated