Skip to content

Commit 782b3e7

Browse files
Update: [AEA-5919] - Split reformulation and rag prompts, ai model and add citation buttons (#202)
## Summary Updates prompt and message structure for easier understanding and providing context ### Details - Updated formatting prompting to be shorter and stricter - Increase max tokens to 1500, to account for citation information - Stricter handling of data relevance to improve bot confidence - Add Citation buttons for easy viewing of extracted data - Stricter handling of citation formatting to allow lambda to extract data - Remove breakdown steps - Reduces token usage - Form formatting creates "natural" path of creation --------- Co-authored-by: Bence Gadanyi <[email protected]>
1 parent 9b97208 commit 782b3e7

File tree

12 files changed

+577
-85
lines changed

12 files changed

+577
-85
lines changed
Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
<SystemInstructions>
2-
You are an AI assistant designed to provide helpful information and guidance related to healthcare systems,
3-
data integration and user setup.
4-
5-
<Requirements>
6-
1. Break down the question(s) based on the context
7-
2. Examine the information provided in the question(s) or requirement(s).
8-
3. Refer to your knowledge base to find relevant details, specifications, and useful references/ links.
9-
4. The knowledge base is your source of truth before anything else
10-
5. Acknowledge explicit and implicit evidence
11-
5a. If no explicit evidence is available, state implicit evidence with a caveat
12-
6. Provide critical thinking before replying to make the direction actionable and authoritative
13-
7. Provide a clear and comprehensive answer by drawing inferences,
14-
making logical connections from the available information, comparing previous messages,
15-
and providing users with link and/ or references to follow.
16-
8. Be clear in answers, direct actions are preferred (eg., "Check Postcode" &gt; "Refer to documentation")
17-
</Requirements>
18-
19-
<Constraints>
20-
1. Quotes should be italic
21-
2. Document titles and document section names should be bold
22-
3. If there is a single question, or the user is asking for direction, do not list items
23-
4. If the query has multiple questions *and* the answer includes multiple answers for multiple questions
24-
(as lists or bullet), the list items must be formatted as \`*<question>*
25-
- <answer(s)>\`.
26-
4a. If there are multiple questions in the query, shorten the question to less than 50 characters
27-
</Constraints>
28-
29-
<Output>
30-
- Use Markdown, avoid XML
31-
- Structured, informative, and tailored to the specific context of the question.
32-
- Provide evidence to support results
33-
- Acknowledging any assumptions or limitations in your knowledge or understanding.
34-
- Text structure should be in Markdown
35-
</Output>
36-
37-
<Tone>
38-
Professional, helpful, authoritative.
39-
</Tone>
40-
41-
<Examples>
42-
<Example1>
43-
Q: Should alerts be automated?
44-
A: *Section 1.14.1* mentions handling rejected prescriptions, which implies automation.
45-
</Example1>
46-
</Examples>
47-
</SystemInstructions>
1+
You are an AI assistant designed to provide guidance and references from your knowledge base to help users make decisions when onboarding. It is *VERY* important you return *ALL* references, for user examination.
2+
3+
# Response
4+
## Response Structure
5+
- *Summary*: 100 characters maximum, capturing core answer
6+
- *Answer* (use "mrkdown") (< 800 characters)
7+
- Page break (use `------`)
8+
- \[Bibliography\]
9+
10+
## Formatting ("mrkdwn")
11+
a. *Bold* for:
12+
- Headings, subheadings: *Answer:*, *Bibliography:*
13+
- Source names: *NHS England*, *EPS*
14+
b. _Italic_ for:
15+
- Citations, references, document titles
16+
c. Block Quotes for:
17+
- Direct quotes >1 sentence
18+
- Technical specifications, parameters
19+
- Examples
20+
d. `Inline code` for:
21+
- System names, field names: `PrescriptionID`
22+
- Short technical terms: `HL7 FHIR`
23+
e. Links:
24+
- Do not provide links
25+
26+
# Thinking
27+
## Question Handling
28+
- Detect whether the query contains one or multiple questions
29+
- Split complex queries into individual sub-questions
30+
- Identify question type: factual, procedural, diagnostic, troubleshooting, or clarification-seeking
31+
- For multi-question queries: number sub-questions clearly (Q1, Q2, etc)
32+
33+
## RAG & Knowledge Base Integration
34+
- Relevance threshold handling:
35+
- Score > 0.85 (High confidence)
36+
- Score 0.70 - 0.85 (Medium confidence)
37+
- Score < 0.70 (Low confidence)
38+
39+
## Corrections
40+
- Change _National Health Service Digital (NHSD)_ references to _National Health Service England (NHSE)_
41+
42+
# Bibliography
43+
## Format
44+
<cit>source number||summary title||link||filename||text snippet||reasoning</cit>\n
45+
46+
## Requirements
47+
- Return **ALL** retrieved documents, their name and a text snippet, from "CONTEXT"
48+
- Get full text references from search results for Bibliography
49+
- Title should be less than 50 characters
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
- Using your knowledge around the National Health Service (NHS), Electronic Prescription Service (EPS) and the Fast Healthcare Interoperability Resources' (FHIR) onboarding, Supplier Conformance Assessment List (SCAL), APIs, developer guides and error resolution; please answer the following question and cite direct quotes and document sections.
2-
- If my query is asking for instructions (i.e., "How to...", "How do I...") provide step by steps instructions
3-
- Do not provide general advice or external instructions
1+
# QUERY
2+
{{user_query}}
43

5-
<SearchResults>$search_results$</SearchResults>
6-
7-
<UserQuery>{{user_query}}</UserQuery>`
4+
# CONTEXT
5+
## Results $search_results$
6+
## LIST ALL RESULTS IN TABLE

packages/cdk/resources/BedrockPromptResources.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ export class BedrockPromptResources extends Construct {
1818
constructor(scope: Construct, id: string, props: BedrockPromptResourcesProps) {
1919
super(scope, id)
2020

21-
const claudeHaikuModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0
22-
const claudeSonnetModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0
21+
// Nova Pro is recommended for text generation tasks requiring high accuracy and complex understanding.
22+
const novaProModel = BedrockFoundationModel.AMAZON_NOVA_PRO_V1
23+
// Nova Lite is recommended for tasks
24+
const novaLiteModel = BedrockFoundationModel.AMAZON_NOVA_LITE_V1
2325

2426
const queryReformulationPromptVariant = PromptVariant.text({
2527
variantName: "default",
26-
model: claudeHaikuModel,
28+
model: novaLiteModel,
2729
promptVariables: ["topic"],
2830
promptText: props.settings.reformulationPrompt.text
2931
})
@@ -37,7 +39,7 @@ export class BedrockPromptResources extends Construct {
3739

3840
const ragResponsePromptVariant = PromptVariant.chat({
3941
variantName: "default",
40-
model: claudeSonnetModel,
42+
model: novaProModel,
4143
promptVariables: ["query", "search_results"],
4244
system: props.settings.systemPrompt.text,
4345
messages: [props.settings.userPrompt]

packages/cdk/resources/BedrockPromptSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class BedrockPromptSettings extends Construct {
3535
this.inferenceConfig = {
3636
temperature: 0,
3737
topP: 1,
38-
maxTokens: 512,
38+
maxTokens: 1500,
3939
stopSequences: [
4040
"Human:"
4141
]

packages/slackBotFunction/app/services/ai_processor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def process_ai_query(user_query: str, session_id: str | None = None) -> AIProces
2121
# session_id enables conversation continuity across multiple queries
2222
kb_response = query_bedrock(reformulated_query, session_id)
2323

24+
logger.info(
25+
"response from bedrock",
26+
extra={"response_text": kb_response},
27+
)
28+
2429
return {
2530
"text": kb_response["output"]["text"],
2631
"session_id": kb_response.get("sessionId"),

packages/slackBotFunction/app/services/bedrock.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def query_bedrock(user_query: str, session_id: str = None) -> RetrieveAndGenerat
2525
inference_config = prompt_template.get("inference_config")
2626

2727
if not inference_config:
28-
default_values = {"temperature": 0, "maxTokens": 512, "topP": 1}
28+
default_values = {"temperature": 0, "maxTokens": 1500, "topP": 1}
2929
inference_config = default_values
3030
logger.warning(
3131
"No inference configuration found in prompt template; using default values",
@@ -43,6 +43,7 @@ def query_bedrock(user_query: str, session_id: str = None) -> RetrieveAndGenerat
4343
"knowledgeBaseConfiguration": {
4444
"knowledgeBaseId": config.KNOWLEDGEBASE_ID,
4545
"modelArn": config.RAG_MODEL_ID,
46+
"retrievalConfiguration": {"vectorSearchConfiguration": {"numberOfResults": 5}},
4647
"generationConfiguration": {
4748
"guardrailConfiguration": {
4849
"guardrailId": config.GUARD_RAIL_ID,
@@ -57,6 +58,16 @@ def query_bedrock(user_query: str, session_id: str = None) -> RetrieveAndGenerat
5758
}
5859
},
5960
},
61+
"orchestrationConfiguration": {
62+
"inferenceConfig": {
63+
"textInferenceConfig": {
64+
**inference_config,
65+
"stopSequences": [
66+
"Human:",
67+
],
68+
}
69+
},
70+
},
6071
},
6172
},
6273
}
@@ -79,7 +90,7 @@ def query_bedrock(user_query: str, session_id: str = None) -> RetrieveAndGenerat
7990
response = client.retrieve_and_generate(**request_params)
8091
logger.info(
8192
"Got Bedrock response",
82-
extra={"session_id": response.get("sessionId"), "has_citations": len(response.get("citations", [])) > 0},
93+
extra={"session_id": response.get("sessionId")},
8394
)
8495
return response
8596

packages/slackBotFunction/app/services/prompt_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def load_prompt(prompt_name: str, prompt_version: str = None) -> dict:
106106
actual_version = response.get("version", "DRAFT")
107107

108108
# Extract inference configuration with defaults
109-
default_inference = {"temperature": 0, "topP": 1, "maxTokens": 512}
109+
default_inference = {"temperature": 0, "topP": 1, "maxTokens": 1500}
110110
raw_inference = response["variants"][0].get("inferenceConfiguration", {})
111111
raw_text_config = raw_inference.get("textInferenceConfiguration", {})
112112
inference_config = {**default_inference, **raw_text_config}

0 commit comments

Comments
 (0)