Spaces:
Runtime error
Runtime error
File size: 1,429 Bytes
bb0f4d5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | """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())
|