acpc-testing-7 / scripts /debug_ldce_sql.py
welcometoFightclub's picture
Upload 107 files
bb0f4d5 verified
Raw History Blame Contribute Delete
1.43 kB
"""Debug: show the actual SQL generated for LDCE queries."""
import asyncio
import json
import sys
sys.path.insert(0, ".")
from app.retrieval.sql_retriever import get_sql_retriever_singleton
from app.orchestration.query_rewriter import get_query_rewriter_singleton
async def debug_query(query: str):
print(f"\n{'='*80}")
print(f"QUERY: {query}")
print('='*80)
rewriter = get_query_rewriter_singleton()
retriever = get_sql_retriever_singleton()
await retriever.initialise()
# Step 1: See the intent
intent = await rewriter.rewrite_for_sql(query)
print(f"\nINTENT: {json.dumps(intent, indent=2)}")
# Step 2: See the SQL
schema = await retriever._get_schema()
schema_text = retriever._schema_text(schema)
sql = await retriever._generate_sql(intent, schema_text)
print(f"\nGENERATED SQL:\n {sql}")
# Step 3: Execute and see result
result = await retriever.execute_nl_query(intent)
print(f"\nRESULT: {result.row_count} rows")
if result.error:
print(f"ERROR: {result.error}")
if result.query_used:
print(f"QUERY USED: {result.query_used}")
for row in result.rows[:5]:
print(f" {row}")
async def main():
await debug_query("What are the cutoff ranks for LDCE Ahmedabad?")
await debug_query("LDCE computer engineering cutoff")
await debug_query("L.D. College of Engineering cutoff ranks")
asyncio.run(main())