Chamin09 commited on
Commit
fb82bd1
·
verified ·
1 Parent(s): 681cb59

Update indexes/query_engine.py

Browse files
Files changed (1) hide show
  1. indexes/query_engine.py +16 -0
indexes/query_engine.py CHANGED
@@ -39,6 +39,22 @@ class CSVQueryEngine:
39
  "sources": self._get_sources(relevant_csvs)
40
  }
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  def _handle_statistical_query(self, query: str, csv_ids: List[str]) -> Optional[str]:
43
  """Handle direct statistical queries without using the LLM."""
44
  query_lower = query.lower()
 
39
  "sources": self._get_sources(relevant_csvs)
40
  }
41
 
42
+ def _get_sources(self, csv_ids: List[str]) -> List[Dict[str, str]]:
43
+ """Get source information for the response."""
44
+ sources = []
45
+
46
+ for csv_id in csv_ids:
47
+ if csv_id not in self.index_manager.indexes:
48
+ continue
49
+
50
+ metadata = self.index_manager.indexes[csv_id]["metadata"]
51
+ sources.append({
52
+ "csv": metadata["filename"],
53
+ "columns": ", ".join(metadata["columns"][:5]) + ("..." if len(metadata["columns"]) > 5 else "")
54
+ })
55
+
56
+ return sources
57
+
58
  def _handle_statistical_query(self, query: str, csv_ids: List[str]) -> Optional[str]:
59
  """Handle direct statistical queries without using the LLM."""
60
  query_lower = query.lower()