Arize AI
Search…
Querying Nested Data
This tutorial will show you how to query for nested data and collections
Now that you know how to form basic queries using the node concept from the previous page, we will show you how to query nested collections of data. This is a very powerful concept that will allow you to quickly traverse the data objects in Arize without stopping to gather id's at every step.
This example will show you how to find all of the triggered monitors and their models within your space. The benefit of GraphQL is that the skills you learn in this tutorial will apply to all other object relationships.
We highly recommend that you type out these examples (with your own IDs) in the API explorer directly.
The explorer helps with autocompletion and will help you contextualize your queries. In the explorer, navigate to the Documentation Explorer on the right to find the exact fields for each object.

Querying collections

1. Start with the space

Grab your node id for you space from the browser (e.x. /spaces/:space_id), as described in the previous section
Request
Response
query {
node(id: ":space_id") {
... on Space {
name
}
}
}
{
"data": {
"node": {
"name": "test_space"
}
},
"extensions": {
"tracing": {
"startTime": "2022-06-14T21:39:53.186Z",
"endTime": "2022-06-14T21:39:53.192Z",
"duration": 6
}
}
}

2. Get the model connection in your space:

Now, let's get the models for your space. There is a models property on space. This returns an edge, which is a container for the actual model (which is considered a node). There is a lot to unpack here, but first we'll show the example:
Request
Response
query {
node(id: ":space_id"){
... on Space {
models(first: 2) {
totalCount
edges {
cursor
node {
name
}
}
}
}
}
}
{
"data": {
"node": {
"models": {
"totalCount": 5,
"edges": [
{
"cursor": "YXJyYXljb25uZWN0aW9uOjA=",
"node": {
"externalModelId": "arize-demo-churn-prediction-use-case"
}
},
{
"cursor": "YXJyYXljb25uZWN0aW9uOjE=",
"node": {
"externalModelId": "arize-demo-click-through-rate-use-case"
}
}
]
}
}
}
}tab

Here are the components:

  • models(first: 2){ totalCount }: models returns a connection. A connection can be thought of as a "container" for a collection of results as well as metadata. In this example, we requested the totalCount of the collection. Connections also can take arguments. Here we only request the first 2 models. There are also custom arguments or filters in addition to standard pagination-related arguments, for example: models(search: "arize-demo").
  • edges { cursor }: Connections return edges. Edges are like a container for each element in the collection, and also contain metadata. In this case, we returned the cursor field on the edge, which can be used for pagination like this models(first:2, after: "YXJyYXljb25uZWN0aW9uOjE=").
  • node { name }: Finally, we get to the actual model and its fields. Note that most objects in our system implement the node interface (as described on the previous page). This particular node is of the type Model and has the field name which is the modelId that was used to ingest the model.

3. Get only triggered monitors

Finally, we can go one level deeper and get the monitors on each model. Additionally, we'll use the arguments to filter only for triggered models.
Note: you can also query for monitors on a space. We are just using space -> models to as an example of a deeply nested query. This is also helpful if you wanted to search for specific models in a space before getting their monitors.
Request
Response
query {
node(id: ":space_id"){
... on Space {
models(first: 1) {
edges {
node {
name
monitors(first: 1, currentStatus: triggered) {
edges {
node {
name
threshold
currentMetricValue
operator
}
}
}
}
}
}
}
}
}
{
"data": {
"node": {
"models": {
"edges": [
{
"node": {
"externalModelId": "arize-demo-churn-prediction-use-case",
"monitors": {
"edges": [
{
"node": {
"name": "Model Drift for delinq_2yrs",
"threshold": 0.000164044030786001,
"currentMetricValue": "0.00043",
"operator": "greaterThan"
}
}
]
}
}
}
]
}
}
}
Here we use the argument monitors(currentStatus: triggered) (note triggered is not a string, it is an enum and should not be in quotes) to denote that we only want to view triggered monitors. Now we can view the operator, the current value of the metric and the threshold, and the current threshold.

What's next?

After you get more comfortable querying for collections and using the Documentation Explorer, you'll be querying the rest of your data in no time.
In the next section, we'll show you how to update your data through mutations.
Having trouble? Reach out to us via email [email protected] or Slack us in the #arize-support channel for more support.
Copy link
Outline
Querying collections
1. Start with the space
2. Get the model connection in your space:
3. Get only triggered monitors
What's next?