Spaces:
Paused
Paused
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -195,14 +195,23 @@ def debug_search_tables(vector_index, search_term="С-25"):
|
|
| 195 |
|
| 196 |
return matching
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
def answer_question(question, query_engine, reranker, current_model, chunks_df=None):
|
|
|
|
|
|
|
|
|
|
| 199 |
if query_engine is None:
|
| 200 |
return "<div style='background-color: #e53e3e; color: white; padding: 20px; border-radius: 10px;'>Система не инициализирована</div>", "", ""
|
| 201 |
|
| 202 |
try:
|
| 203 |
start_time = time.time()
|
| 204 |
-
|
|
|
|
| 205 |
log_message(f"user query: {question}")
|
|
|
|
| 206 |
|
| 207 |
|
| 208 |
log_message(f"RETRIEVED: {len(retrieved_nodes)} nodes")
|
|
@@ -218,11 +227,11 @@ def answer_question(question, query_engine, reranker, current_model, chunks_df=N
|
|
| 218 |
log_message(f" [{i+1}] {doc_id} - Table {table_num}: {table_title[:50]}")
|
| 219 |
log_message(f"UNIQUE NODES: {len(unique_retrieved)} nodes")
|
| 220 |
|
| 221 |
-
# Simple reranking
|
| 222 |
-
reranked_nodes = rerank_nodes(
|
| 223 |
|
| 224 |
-
# Direct query without formatting
|
| 225 |
-
response = query_engine.query(
|
| 226 |
|
| 227 |
end_time = time.time()
|
| 228 |
processing_time = end_time - start_time
|
|
|
|
| 195 |
|
| 196 |
return matching
|
| 197 |
|
| 198 |
+
# Add this import at the top of utils.py
|
| 199 |
+
from documents_prep import normalize_text
|
| 200 |
+
|
| 201 |
+
# MODIFIED: Update answer_question function
|
| 202 |
def answer_question(question, query_engine, reranker, current_model, chunks_df=None):
|
| 203 |
+
# NORMALIZE the question to convert C to С
|
| 204 |
+
normalized_question = normalize_text(question)
|
| 205 |
+
|
| 206 |
if query_engine is None:
|
| 207 |
return "<div style='background-color: #e53e3e; color: white; padding: 20px; border-radius: 10px;'>Система не инициализирована</div>", "", ""
|
| 208 |
|
| 209 |
try:
|
| 210 |
start_time = time.time()
|
| 211 |
+
# Use NORMALIZED question for retrieval
|
| 212 |
+
retrieved_nodes = query_engine.retriever.retrieve(normalized_question)
|
| 213 |
log_message(f"user query: {question}")
|
| 214 |
+
log_message(f"normalized query: {normalized_question}")
|
| 215 |
|
| 216 |
|
| 217 |
log_message(f"RETRIEVED: {len(retrieved_nodes)} nodes")
|
|
|
|
| 227 |
log_message(f" [{i+1}] {doc_id} - Table {table_num}: {table_title[:50]}")
|
| 228 |
log_message(f"UNIQUE NODES: {len(unique_retrieved)} nodes")
|
| 229 |
|
| 230 |
+
# Simple reranking with NORMALIZED question
|
| 231 |
+
reranked_nodes = rerank_nodes(normalized_question, unique_retrieved, reranker, top_k=20)
|
| 232 |
|
| 233 |
+
# Direct query without formatting - use normalized question
|
| 234 |
+
response = query_engine.query(normalized_question)
|
| 235 |
|
| 236 |
end_time = time.time()
|
| 237 |
processing_time = end_time - start_time
|