Text-to-query (GPT workbooks)

Gustav Staprans · Friday Demos · March 29, 2024 · 15:26

Text to query for free text data exploration on top of the data model, but inside the bounds of the data model

Transcript

This transcript is auto-generated. Names and product terms may be wrong.

  1. are demos I can demo on the AI train give me a second so Richard and I uh were also playing around with AI and we were trying to run queries or create queries in Omni uh using Ai and so I guess the simple prompt is can we LM how to write an omni query turns out we can and so I was going to kind of walk through a bit of the process there but instead I'm just going to jump into a demo because I think that's more fun um this is my local instance and so let's start from new so this is a first like first time query experience you'll notice there's a few things new on the page here one is this you can

  2. ask any question you want of your data and there's also these suggestions here here these suggestions look at your data model for this specific topic so it'll say like okay Distribution Center inventory items look at all your fields or all your dimensions and measures and it'll try to come up with some interesting questions you might want to ask of your data so for example uh this says inventory items available at e each Distribution Center helping Monitor and manage inventory levels across locations so let's give that one a try um um and so not only did it come up with the question it also actually crafted the query um to answer that question you can see that it's it's you know grabbing the right measures and

  3. right dimensions and under the hood it's not actually writing I mean you'll see some Omni SQL if you go to the SQL um but we decided not to write SQL and instead to actually create an omni query here and if we want to what we can do is we can actually come up here and extend this so like let's say um filter this by inventory that was added in the last I don't know last year and obviously you could just do this through the UI and it might be it would be faster um but it's going to think for a minute it's going to look at your existing query and then hopefully if the demo gods are kind to me you'll see that it um

  4. it actually goes and creates the appropriate filter for you here um and adjusts the results accordingly so that's the first piece of the demo um and if we come back in here um we can start asking some more generic questions um and so I have a few that I've somewhat pre-screened um and we'll just see how this goes um so the first one I want to ask is show me items that have been ordered the least just going to think for a minute um and this is somewhat helpful um but let's say I don't want the inventory Item ID instead I want the name so show me the item name and not the ID and it should be able to go and again update this

  5. query and give you a a new result back um so yeah now you can see here's the names and let's add a filter here and say show me that have been ordered more than five times just to show off a little bit more of the the filtering functionality and then yeah there we go so we added the filter um but now it's it's in the wrong sort order so let's say let's sort this by least ordered um instead of sorting top to bottom think for a minute hope we get the right answer uh so it looks like it blew away the filter there in that case so it's not always perfect sometimes it might um it might change things it shouldn't on the query um

  6. but it tends to actually be able to construct queries pretty successfully um so let's let's kind of maybe push this to the Limit now and uh let's ask the AI to show me inventory levels that each Distribution Center month over month for the past two years years so there's some filters in here there's some pivots in here um and let's see if uh the AI can figure this out looks like it got it so it has distribution center Broken Out month over month um and inventory items as well and you can um you can update this if you want to so you could say instead of month over month show me year over year I would expect it to come back and replace the pivot

  7. um on created at month with created at year instead so it can be kind of a oh go for it can I ask a question yeah what uh what do you what is the context window here like field names model what are you guys actually using behind the scenes yeah so that's a good question um so uh I have a slide here the context we passing in is the fields and measures on the current topic so basically the views and that shares the type uh the field the fully qualified field name the type uh whether or not it's an aggregate what type of aggregate it is if it's an aggregate um then we also pass in Sample questions which I will actually show off in

  8. just a second this is I probably where we saw the biggest gains where we can actually tweak the sample questions that we passed in um and then we also give it our entire filter syntax like all of our typescript types and some examples there so it knows how to properly craft filters um and on the let me share my vs code really quickly um on the sample questions um this was a fun exercise Richard and I did where we actually got on a whiteboard and we wrote out a bunch of questions so like states that sold the most products states that sold the most products in the last month states that sold the most products over the last month that are over $50 and then

  9. we ran the query by hand in Omni and then copied out the data structure for that so you can see here it has like Fields filters limits and sorts and we did this for I think probably like 15 or so questions with pivots um all sorts of different types of filters tons of fields in some of them um a few fields and other ones you pass this in with the context window so it knows kind of roughly what a an omni query looks like and what um what it can what it can use to actually construct the query um does that answer your question Colin yep sweet um what else um there was um a funny Quirk where we found out that it really really

  10. liked pivoting data um and when we originally trained it we gave it of the first 10 questions or questions and answers um we gave it one example with one pivot and it would come back and just be pivoting everything non-stop um and so we actually had to give it a lot more examples of like uh questions where um almost actually the example that I showed here where we try to basically pivot everything and we had to show up for questions like this actually you only want to Pivot one of the one of the two possible pivots um and it was able to pick that up another thing was that it really it was heavily restricting the limit always to be 10 and that was because

  11. we accidentally like I just copy and pasted 10 in as the limit for like four or five examples and so it just saw that and was like okay limit is always 10 no matter what um so we had to you know think more consciously about the limits and the examples as well um yeah and uh I guess some of the benefits that we we actually originally tried doing this with SQL um and so we would try to generate SQL so for example we'd run like show me orders by each email domain and it would say oh my model doesn't have an email domain field so let me go and like literally try to write a alter table um and run it and uh that was

  12. kind of the moment where like wait a minute we need to stop using SQL and instead um use the model to generate Omni queries because that just puts up a ton of guard rails and makes sure that it's generating valid SQL and it makes sure that you're staying within the the bounds of what you have access to in that specific topic that's it the alter table is terrifying this is amazing yeah um how reasonable is it to like put this up on playground and Omni internal like just to see I mean it's same question for the Vega thing like I'm just sort of curious what how launchable they are like even in very very raw form I think it would take a couple days um

  13. just the code is a hot mess but it all like it all works so I think we just want to clean it up for probably two or three days throw it on playground and yeah we could play around with it yeah because I I remember the first cut that we did at the llm thing when we tried to throw it up on uh internal we we couldn't ingest the whole data model so it was struggling under the weight of that yeah we need to get on real data so like putting it on Omni would be awesome just to make sure like as we contextualize it with you know some some of the topic information too just to see are we going to blow up the

  14. context windows uh you know tokens and stuff like you might need to put a topic picker in front of it actually to make the context Windows small enough but I'm just sort of curious like inra it too yeah there's a a funny quirk in the demo which you may have seen is I have to actually click the topic that I'm using um or else it just doesn't work at all um and so I don't know if that's sort of what you meant but no that's that actually could be a good thing um because like part of it is just that we want to isolate the problem a little bit and see if it solves it in like the isolated case and then we can sort

  15. of generalize it from there yeah so like you me I'm obsessed with like the filter thing like I'm really curious whether we could make it so you could just always type in text the filter and like we just construct the filter for you um that like that would be very very interesting to just use exclusively for a while yeah I actually have one more fun example that uh I was playing around with just this morning um so Richard's not here right now um but uh if he were around I might like to ask him uh how many jeans have you ordered in the last two years and I thought this was a fun query because it's going to add a bunch of filters on time

  16. it's gonna also add a filter on Richard as well okay I didn't select the topic let's select it and give it a shot dang okay so in this case it thought you wanted product name but you really want a product category um but this worked earlier as a as a fun little query that'll be able to pull out all sorts of different filters names um that that is super cool too I think even even just that that like flub is sort of interesting where you know how how can we provide better context to to the llm to be like maybe it's indexing certain values and uh you know sort of some of the rag techniques and the like that that sort of allow for you

  17. know us providing even more metadata about a column so that like we can say a category is comprised of these types of values or these example values if we don't want to do the whole thing but this is this is so cool yeah the one of the most surprising things is that it it fails very infrequently like it might not produce the right result or pick the right field but it it tends to actually not just fall over and not be able to produce an omni query very rarely at least in the internal testing we've done I think this is really awesome I think both demos really awesome uh question which which llm are we using and then if we thought about this practically would

  18. part of customer onboarding be that an analyst team go in and uh train this for you know a number of weeks like how many prompts did you guys put in to make this as accurate it as it is like because to me this is this is what gets the product super sticky for a business user is when you know your average salesperson can go in use a chat interface to generate the you know the the the the the tables and the charts that they need like that becomes hyper hyper sticky so um statement of Awesomeness and and that goes for the Vega charts too and I'm curious like what's behind the scenes and what level of effort and like where would we see this becoming

  19. a part of an onboarding process yeah good questions it's using Chad chbt 4.0 um which I don't actually think is the best one for this anymore I think Claude 3 is much better at code generation um and so there's like maybe some discussion should we make it more generic so you can can use different models but right now all like our infrastructures pin the chat GPT um as far as the training data there were ended up being 12 examples to get this far um and yeah we I think the most challenging thing is like one thing is having the the actual Omni query and the result but then we needed to label it with what with the question to go along with it um and

  20. so like it would be great if you could just look at the last 10 queries or 20 queries someone did and shove those in the context window but you don't necessarily know what natural language question they're trying to ask um so maybe there's some sort of labeling customers can do and then add that to the context window um to train it this would be a great thing Greg for maybe at the end of the bik code and teams andt partners for them to like test this for us uh and then they could package this together as like an offering um because they're already starting to do that this this is so amazing yeah super cool how expensive do we assume this might get if we're

  21. using GPT 4 um it got pretty pretty expensive when we were at source graph we're doing this very naively and I would say it's like a few cents per query that you run right now um but the suggestions page is actually where it gets like pretty bad we're jamming a lot more to the suggestions page and so it takes almost like 30 seconds to load that without being cashed and then means like every time you load that blink screen even if you don't ask a question loading those suggestions is going to be like 20 cents or 30 cents yeah okay cool th this these are down the road problems as we think about margin and pricing and packaging and this is awesome yeah we did

  22. talk about adding like an input where someone can put in their own uh credentials their own keys for their whatever LM they want to use um to circumvent this problem