Does data volume has any effect on API consumption for LangChain + OpenAI API to generate SQL queries?

I have a table in a MySQL database with 300K records, and I plan to build a chatbot that accepts natural language queries, turn that into SQL, queries the database, and comes up with the results. Does the data volume affect the OpenAI API consumption?

What are some optimisations I can do to minimise the API calls? One idea I thought of is to save all the questions and their corresponding SQL queries. Whenever a person asks a natural language question, use the saved SQL query instead of generating a new one. Any other ideas from people who tried text to sql?

explore prompt caching from langchain
https://python.langchain.com/en/latest/modules/models/llms/examples/llm_caching.html

You will only incur the cost of the tokens used in the prompt, and the resulting model output. You could of course cache the results and store them in a lookup table for later use.

SQL queries are typically ran once on the data, unless there are chain of thought tasks being performed it should just be the once per SQL transaction.

1 Like