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.
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.
# Alternatively, you can add all models: ddn model add <connector_link_name> "*"
ddn model add <connector_link_name> <collection_name>
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.
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.
ddn connector introspect <connector_name>
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 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
ddn model remove users
In addition to removing the Model
object itself, the CLI will also remove the associated metadata definitions.
Next steps
- If you've added your first model, check out commands for writing data next.
- You can learn more about models in the metadata reference docs.