Formulating SQL queries via Retrieval Augmented Generation (RAG). - Mailing list pgsql-general

From Allan Kamau
Subject Formulating SQL queries via Retrieval Augmented Generation (RAG).
Date
Msg-id CAF3N6oQ4GeF93L34FJ=E5GoYBHXv7H4H0gK4FANgv=fHORoN4Q@mail.gmail.com
Whole thread Raw
List pgsql-general
I am not sure if this is the right place to post a PostgreSQL + Retrieval Augmented Generation (RAG) question, but I have tried other sites but I did not receive any response.

I have managed to use RAG to query data in a PostgreSQL table using Python and the lanchain_community module.

But I have been struggling for weeks trying to find a solution to using RAG to perform WITH RECURSIVE CTE on two tables (modeling node and edge graph data).
The SQL queries generated by RAG for this graph data model are error prone.
Is there an example somewhere where RAG has been used to successfully generate WITH RECURSIVE CTE on two table graph data?

Below is the main code section I am using to perform RAG on PostgreSQL.

    llm = ChatGroq(model="mixtral-8x7b-32768", temperature=0);        chain = (        RunnablePassthrough.assign(query=sql_chain).assign(            schema=lambda _: db.get_table_info(),            response=lambda vars: db.run(vars["query"]),        )        | prompt        | llm    )    response_obj: langchain_core.messages.ai.AIMessage=chain.invoke({        "question": user_query_str,        "chat_history": chat_history_list,    });


Any pointers are welcome.

-Allan

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Errors when restoring backup created by pg_dumpall
Next
From: Felipe Matas
Date:
Subject: Clusters and shared permissions using LDAP