Adam Cseresznye commited on
Commit ·
f4710af
1
Parent(s): 5b3eb12
Refine synthesis prompt
Browse files- agents/synthesis_agent.py +11 -15
agents/synthesis_agent.py
CHANGED
|
@@ -25,6 +25,7 @@ from typing import List
|
|
| 25 |
from loguru import logger
|
| 26 |
|
| 27 |
from llama_index.core.schema import NodeWithScore
|
|
|
|
| 28 |
|
| 29 |
from utils.llm_router import LLMRouter
|
| 30 |
import re
|
|
@@ -46,10 +47,6 @@ CITATION_QA_TEMPLATE = (
|
|
| 46 |
"You are a Senior Scientific Research Fellow briefing a Principal Investigator. "
|
| 47 |
"Your goal is to distill a complex body of literature into a definitive, scientifically rigorous synthesis.\n"
|
| 48 |
"---------------------\n"
|
| 49 |
-
"### CONTEXT CHUNKS:\n"
|
| 50 |
-
"Format: [Source ID] Text content...\n\n"
|
| 51 |
-
"{context_str}\n"
|
| 52 |
-
"---------------------\n\n"
|
| 53 |
"### INSTRUCTIONS:\n"
|
| 54 |
"1. **THE BLUF (Bottom Line Up Front):**\n"
|
| 55 |
" - Start immediately with a bold **Label**. Choose the best fit:\n"
|
|
@@ -63,25 +60,25 @@ CITATION_QA_TEMPLATE = (
|
|
| 63 |
" - **Critical Nuances:** Discuss conflicts, sexual dimorphism, in vivo vs in vitro discrepancies, or major limitations.\n\n"
|
| 64 |
"3. **STYLE & CONSTRAINTS:**\n"
|
| 65 |
" - **Target Length:** ~250-350 words. Be dense but readable.\n"
|
| 66 |
-
" - **Bullet Style:** Start every bullet point with a **Bold Concept Label** followed by a dash
|
| 67 |
-
" - **Tone:** Professional. Use precise terminology
|
| 68 |
-
" - **Definitions:** Define ONLY non-standard acronyms
|
| 69 |
"4. **PROTOCOL FOR INSUFFICIENT DATA:**\n"
|
| 70 |
" - If the provided chunks do not contain the answer, do not hallucinate.\n"
|
| 71 |
-
" - Output exactly: **Verdict: Insufficient Evidence.** followed by a brief explanation
|
| 72 |
"5. **CITATION RULES (STRICT):**\n"
|
|
|
|
| 73 |
" - **Atomic Citations:** Every specific claim must be cited immediately [N].\n"
|
| 74 |
" - **Verification:** Do not cite a source unless the text explicitly supports the claim.\n"
|
| 75 |
-
" - **
|
| 76 |
-
" - **The 'Eyes-Only' Rule (CRITICAL):** You likely know these famous papers from your pre-training. **IGNORE YOUR TRAINING DATA.** \n"
|
| 77 |
-
" * You are FORBIDDEN from using facts, numbers, or specific outcomes that are not physically present in the provided text chunks.\n"
|
| 78 |
-
" * If you 'know' a paper has a sample size of 50, but the text chunk doesn't say it, **DO NOT** write 'N=50'. Write 'a study [1]' instead.\n"
|
| 79 |
-
" * **Violation Penalty:** If you cite a fact that is not in the chunk, the citation is considered invalid."
|
| 80 |
"### REQUIRED OUTPUT FORMAT:\n"
|
| 81 |
"---------------------\n"
|
| 82 |
f"{FEW_SHOT_EXAMPLE}\n"
|
| 83 |
"---------------------\n\n"
|
|
|
|
|
|
|
| 84 |
"User Query: {query_str}\n"
|
|
|
|
| 85 |
)
|
| 86 |
|
| 87 |
|
|
@@ -139,8 +136,7 @@ class SynthesisAgent:
|
|
| 139 |
|
| 140 |
# Build the full prompt
|
| 141 |
prompt = CITATION_QA_TEMPLATE.format(
|
| 142 |
-
context_str=context_str,
|
| 143 |
-
query_str=query,
|
| 144 |
)
|
| 145 |
|
| 146 |
logger.debug(
|
|
|
|
| 25 |
from loguru import logger
|
| 26 |
|
| 27 |
from llama_index.core.schema import NodeWithScore
|
| 28 |
+
from config import RAG_RERANK_TOP_K
|
| 29 |
|
| 30 |
from utils.llm_router import LLMRouter
|
| 31 |
import re
|
|
|
|
| 47 |
"You are a Senior Scientific Research Fellow briefing a Principal Investigator. "
|
| 48 |
"Your goal is to distill a complex body of literature into a definitive, scientifically rigorous synthesis.\n"
|
| 49 |
"---------------------\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
"### INSTRUCTIONS:\n"
|
| 51 |
"1. **THE BLUF (Bottom Line Up Front):**\n"
|
| 52 |
" - Start immediately with a bold **Label**. Choose the best fit:\n"
|
|
|
|
| 60 |
" - **Critical Nuances:** Discuss conflicts, sexual dimorphism, in vivo vs in vitro discrepancies, or major limitations.\n\n"
|
| 61 |
"3. **STYLE & CONSTRAINTS:**\n"
|
| 62 |
" - **Target Length:** ~250-350 words. Be dense but readable.\n"
|
| 63 |
+
" - **Bullet Style:** Start every bullet point with a **Bold Concept Label** followed by a dash. Mandatory.\n"
|
| 64 |
+
" - **Tone:** Professional. Use precise terminology.\n"
|
| 65 |
+
" - **Definitions:** Define ONLY non-standard acronyms on first use.\n\n"
|
| 66 |
"4. **PROTOCOL FOR INSUFFICIENT DATA:**\n"
|
| 67 |
" - If the provided chunks do not contain the answer, do not hallucinate.\n"
|
| 68 |
+
" - Output exactly: **Verdict: Insufficient Evidence.** followed by a brief explanation.\n\n"
|
| 69 |
"5. **CITATION RULES (STRICT):**\n"
|
| 70 |
+
" - **Valid Source Range:** You have access to Sources 1 through {max_id}. **ANY CITATION > {max_id} IS A HALLUCINATION.**\n"
|
| 71 |
" - **Atomic Citations:** Every specific claim must be cited immediately [N].\n"
|
| 72 |
" - **Verification:** Do not cite a source unless the text explicitly supports the claim.\n"
|
| 73 |
+
" - **The 'Eyes-Only' Rule:** IGNORE YOUR TRAINING DATA. Use ONLY facts present in the text chunks.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
"### REQUIRED OUTPUT FORMAT:\n"
|
| 75 |
"---------------------\n"
|
| 76 |
f"{FEW_SHOT_EXAMPLE}\n"
|
| 77 |
"---------------------\n\n"
|
| 78 |
+
"### CONTEXT CHUNKS (Sources 1-{max_id}):\n"
|
| 79 |
+
"{context_str}\n\n"
|
| 80 |
"User Query: {query_str}\n"
|
| 81 |
+
"Answer (using ONLY Sources 1-{max_id}):"
|
| 82 |
)
|
| 83 |
|
| 84 |
|
|
|
|
| 136 |
|
| 137 |
# Build the full prompt
|
| 138 |
prompt = CITATION_QA_TEMPLATE.format(
|
| 139 |
+
context_str=context_str, query_str=query, max_id=RAG_RERANK_TOP_K
|
|
|
|
| 140 |
)
|
| 141 |
|
| 142 |
logger.debug(
|