Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Unlocking Data with Generative AI and RAG

You're reading from   Unlocking Data with Generative AI and RAG Enhance generative AI systems by integrating internal data with large language models using RAG

Arrow left icon
Product type Paperback
Published in Sep 2024
Publisher Packt
ISBN-13 9781835887905
Length 346 pages
Edition 1st Edition
Concepts
Arrow right icon
Author (1):
Arrow left icon
Keith Bourne Keith Bourne
Author Profile Icon Keith Bourne
Keith Bourne
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part 1 – Introduction to Retrieval-Augmented Generation (RAG) FREE CHAPTER
2. Chapter 1: What Is Retrieval-Augmented Generation (RAG) 3. Chapter 2: Code Lab – An Entire RAG Pipeline 4. Chapter 3: Practical Applications of RAG 5. Chapter 4: Components of a RAG System 6. Chapter 5: Managing Security in RAG Applications 7. Part 2 – Components of RAG
8. Chapter 6: Interfacing with RAG and Gradio 9. Chapter 7: The Key Role Vectors and Vector Stores Play in RAG 10. Chapter 8: Similarity Searching with Vectors 11. Chapter 9: Evaluating RAG Quantitatively and with Visualizations 12. Chapter 10: Key RAG Components in LangChain 13. Chapter 11: Using LangChain to Get More from RAG 14. Part 3 – Implementing Advanced RAG
15. Chapter 12: Combining RAG with the Power of AI Agents and LangGraph 16. Chapter 13: Using Prompt Engineering to Improve RAG Efforts 17. Chapter 14: Advanced RAG-Related Techniques for Improving Results 18. Index 19. Other Books You May Enjoy

Fundamentals of prompt design

When designing prompts for RAG applications, it’s essential to keep the following fundamentals in mind:

  • Be concise and specific: Clearly define the task you want the AI model to perform, and provide only the necessary information to complete the task effectively. For example, saying Please analyze the given context and provide an answer to the question, taking into account all the relevant information and details would be less concise and specific than saying Based on the context provided, answer the following question: [specific question].
  • Ask one task at a time: Break down complex tasks into smaller, more manageable sub-tasks, and create separate prompts for each sub-task to ensure better results. For example, if you said Summarize the main points of the context, identify the key entities mentioned, and then answer the given question, that is multiple tasks you are asking for at the same time. You would likely have better results if you broke this into multiple prompts and said something similar to this:
    • Summarize the main points of the following context: [context]
    • Identify the key entities mentioned in the following summary: [summary from previous prompt]
    • Using the context and entities identified, answer the following question: [specific question]
  • Turn generative tasks into classification tasks: When possible, rephrase open-ended generative tasks as classification tasks with a limited set of options, as this can lead to more accurate and focused responses from the AI model. For example, instead of saying Based on the context, what is the sentiment expressed towards the topic?, you would likely have better results if you said Based on the context, classify the sentiment expressed towards the topic as either positive, negative, or neutral.
  • Improve response quality by including examples: We’ll build off the one-or-more-shot concept we talked about previously. This fundamental concept focuses on providing relevant examples in your prompts to guide the AI model toward the desired output format and style. As an example, rather than saying Answer the following question based on the provided context, you would want to say something similar to Using the examples below as a guide, answer the following question based on the provided context: Example 1: [question] [context] [answer] Example 2: [question] [context] [answer] Current question: [question] Context: [context].
  • Start simple and iterate gradually: Begin with simple prompts and gradually add more elements and context as needed to achieve better results. This iterative approach allows you to fine-tune your prompts and optimize performance. For example, the Summarize the main points of the article, identify key entities, and answer the following question: [question]. Provide examples and use the following format for your answer: [format]. Article: [lengthy article text] prompt will likely be less effective than prompting with multiple iterations such as the following:
    • Iteration 1: Summarize the main points of the following article: [article text]
    • Iteration 2: Summarize the main points and identify key entities in the following article: [article text]
    • Iteration 3: Based on the summary and key entities, answer the following question: [question] Article: [article text]
  • Place instructions at the beginning of the prompt: Clearly state the instructions at the start of the prompt, and use clear separators such as ### to distinguish between the instruction and context sections. This helps the AI model better understand and follow the given instructions. For example, you will have less success with a prompt such as [Context] Please use the above context to answer the following question: [question]. Provide your answer in a concise manner compared to this prompt: Instructions: Using the context provided below, answer the question in a concise manner. Context: [context] Question: [question].

While the fundamentals of prompt design provide a solid foundation for creating effective prompts, it’s important to remember that different language models may require specific adaptations to achieve optimal results. Let’s discuss that topic next.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image