public inbox for [email protected]  
help / color / mirror / Atom feed
From: Allan Kamau <[email protected]>
To: Postgres General Postgres General <[email protected]>
Subject: Formulating SQL queries via Retrieval Augmented Generation (RAG).
Date: Tue, 10 Dec 2024 15:59:00 +0300
Message-ID: <CAF3N6oQ4GeF93L34FJ=E5GoYBHXv7H4H0gK4FANgv=fHORoN4Q@mail.gmail.com> (raw)

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


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Formulating SQL queries via Retrieval Augmented Generation (RAG).
  In-Reply-To: <CAF3N6oQ4GeF93L34FJ=E5GoYBHXv7H4H0gK4FANgv=fHORoN4Q@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox