Skip to main content
Version: PromptQL

Read Data

Introduction

PromptQL uses models to access and interpret data from your sources.

These models can be tables, views, collections, or native queries. They help PromptQL understand the data's structure and meaning. This understanding allows PromptQL to create accurate query plans and extract valuable insights from your data.

An example model for a users table:
kind: Model
version: v2
definition:
name: users
description: |
Represents people who have registered for the app. This model stores core info like:
- name
- email
- ID
Along with any other metadata tied to the user. It’s often the starting point for building
relationships with other models—things like sessions, subscriptions, or audit logs.
objectType: users
source:
dataConnectorName: operations
collection: users

Other metadata exists when you create a model, but this is the core object for reading data from a data source.

Lifecycle

Create a model

To add a model you will need to have a data connector which has already introspected the data source. Follow the relevant tutorial in How to Build with PromptQL to get to that point.

Add your model by passing the connector's and model's names:
# Alternatively, you can add all models: ddn model add <connector_link_name> "*"

ddn model add <connector_link_name> <collection_name>
Not sure which models you have?

You can see a list of all available resources using the CLI:

ddn connector show-resources <connector_name>

For each model, you'll find an HML file included in the relevant metadata directory for your connected data source.

You can now create a build, serve it, and begin having meaningful conversations with the data it represents through PromptQL. With robust models in place, PromptQL can create dynamic query plans that accurately address your requests and provide deep insights into your data.

Context for CLI commands

Note that the above CLI commands work without also adding the relevant subgraph to the command with the --subgraph flag because this has been set in the CLI context. You can learn more about creating and switching contexts in the CLI context section.

Update a model

If you want to update your model to reflect a change that happened in the underlying data source you should first introspect to get the latest resources and then update the relevant model.

Re-introspect your data source:
ddn connector introspect <connector_name>
Then, update your existing model:
ddn model update <connector_link_name> <model_name>

You will see an output which explains how new resources were added or updated in the model.

You can now create a build, serve it, and continue interacting with the data it represents using PromptQL, which will automatically adjust its query plans based on the updated model definitions.

You can manually edit metadata!

You can also update the model by manually editing the metadata. To avoid errors, we recommend using the VS Code extension to validate your changes.

Delete a model

If you no longer need a model, you can delete it:
ddn model remove users

In addition to removing the Model object itself, the CLI will also remove the associated metadata definitions.

Next steps