Member-only story

AI’nt That Easy #18: Text-to-SQL, RAG, and TAG Explained

Four approaches — Text-to-SQL, RAG, RAG over Tabular Data, and TAG — each offer unique advantages depending on your use case

Aakriti Aggarwal
7 min readOct 5, 2024

Natural Language Processing (NLP) has come a long way, especially with the integration of large language models like GPT-4. One of the most exciting developments is how these models can now interact with both structured and unstructured data to answer queries in a more human-friendly way. But with so many approaches out there, how do you decide which one to use?

In this post, we’ll explore four cutting-edge techniques — Text-to-SQL, Retrieval Augmented Generation (RAG), RAG over Tabular Data, and Table-Augmented Generation (TAG) — and show you how each of them works through code examples. Whether you’re looking to query a database, retrieve knowledge, or combine the two, you’ll find the right tool for the job here.

Setting the Stage

To keep things practical, let’s assume we have a simple inventory of laptops stored in a database and some extra knowledge about those products in a knowledge base. Our task is to answer a common question:

What is the top-selling laptop and why might it be popular?

We’ll use Python and GPT-4 for each of the following approaches. Here’s the basic setup:

from openai import OpenAI…

--

--

No responses yet