Main /
RAGPromptExamples
With different prompts, we can engineer the RAG pipeline to generate new output. For instance, using the information in the retrieved documents, we can generate a message from the university administration on a topic of interest:
New prompt in query.py
:
#
# Custom prompt for the query engine
#
PROMPT = PromptTemplate(
"""You are a university adminstrator. You are given top-ranked examples (CONTEXT) on a TOPIC.
Instructions:
- Base your response *only* on the CONTEXT.
- The snippets are ordered from most to least relevant—prioritize insights from earlier (higher-ranked) snippets.
- Do not invent or generalize; refer to specific passages or facts only.
- If a passage only loosely matches, deprioritize it.
Write a message of up to three paragraphs addressed to the university commuinty on the TOPIC using the CONTEXT.
CONTEXT:
{context_str}
TOPIC:
{query_str}
Now provide the message to the university community."""
)
# Custom prompt for the query engine
#
PROMPT = PromptTemplate(
"""You are a university adminstrator. You are given top-ranked examples (CONTEXT) on a TOPIC.
Instructions:
- Base your response *only* on the CONTEXT.
- The snippets are ordered from most to least relevant—prioritize insights from earlier (higher-ranked) snippets.
- Do not invent or generalize; refer to specific passages or facts only.
- If a passage only loosely matches, deprioritize it.
Write a message of up to three paragraphs addressed to the university commuinty on the TOPIC using the CONTEXT.
CONTEXT:
{context_str}
TOPIC:
{query_str}
Now provide the message to the university community."""
)
I used llama3.1:7b
as the generating model because I suspected that it might add a little more flourish to the output.
Here's an example run on our lab workstation:
((.venv) ) furst@anisotropic:~/LLM/rag/demo$ python query_alt.py
Loading llama_index.core.storage.kvstore.simple_kvstore from ./storage/docstore.json.
Loading llama_index.core.storage.kvstore.simple_kvstore from ./storage/index_store.json.
Enter a search topic or question (or 'exit'): welcome back to a new school year
Dear UD Community,
As we embark on this new academic year, I would like to extend a warm welcome to all of you. Whether you are a new or continuing student, faculty or staff member, our campus is alive with energy and excitement as we begin another year of learning and growth.
Our community is strengthened by the connections we forge with each other and the collaborations we pursue around bold ideas. I am thrilled to see that this new class of students, including one of the highest test scores and cumulative grade point average in recent years, brings with them a fresh perspective and passion for learning.
As we move forward together, I encourage you to take advantage of everything UD has to offer – from challenging academic pursuits to stimulating social activities, cultural engagement, innovative research, and community service. Our campus is a place where students, faculty, and staff come together to learn, grow, and make a positive impact on the world.
As we look to the future, I want to emphasize our commitment to diversity, equity, and inclusion. We recognize that our strength lies in the diverse perspectives, talents, and skills of each and every one of you. Our goal is to create an environment where everyone feels welcome, valued, and empowered to succeed.
I invite you to join me in making this new academic year one to remember. Let us work together to turn our Delaware Will Shine strategic plan from words into actions, fostering a culture of intellectual pursuits, mutual respect, and open-mindedness.
Together, we will continue to cultivate learning, develop knowledge, and foster the free exchange of ideas. We will build on our strengths, leverage new opportunities, and push forward with confidence and determination.
Welcome back to UD! I look forward to seeing you on campus and working together to make this academic year an unforgettable one.
Sincerely,
President
Source documents:
2023_08_28_120747.txt /home/furst/LLM/demo/data/2023_08_28_120747.txt 0.643636250412912
2019_08_26_084103.txt /home/furst/LLM/demo/data/2019_08_26_084103.txt 0.6190674300618136
2015_09_01_084152.txt /home/furst/LLM/demo/data/2015_09_01_084152.txt 0.616119388597392
2024_08_26_100859.txt /home/furst/LLM/demo/data/2024_08_26_100859.txt 0.6109821657344754
2020_03_15_211550.txt /home/furst/LLM/demo/data/2020_03_15_211550.txt 0.6072407167106767
2020_07_22_153925.txt /home/furst/LLM/demo/data/2020_07_22_153925.txt 0.6065073534647268
2022_01_03_102651.txt /home/furst/LLM/demo/data/2022_01_03_102651.txt 0.6032120789604264
2025_07_18_094529.txt /home/furst/LLM/demo/data/2025_07_18_094529.txt 0.6026328255509924
2020_06_23_150652.txt /home/furst/LLM/demo/data/2020_06_23_150652.txt 0.6024682670824563
2020_09_01_091133.txt /home/furst/LLM/demo/data/2020_09_01_091133.txt 0.6008153126432857
2019_12_20_204740.txt /home/furst/LLM/demo/data/2019_12_20_204740.txt 0.6004832985448465
2021_08_30_132201.txt /home/furst/LLM/demo/data/2021_08_30_132201.txt 0.5990430273606064
2017_01_06_105509.txt /home/furst/LLM/demo/data/2017_01_06_105509.txt 0.5987792036926197
2016_08_30_131858.txt /home/furst/LLM/demo/data/2016_08_30_131858.txt 0.5984471678852645
2010_11_08_110641.txt /home/furst/LLM/demo/data/2010_11_08_110641.txt 0.597488798362081
Elapsed time: 54.2 seconds
Loading llama_index.core.storage.kvstore.simple_kvstore from ./storage/docstore.json.
Loading llama_index.core.storage.kvstore.simple_kvstore from ./storage/index_store.json.
Enter a search topic or question (or 'exit'): welcome back to a new school year
Dear UD Community,
As we embark on this new academic year, I would like to extend a warm welcome to all of you. Whether you are a new or continuing student, faculty or staff member, our campus is alive with energy and excitement as we begin another year of learning and growth.
Our community is strengthened by the connections we forge with each other and the collaborations we pursue around bold ideas. I am thrilled to see that this new class of students, including one of the highest test scores and cumulative grade point average in recent years, brings with them a fresh perspective and passion for learning.
As we move forward together, I encourage you to take advantage of everything UD has to offer – from challenging academic pursuits to stimulating social activities, cultural engagement, innovative research, and community service. Our campus is a place where students, faculty, and staff come together to learn, grow, and make a positive impact on the world.
As we look to the future, I want to emphasize our commitment to diversity, equity, and inclusion. We recognize that our strength lies in the diverse perspectives, talents, and skills of each and every one of you. Our goal is to create an environment where everyone feels welcome, valued, and empowered to succeed.
I invite you to join me in making this new academic year one to remember. Let us work together to turn our Delaware Will Shine strategic plan from words into actions, fostering a culture of intellectual pursuits, mutual respect, and open-mindedness.
Together, we will continue to cultivate learning, develop knowledge, and foster the free exchange of ideas. We will build on our strengths, leverage new opportunities, and push forward with confidence and determination.
Welcome back to UD! I look forward to seeing you on campus and working together to make this academic year an unforgettable one.
Sincerely,
President
Source documents:
2023_08_28_120747.txt /home/furst/LLM/demo/data/2023_08_28_120747.txt 0.643636250412912
2019_08_26_084103.txt /home/furst/LLM/demo/data/2019_08_26_084103.txt 0.6190674300618136
2015_09_01_084152.txt /home/furst/LLM/demo/data/2015_09_01_084152.txt 0.616119388597392
2024_08_26_100859.txt /home/furst/LLM/demo/data/2024_08_26_100859.txt 0.6109821657344754
2020_03_15_211550.txt /home/furst/LLM/demo/data/2020_03_15_211550.txt 0.6072407167106767
2020_07_22_153925.txt /home/furst/LLM/demo/data/2020_07_22_153925.txt 0.6065073534647268
2022_01_03_102651.txt /home/furst/LLM/demo/data/2022_01_03_102651.txt 0.6032120789604264
2025_07_18_094529.txt /home/furst/LLM/demo/data/2025_07_18_094529.txt 0.6026328255509924
2020_06_23_150652.txt /home/furst/LLM/demo/data/2020_06_23_150652.txt 0.6024682670824563
2020_09_01_091133.txt /home/furst/LLM/demo/data/2020_09_01_091133.txt 0.6008153126432857
2019_12_20_204740.txt /home/furst/LLM/demo/data/2019_12_20_204740.txt 0.6004832985448465
2021_08_30_132201.txt /home/furst/LLM/demo/data/2021_08_30_132201.txt 0.5990430273606064
2017_01_06_105509.txt /home/furst/LLM/demo/data/2017_01_06_105509.txt 0.5987792036926197
2016_08_30_131858.txt /home/furst/LLM/demo/data/2016_08_30_131858.txt 0.5984471678852645
2010_11_08_110641.txt /home/furst/LLM/demo/data/2010_11_08_110641.txt 0.597488798362081
Elapsed time: 54.2 seconds
command-r7b
did a respectable job, too, and in just under 7 seconds!
((.venv) ) furst@anisotropic:~/LLM/rag/demo$ python query_alt.py
Loading llama_index.core.storage.kvstore.simple_kvstore from ./storage/docstore.json.
Loading llama_index.core.storage.kvstore.simple_kvstore from ./storage/index_store.json.
Enter a search topic or question (or 'exit'): welcome back to a new school year
## Welcome Back to a New School Year!
The start of a new academic year is always an exciting time, filled with potential and possibilities for growth. As we begin this jo
urney together once more, I want to extend a warm welcome to all members of the University of Delaware community—both old and new.
Whether you are returning for another semester or stepping onto campus as a freshman, your presence here enriches our diverse academ
ic environment. We are grateful for the unique perspectives, talents, and skills that each of you brings. Together, we form a vibran
t community with a strong foundation in values, dedicated to transforming possibilities into impactful outcomes.
Our university is built on the principles of diversity, equity, and inclusion. This year, more than ever, these values are at the he
art of our campus culture. We continue to advance initiatives that ensure UD remains accessible to everyone.
The arrival of new students is a key part of our community's fabric. This year, we welcome the Class of 2027—a group of talented ind
ividuals who have come to us with exceptional test scores and GPAs. Their presence further strengthens our university's reputation f
or academic excellence.
As we navigate this new semester, I encourage everyone to actively engage with the vibrant community around them. Embrace the opport
unities that await you here at UD—from challenging academics to engaging social activities and innovative research. Explore, learn,
and contribute your own unique voice.
Together, we will continue to shape a future where our university thrives as a world-class institution, preparing students for their
leadership roles in society.
Let's make this year one of discovery, collaboration, and positive impact!
Source documents:
2023_08_28_120747.txt /home/furst/LLM/demo/data/2023_08_28_120747.txt 0.643636250412912
2019_08_26_084103.txt /home/furst/LLM/demo/data/2019_08_26_084103.txt 0.6190674300618136
2015_09_01_084152.txt /home/furst/LLM/demo/data/2015_09_01_084152.txt 0.616119388597392
2024_08_26_100859.txt /home/furst/LLM/demo/data/2024_08_26_100859.txt 0.6109821657344754
2020_03_15_211550.txt /home/furst/LLM/demo/data/2020_03_15_211550.txt 0.6072407167106767
2020_07_22_153925.txt /home/furst/LLM/demo/data/2020_07_22_153925.txt 0.6065073534647268
2022_01_03_102651.txt /home/furst/LLM/demo/data/2022_01_03_102651.txt 0.6032120789604264
2025_07_18_094529.txt /home/furst/LLM/demo/data/2025_07_18_094529.txt 0.6026328255509924
2020_06_23_150652.txt /home/furst/LLM/demo/data/2020_06_23_150652.txt 0.6024682670824563
2020_09_01_091133.txt /home/furst/LLM/demo/data/2020_09_01_091133.txt 0.6008153126432857
2019_12_20_204740.txt /home/furst/LLM/demo/data/2019_12_20_204740.txt 0.6004832985448465
2021_08_30_132201.txt /home/furst/LLM/demo/data/2021_08_30_132201.txt 0.5990430273606064
2017_01_06_105509.txt /home/furst/LLM/demo/data/2017_01_06_105509.txt 0.5987792036926197
2016_08_30_131858.txt /home/furst/LLM/demo/data/2016_08_30_131858.txt 0.5984471678852645
2010_11_08_110641.txt /home/furst/LLM/demo/data/2010_11_08_110641.txt 0.597488798362081
Elapsed time: 6.9 seconds
Loading llama_index.core.storage.kvstore.simple_kvstore from ./storage/docstore.json.
Loading llama_index.core.storage.kvstore.simple_kvstore from ./storage/index_store.json.
Enter a search topic or question (or 'exit'): welcome back to a new school year
## Welcome Back to a New School Year!
The start of a new academic year is always an exciting time, filled with potential and possibilities for growth. As we begin this jo
urney together once more, I want to extend a warm welcome to all members of the University of Delaware community—both old and new.
Whether you are returning for another semester or stepping onto campus as a freshman, your presence here enriches our diverse academ
ic environment. We are grateful for the unique perspectives, talents, and skills that each of you brings. Together, we form a vibran
t community with a strong foundation in values, dedicated to transforming possibilities into impactful outcomes.
Our university is built on the principles of diversity, equity, and inclusion. This year, more than ever, these values are at the he
art of our campus culture. We continue to advance initiatives that ensure UD remains accessible to everyone.
The arrival of new students is a key part of our community's fabric. This year, we welcome the Class of 2027—a group of talented ind
ividuals who have come to us with exceptional test scores and GPAs. Their presence further strengthens our university's reputation f
or academic excellence.
As we navigate this new semester, I encourage everyone to actively engage with the vibrant community around them. Embrace the opport
unities that await you here at UD—from challenging academics to engaging social activities and innovative research. Explore, learn,
and contribute your own unique voice.
Together, we will continue to shape a future where our university thrives as a world-class institution, preparing students for their
leadership roles in society.
Let's make this year one of discovery, collaboration, and positive impact!
Source documents:
2023_08_28_120747.txt /home/furst/LLM/demo/data/2023_08_28_120747.txt 0.643636250412912
2019_08_26_084103.txt /home/furst/LLM/demo/data/2019_08_26_084103.txt 0.6190674300618136
2015_09_01_084152.txt /home/furst/LLM/demo/data/2015_09_01_084152.txt 0.616119388597392
2024_08_26_100859.txt /home/furst/LLM/demo/data/2024_08_26_100859.txt 0.6109821657344754
2020_03_15_211550.txt /home/furst/LLM/demo/data/2020_03_15_211550.txt 0.6072407167106767
2020_07_22_153925.txt /home/furst/LLM/demo/data/2020_07_22_153925.txt 0.6065073534647268
2022_01_03_102651.txt /home/furst/LLM/demo/data/2022_01_03_102651.txt 0.6032120789604264
2025_07_18_094529.txt /home/furst/LLM/demo/data/2025_07_18_094529.txt 0.6026328255509924
2020_06_23_150652.txt /home/furst/LLM/demo/data/2020_06_23_150652.txt 0.6024682670824563
2020_09_01_091133.txt /home/furst/LLM/demo/data/2020_09_01_091133.txt 0.6008153126432857
2019_12_20_204740.txt /home/furst/LLM/demo/data/2019_12_20_204740.txt 0.6004832985448465
2021_08_30_132201.txt /home/furst/LLM/demo/data/2021_08_30_132201.txt 0.5990430273606064
2017_01_06_105509.txt /home/furst/LLM/demo/data/2017_01_06_105509.txt 0.5987792036926197
2016_08_30_131858.txt /home/furst/LLM/demo/data/2016_08_30_131858.txt 0.5984471678852645
2010_11_08_110641.txt /home/furst/LLM/demo/data/2010_11_08_110641.txt 0.597488798362081
Elapsed time: 6.9 seconds
I'm not going to say that we could totally replace university administration with AI and focus those cost savings on more teaching, scholarship, and service (perhaps by hiring more faculty and staff), but I, for one, welcome our new robot overlords!