Using the app
About the Functions available in the app
Upon installing the native app, a new database is created in Snowflake under the application name you chose during installation. This database includes a schema named datadotworld_api, containing a range of functions and stored procedures that simplify the use of data.world functionality.
When you open a worksheet in Snowsight or launch a Streamlit-in-Snowflake app, you can expand this database to view the functions and their signatures.
Important
Any of these functions, when used, will utilize the data.world API token supplied during the app installation process.
Add_table
Allows you to add a table to a data.world project or dataset to make virtualized, federated dwSQQL or SPARQL queries into.
Parameter name | Description |
---|---|
Owner | Organization ID that owns the dataset you want to add a table to. |
Dataset_id | Dataset or project ID that will house the virtualized table. |
connection_id | The data.world database connection to use for virtualization. |
table_db | Snowflake database name. |
table_schema | Snowflake schema. |
Table_name | Snowflake table name to virtualize into the project or dataset. |
Ask_question
Calls the data.world AI Context Engine answerTool API. If you have not set up a data.world project as a container for the Context Engine, also allows the use of demo mode so you can test building data applications using the data.world AI Context Engine.
Parameter name | Description |
---|---|
Owner | Organization ID that owns the dataset housing AI Context Engine configuration. |
project_id | Project ID that has the tables to ask questions about virtualized and configured for AI Context Engine use. |
Nl_question | The natural language question to ask of your data. |
Demo_mode | Puts the API in demo mode where the AI Context Engine will generate valid sample API responses with synthetic data regardless of actual configuration state of the Context Engine. |
Create_connection
Create a database connection to virtualize datasets between data.world and Snowflake. Virtual connections will allow users to write federated dwSQL or SPARQL graph queries between data inside Snowflake and other data sources and allow the AI Context Engine to query data as well. Using this function requires the API token.
Parameter name | Description |
---|---|
Owner | The data.world organization ID that the connection will be associated with. |
Connection_name | A name for the connection in the data.world UI. |
Host | The host address for the database connection. Use your Snowflake account URL. |
Connection_type | Use SNOWFLAKE. |
Username | The snowflake account username you’d like to access the connection using. |
Password | The password for the account. |
Optional_params | For a Snowflake connection, pass a JSON object (or variant) with the key database and the value set to the Snowflake database name you wish to access over this connection. |
Create_dataset
Create a data.world dataset that can be used to host virtualized tables and make SPARQL or dwSQL queries against.
Parameter name | Description |
---|---|
Owner | The organization or user ID that will be the owner of the dataset in data.world. |
Title | The title of the dataset. It will be used to create the ID. |
Visibility | OPEN - usable by all members of the owning organization or PRIVATE - usable by only the owner and users the owner shares with. |
Optional_parameters | Additional parameters to pass to the dataset such as licensing etc. See the data.world api docs for more details. |
Get_datasets
Gets a list of data.world datasets that the API token provided to the app has access to in the given organization.
Parameter name | Description |
---|---|
Owner | The organization whose datasets to list. |
Get_orgs
Gets a list of data.world organizations that the API token provided to the app has access. There are no parameters for this function.
Get_projects
Gets a list of data.world projects that the API token provided to the app has access to in the given organization.
Parameter name | Description |
---|---|
Owner | The organization whose projects to list. |
Get_user
Get details on the user object associated with the API token provided to the application. Can be used to check if the API token can authenticate to the data.world application. There are no parameters for this function.
Run_sparql_query
Run a SPARQL query against the organization and dataset or project context provided in the call. We suggest calling format_response to appropriately turn the response into a table structure immediately after.
Parameter name | Description |
---|---|
Owner | The organization context for the query. Determines what projects or datasets are available for the query. |
Dataset_id | The dataset or project ID to run the query against. |
Query | The query text to use. Must be a SPARQL select query. You cannot use a SPARQL describe from inside Snowflake. |
Run_sql_query
Run a dwSQL query against the organization and dataset or project context provided in the call. We suggest calling format_response to appropriately turn the response into a table structure immediately after.
Parameter name | Description |
---|---|
Owner | The organization context for the query. Determines what projects or datasets are available for the query. |
Dataset_id | The dataset or project ID to run the query against. |
Query | The query text to use. Must be a dwSQL select query. |
Format_response
A convenience function that will take the results of a run_sparql_query or run_sql_query call and format the results in an easy to parse variant/json format.
Parameter name | Description |
---|---|
Response | The response from a run_sparql_query or run_sql_query call. |
Calling Functions from Python or Streamlit
The functions and procedures from the native app can be easily called from a Python Worksheet or Streamlit-in-Snowflake app inside Snowsight.
Following is an example call to the ask_question function in a Streamlit:
with st.form("chat_tab_form"): st.info("Enter a question to interact with data.world's AI context engine.", icon="ℹ️") # give the user a radio option to toggle demo mode demo_mode = st.radio("Demo Mode", ["On", "Off"], key="chat_tab_demo_mode", index=1, help="Toggle demo mode to see the AI context engine in action") question = st.text_area("Question", key="chat_tab_question", help="Enter a question to ask the AI context engine") submitted = st.form_submit_button("Submit Question") if submitted: # submit the question dataset_id = app_state["selected_dataset"] org_id = app_state["selected_org"] demo_mode = True if demo_mode == "On" else False query_sql = f"""SELECT datadotworld_api.ask_question( owner => ? , project_id => ? , nl_question => ? , demo_mode => ? )""" response = session.sql(query_sql, params=[owner, project_id, nl_question, demo_mode]).collect()[0][0] # convert the response to a dict answer_response = json.loads(response) # display the results to the userx answer = answer_response.get('answer') st.subheader('AI Context Engine Response') st.write(f"**Answer:**") if 'error' in answer.lower(): .error(f'Error: {answer_response.get("answer")}') return st.caption(answer) st.write('**SPARQL Query:**') st.code(answer_response.get('sparql'), language='sparql') if answer_response.get('terms'): st.write('**Terms Used:**') terms = pd.DataFrame(answer_response.get('terms')) terms = terms.rename(columns={'term': 'Term', 'definition': 'Definition', 'iri': 'data.world Link'}) # change column order terms = terms[['Term', 'Definition', 'data.world Link']] st.dataframe(terms)
Calling Functions from Worksheets
Functions can also be from SQL worksheets inside Snowsight.
Following is an example call to the ask_question API from the worksheet:
-- ask question SELECT PARSE_JSON(DATADOTWORLD_PLUGIN_APP.DATADOTWORLD_API.ASK_QUESTION( owner => 'global', project_id => 'chat-with-our-data', nl_question => 'How many users do we currently have?', demo_mode => True ));
Accessing the App in Snowsight
Along with the Functions, the application contains a Streamlit based UI that can be accessed from Snowsight.
To access the app:
In Snowsight, browse to Data Products > Apps.
Click the Connector tab to view the data.world Catalog and AI Context Engine Plug-In.
Configuration tab: This tab allows you to verify the successful authentication of your provided token with data.world. Moreover, you can establish database connections between data.world and Snowflake, create new datasets and projects, and add tables to virtualize from Snowflake to data.world projects or datasets.
Query tab: This tab enables you to run dwSQL or SPARQL queries within Snowflake. These queries can span across datasets, and it also allows you to execute graph SPARQL queries against relational data hosted in Snowflake.
Chat tab: This tab allows you to test the data.world AI Context Engine AnswerTool API endpoint within the scope of a dataset or project.