Open AI querying database

  • Goal: To use ChatGPT 4 to query data held in retool (to allow user to ask for key information like "how many GPs can I reach in Germany"

  • Steps: I've connected my OpenAI account and connected to my account, but cannot see how to give it access to the database.

HI @Andrew_Hastie, Thanks for the question!

Retool AI can automatically include context from Retool Vectors in the LLM input. That's different than "giving access" to your database. Here's the official docs and I'll try to describe it a bit: Retool Vectors | Retool Docs
Retool Vectors quickstart | Retool Docs

Retool Vectors is separate from your normal SQL database resource. Retool Vectors stores blobs of text that you upload to it, whether that's from from public URLs or Documents you upload directly. More specifically, Retool Vectors converts that text into embeddings (array of decimals) and it stores those embeddings so later on it can measure the distance from your inputs to all the text it knows about.

When you make a new AI Action query from the Code tab, Retool Vectors can provide more context to the chat. This is not quite "throwing the whole database into the prompt" because only relevant text in the Vector storage gets embedded in the prompt. Retool AI Actions + Retool Vectors is the fastest way to inject context into AI queries, *assuming you have all that text in Retool Vectors.

See the bottom of this screenshot where I include the Retool AI docs with my query:

To give the AI your data "directly from your database," you'd use prompt engineering to send a formatted prompt where you describe your data, and what you're looking for, and then {{inject}} the data into the prompt in a way you think the LLM will "understand." This is the more direct way to work with LLMs because you're making the prompt more verbose in some areas and more concise in others to get the desired response.

Some combination of the two (Prompt Engineering + Retool Vectors) plus Retool's flexible LLM options should fit most AI use cases.

Let me know if you have questions!

Dan K
Retool TAM