I feel like I’m losing my mind. Let me start off by saying in a Ruby, not Python or Java developer. Let me also say I’ve never done anything with NLM or AI dev before, so most of these posts are confusing as heck. Tbh, I feel like there is a massive chasm between the dev world and those that get this stuff and those that get this stuff just assume the rest of us can figure it out.
With that said, after watching YouTube videos reading Reddit posts and medium articles I decided to just ask Claude and ChatGPT the following - “explain to me from a high level how to search a Postgres database using an NLM or AI”.
They both came back with basically the same thing:
-
Send your db schema to the AI with an explanation of each table and column and association
-
Send your prompt and ask the AI to generate. A SQL query.
-
Run that query against your database.
Love it. Makes sense, doesn’t require me to send my massive db in some odd format to the AI and is manageable. But I had questions.
Specifically I asked:
- how do I send the schema to the AI? What format?
- if I send the schema every time it’s going to cost a fortune. What can I do?
- how do I train the AI if the sql being returned is not producing the correct results? Do I need to do that every time?
The AI came back and told me:
-
You can create a json, yaml or OpenAI representation of your schema and gave me the representation based on my db schema, which I saved to a file and augmented with descriptions and associations.
-
You post this formatted representation to OpenAI to create a context embedding. You will get an id to reference in future api calls.
-
When you make an API to the completion endpoint, tell the AI to use those embeddings, which won’t count against your tokens.
4 use fine tuning to create an augmented version of the ai model that is trained by submitting a file with example
Prompts and the correct sql. You’ll get a model id you can then use for the next completion call, or better, you can create a model alias to use that you can keep updating the tuning for.
Love love love it. Makes so much send. Tell the AI about your db, store that knowledge with the AI, reference it when sending prompts, use an augmented version of the AIs model that you keep training over time.
It even gave me code to use.
Here’s the problem - it appears to all be wrong.
There is no context embedding endpoint in OpenAI, just an embedding endpoint that doesn’t accept my json representation. When I send it as text I get back an array of numbers, which I know are embedding but are longer than the original schema representation. No embedding is to use.
When I call the completions endpoint there is no embedding atttribute I can use to send the embeddings (or phantom embedding id).
And finally there is no way to fine tune the model to create an augmented version that understands my data of the open ai model. At least nothing I can find.
And every darn search I do is super confusing or points to a “recipe” for generating sql from your schema in the OpenAI cookbook that doesn’t exist.
So what happened here? Why is the AI sending me on insanely frustrating wild goose chases? How can I actually figure this out?
Thank you for helping a true LLM newbie gain some sanity.