paint-brush
Explaining Prompt Engineeringby@docligot
New Story

Explaining Prompt Engineering

by Dominic LigotNovember 14th, 2024
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

How and why does prompt engineering actually work.
featured image - Explaining Prompt Engineering
Dominic Ligot HackerNoon profile picture

The art of prompt engineering is becoming a critical skill for effectively harnessing AI's potential as artificial intelligence continues to evolve. Yet, for all its importance, prompt engineering is often reduced to simplistic advice—tips like “be specific” or quick hacks such as “let’s think step by step.”


While helpful for beginners, these pointers barely scratch the surface. True prompt engineering requires a much deeper understanding of the mechanics behind AI responses, moving far beyond what’s often little more than zero-shot Google searching. Here we go through some foundational principles to explain why good prompting actually works.


Embeddings: The Foundation of Prompt Understanding

One of the foundational concepts in effective prompting is understanding embeddings. When we input a prompt into a model, it doesn’t process language as we do; instead, each word or phrase is transformed into an embedding, a numerical representation that captures both the meaning and context of the language. These embeddings act as the model’s internal mapping, helping it interpret relationships, nuances, and associations between words.


Source: Tensorflow Embedding Projector


For prompt engineers, understanding embeddings is essential for prompt intuition. The way a word is represented in embedding space determines how the model interprets it, affecting the content and focus of responses. For example, if a prompt requests information on “manufacturing,” the model will pull content based on embeddings linked to those terms, potentially drawing from areas like production processes, supply chain logistics, or technological advancements. A prompt engineer can influence these responses by skillfully crafting the wording, improving the relevance and depth of the output.


Understanding embeddings also empowers prompt engineers to chain prompts better, where each response builds on previous interactions. By crafting sequences with embedding relationships in mind, prompt engineers create complex, context-aware conversations that adapt to specific needs, producing detailed, responsive outputs.


The Role of Attention: Guiding Model Focus

Another core component in prompt engineering is attention. Unlike human attention, which can dynamically shift between different topics, AI attention assigns weight to relationships between words within the prompt and response text. Attention helps the model prioritize certain parts of the input, and a well-crafted prompt uses this to shape the model’s focus. Take, for instance, a prompt asking for a nuanced view of a cat sitting on a mat.


Source: Bertviz Interactive Tutorial


Prompt engineers can guide the model to emphasize relevant aspects of the prompt's subject, such as the cat's posture, the texture and color of the mat, or the overall scene’s ambiance, leading to a more detailed and vivid response. This approach to prompting. known as directional stimulus, allows the extraction of richer, more relevant answers from the model.

RAG: Retrieval-Augmented Generation for Enhanced Responses

Retrieval-Augmented Generation (RAG) combines generative AI with retrieval systems to improve the accuracy and relevance of responses. Traditional prompt engineering relies on a model’s internal knowledge, which can be outdated or incomplete. RAG addresses this by adding a retrieval layer that pulls in current, contextually relevant information from external sources like databases or search engines, enabling the model to provide more accurate, up-to-date answers.


Typical RAG process


RAG is transformative for prompt engineering. It allows engineers to structure prompts that direct both the retrieval and generative components to work together, especially valuable for complex or fast-evolving subjects. For instance, a prompt about “recent changes in data privacy laws” could trigger the model to fetch the latest legal documents or news, which it then combines with internal information via RAG to synthesize into a coherent response. This dual capability reduces hallucinations and keeps the model grounded in real-time, reliable information.


Prompt engineers working within RAG frameworks can therefore create interactions that are both innovative and anchored in current knowledge, adding an extra layer of sophistication to the AI’s output.

Image Prompting and the Diffusion Process

In image generation, prompt engineering takes on another layer of complexity. Here, prompts are not just about words but about guiding a model through the diffusion process—a technique where random noise is iteratively transformed into a coherent image. The diffusion process relies on iterative adjustments, and each cycle builds upon the previous one to refine an image based on the prompt's guidance.


Source: Midjourney - cat <prompt>



When crafting prompts for image generation, understanding diffusion is essential. Descriptions like “award winning photography” or “fashion photography” can yield varying results depending on how the model interprets "award winning" or “fashion.” Prompt engineers must understand the model’s interpretation of spatial relationships, color, and composition to produce a desired outcome. It’s about more than aesthetics; it’s about leading the model through each step to align with the intended visual concept.


Hallucinations and the Pitfalls of Poor Prompting

One of the most challenging aspects of AI prompting is managing hallucinations—when a model produces content that sounds plausible but is entirely fabricated. Hallucinations often result from vague or poorly structured prompts, which leave too much to the model’s interpretation. In fields like healthcare or finance, where accuracy is critical, even a small hallucination can have serious consequences.


Skilled prompt engineers prevent this by constructing prompts that minimize ambiguity, verifying outputs with fact-checking prompts, and maintaining strict clarity and focus.


Why Prompt Engineering is a Real Skill

Ultimately, prompt engineering is a genuine skill that combines language intuition with a deep technical understanding of AI mechanics. Unlike simple search queries, prompt engineers with knowledge of embeddings, attention mechanisms, and model limitations are able to craft better prompts. Mastering these elements enables prompt engineers to shape responses that are precise, reliable, and often surprisingly creative.


The need for skilled prompt engineers will only grow as AI technology continues to integrate into industries from education to entertainment. They’ll be essential not just for generating content, but for refining AI applications, troubleshooting outputs, and optimizing model performance across fields. Far from a passing trend, prompt engineering is shaping up to be one of the defining skills of the AI era—an essential tool for building communication between humans and machines.



About Me: 25+ year IT veteran combining data, AI, risk management, strategy, and education. 4x global hackathon winner and social impact from data advocate. Currently working to jumpstart the AI workforce in the Philippines. Learn more about me here.