Download README.md from muddasser/trace_RAG: direct link, hf CLI and curl.
- Browser
- Download file 4.13 kB
-
https://huggingface.co/spaces/muddasser/trace_RAG/resolve/main/README.md
- Command line
-
hf download hf://spaces/muddasser/trace_RAG/README.md
-
curl -L -o README.md https://huggingface.co/spaces/muddasser/trace_RAG/resolve/main/README.md
A newer version of the Gradio SDK is available: 6.30.0
title: Trace RAG
emoji: π
colorFrom: red
colorTo: red
sdk: gradio
sdk_version: 5.9.1
python_version: '3.11'
app_file: app.py
pinned: false
Text-to-SQL Trace RAG β Prototype (Gradio / HF Spaces)
A minimal prototype of reasoning-trace RAG applied to retail BI queries.
Instead of retrieving documents/facts, this retrieves verified past question β SQL β reasoning examples and uses them as few-shot patterns to guide new SQL generation. Built for repeat-shaped BI questions ("total X by Y for period Z", "top N by metric", "compare A vs B").
Runs as a Gradio app β deploys directly on HuggingFace Spaces' free Gradio SDK. (Docker Spaces are no longer free on HF, so this version drops the Dockerfile entirely.)
How it works
TRACE_LIBRARYholds verified past questions with their correct SQL and the reasoning steps that produced it.- Each question is embedded with
sentence-transformersand indexed in FAISS. - A new question is embedded, FAISS retrieves the most structurally similar past example(s).
- Those examples are inserted into the prompt as exemplars β the model (via Groq) reuses the query-building pattern, not just column names.
- The generated SQL runs against a DuckDB table and returns real results.
- A second tab lets you manually confirm a generated query was correct and add it back into the trace library β this is how the library compounds over time.
This is the same retrieve β augment β generate mechanism as normal RAG. The only difference is what gets indexed: solved query patterns instead of documents.
Files
app.pyβ Gradio app (toy DuckDB table + FAISS index + Groq generation- UI to grow the trace library)
requirements.txtβ pinned dependencies (includesgradio)README.mdβ this file
Run locally
pip install -r requirements.txt --break-system-packages
export GROQ_API_KEY=your_key_here
python app.py
Opens at http://127.0.0.1:7860.
Deploy on HuggingFace Spaces (free, no Docker)
- Create a new Space β SDK: Gradio (not Docker).
- Upload
app.pyandrequirements.txtto the Space repo (matches your usual HF Spaces deployment pattern). - Go to Settings β Repository secrets on the Space and add:
GROQ_API_KEY= your Groq key
- Space builds automatically and launches
app.py.
No Dockerfile needed β Spaces installs requirements.txt and runs
app.py directly on the Gradio SDK runtime.
Making this real (not a toy)
- Replace the toy
salestable inapp.pywith a real extract of your actual schema (or connect DuckDB to your real source instead of the in-memoryCREATE TABLEblock). - Replace
TRACE_LIBRARYwith your team's actual most-common BI question shapes. Hand-verify the correct SQL for each entry before adding it β a wrong example teaches the model a wrong pattern, which is worse than no example at all. - Use the "Add verified example" tab as the feedback loop: after a
generated query is confirmed correct, add it there so future similar
questions benefit. Note the library currently resets on app
restart (it's in-memory) β for a persistent version, write
TRACE_LIBRARYto a small JSON file or SQLite table on add, and load it on startup, instead of keeping it as a plain Python list. - Don't force-fit this everywhere. This pattern only earns its complexity on repeat-shaped analytical/diagnostic questions. For fact-lookup use cases (order status, policy answers β e.g. Reem), plain document RAG is the right tool; this adds nothing there.
Caveats
- The trace library needs coverage of distinct question shapes, not raw volume β a few dozen verified examples covering your real question patterns will outperform hundreds of near-duplicates.
- Never auto-add unverified traces to the library; incorrect examples compound into worse output over time, not just missing info.
- In-memory
TRACE_LIBRARYresets every time the Space restarts/sleeps on the free tier β fine for a prototype demo, not for production use.