Shouvik599 commited on
Commit Β·
e31b9ae
1
Parent(s): 7ae27cd
Next set of feature improvements
Browse files- features_to_add.txt +7 -1
- frontend/index.html +10 -4
- rag_chain.py +5 -0
features_to_add.txt
CHANGED
|
@@ -17,4 +17,10 @@ Compare mode β a dedicated side-by-side view for "How does Book A vs Book B ad
|
|
| 17 |
Hallucination guardrail β run a separate verification pass checking every claim in the answer maps back to a retrieved chunk; flag or remove unsupported claims
|
| 18 |
Out-of-scope detection β classify queries before retrieval; politely decline non-spiritual questions (e.g. "Write me code") with a prompt-level or classifier-level guard
|
| 19 |
Rate limiting β add per-IP request throttling in FastAPI to prevent API key exhaustion
|
| 20 |
-
API key security β move to server-side key storage properly; never expose NVIDIA_API_KEY or GEMINI_API_KEY in frontend calls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
Hallucination guardrail β run a separate verification pass checking every claim in the answer maps back to a retrieved chunk; flag or remove unsupported claims
|
| 18 |
Out-of-scope detection β classify queries before retrieval; politely decline non-spiritual questions (e.g. "Write me code") with a prompt-level or classifier-level guard
|
| 19 |
Rate limiting β add per-IP request throttling in FastAPI to prevent API key exhaustion
|
| 20 |
+
API key security β move to server-side key storage properly; never expose NVIDIA_API_KEY or GEMINI_API_KEY in frontend calls
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Need to debug -
|
| 24 |
+
1. General questions not citing verses
|
| 25 |
+
2. For exact verses cache threshold score is returning same for chapter 2 verse 4 and chapter 1 verse 10
|
| 26 |
+
3.
|
frontend/index.html
CHANGED
|
@@ -778,7 +778,7 @@
|
|
| 778 |
const reader = res.body.getReader();
|
| 779 |
const decoder = new TextDecoder();
|
| 780 |
let fullAnswer = "";
|
| 781 |
-
let
|
| 782 |
|
| 783 |
// Prepare the assistant UI bubble immediately
|
| 784 |
loadingEl.innerHTML = `
|
|
@@ -796,8 +796,14 @@
|
|
| 796 |
const { done, value } = await reader.read();
|
| 797 |
if (done) break;
|
| 798 |
|
| 799 |
-
|
| 800 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
|
| 802 |
for (const line of lines) {
|
| 803 |
if (!line.trim()) continue;
|
|
@@ -826,7 +832,7 @@
|
|
| 826 |
scrollToBottom();
|
| 827 |
}
|
| 828 |
} catch (e) {
|
| 829 |
-
console.error("
|
| 830 |
}
|
| 831 |
}
|
| 832 |
}
|
|
|
|
| 778 |
const reader = res.body.getReader();
|
| 779 |
const decoder = new TextDecoder();
|
| 780 |
let fullAnswer = "";
|
| 781 |
+
let buffer = "";
|
| 782 |
|
| 783 |
// Prepare the assistant UI bubble immediately
|
| 784 |
loadingEl.innerHTML = `
|
|
|
|
| 796 |
const { done, value } = await reader.read();
|
| 797 |
if (done) break;
|
| 798 |
|
| 799 |
+
// Append new data to the buffer
|
| 800 |
+
buffer += decoder.decode(value, { stream: true });
|
| 801 |
+
|
| 802 |
+
// Split by newline
|
| 803 |
+
const lines = buffer.split("\n");
|
| 804 |
+
|
| 805 |
+
buffer = lines.pop();
|
| 806 |
+
|
| 807 |
|
| 808 |
for (const line of lines) {
|
| 809 |
if (!line.trim()) continue;
|
|
|
|
| 832 |
scrollToBottom();
|
| 833 |
}
|
| 834 |
} catch (e) {
|
| 835 |
+
console.error("Stream parsing error", e);
|
| 836 |
}
|
| 837 |
}
|
| 838 |
}
|
rag_chain.py
CHANGED
|
@@ -335,6 +335,10 @@ def query_sacred_texts(question: str):
|
|
| 335 |
if display_name not in seen_sources:
|
| 336 |
seen_sources.add(display_name)
|
| 337 |
sources.append({"book": display_name, "page": cite_val, "snippet": snippet})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
# Step 2: Format context grouped by book
|
| 339 |
context = format_docs(source_docs)
|
| 340 |
full_answer =""
|
|
@@ -362,6 +366,7 @@ def query_sacred_texts(question: str):
|
|
| 362 |
"sources": display_sources,
|
| 363 |
}
|
| 364 |
|
|
|
|
| 365 |
cache_coll.add(
|
| 366 |
documents=[question],
|
| 367 |
metadatas=[{"response_json": json.dumps(result)}],
|
|
|
|
| 335 |
if display_name not in seen_sources:
|
| 336 |
seen_sources.add(display_name)
|
| 337 |
sources.append({"book": display_name, "page": cite_val, "snippet": snippet})
|
| 338 |
+
# Print book and page of each retrieved source for debugging
|
| 339 |
+
print("\nπ Retrieved sources:")
|
| 340 |
+
for s in sources:
|
| 341 |
+
print(f" - {s['book']} ({s['page']})")
|
| 342 |
# Step 2: Format context grouped by book
|
| 343 |
context = format_docs(source_docs)
|
| 344 |
full_answer =""
|
|
|
|
| 366 |
"sources": display_sources,
|
| 367 |
}
|
| 368 |
|
| 369 |
+
|
| 370 |
cache_coll.add(
|
| 371 |
documents=[question],
|
| 372 |
metadatas=[{"response_json": json.dumps(result)}],
|