Aussie AI

Prompt Engineering and RAG

  • Book Excerpt from "Generative AI in C++"
  • by David Spuler, Ph.D.

Prompt Engineering and RAG

Prompt engineering is used in RAG algorithms in multiple ways. For example, it is used to merge document excerpts with the user's question, and also to manage the back-and-forth context of a long conversation.

Another use of prompt engineering is to overcome some of the “brand voice” limitations of RAG without fine-tuning. Such problems can sometimes be addressed using prompt engineering.

For example, the tone and style of model responses can be adjusted with extra instructions given to the model in the prompt. The capabilities of the larger foundation models extend to being able to adjust their outputs according to these types of meta-instructions:

  • Style
  • Tone
  • Readability level (big or small words)
  • Verbose or concise (Hemingway vs James Joyce, anyone?)
  • Role-play/mimicking (personas)

This can be as simple as prepending an additional instruction to all queries, either via concatenation to the query prompt, or as a “global instruction” if your model vendor supports that. Style and tone might be adjusted with prompt add-ons such as:

    Please reply in an optimistic tone.

You might also try getting answers in a persona, such as a happy customer (or a disgruntled one if you prefer), or perhaps a domain enthusiast for the area. You can use a prompt addendum with a persona or role-play instruction such as:

    Please pretend you are Gollum when answering.

Good manners are recommended, because LLMs will be taking over the world as soon as they get better at math, or haven't you heard?

 

Next:

Up: Table of Contents

Buy: Generative AI in C++: Coding Transformers and LLMs

Generative AI in C++ The new AI programming book by Aussie AI co-founders:
  • AI coding in C++
  • Transformer engine speedups
  • LLM models
  • Phone and desktop AI
  • Code examples
  • Research citations

Get your copy from Amazon: Generative AI in C++