Adapting LLMs: Context Injection vs. Fine-Tuning › Context Injection (Prompt Engineering & RAG)

Michael BrenndoerferJuly 22, 20252 min read
Adapting LLMs: Context Injection vs. Fine-Tuning › Context Injection (Prompt Engineering & RAG)One section · Sections in this article3 / 8 ↓
Instead of altering the model, you provide additional context in the prompt to guide its response. This can range from simple prompt engineering to full Retrieval-Augmented Generation (RAG) pipelines. ## Prompt Engineering You include instructions or background info directly in the prompt. **Examples:** - Prepending "You are an expert financial advisor..." (role setting) - Supplying a few Q&A examples to shape the model's style and behavior (few-shot learning) **Benefits:** - Requires no training - you're essentially programming the model with natural language - Easy to adjust and iterate **Limitations:** - Prompt tweaks can yield different results - The model may ignore or misinterpret instructions if they conflict with its training ## Retrieval-Augmented Generation (RAG) This is a more advanced form of context injection where the model is coupled with an external knowledge base. **How it Works:** When a query comes in, you retrieve relevant documents (e.g. from your proprietary data or latest information) and prepend them to the model's prompt as context. The model then generates an answer using both its built-in knowledge and the provided text. **Why it's Powerful:** RAG "plugs" the LLM into fresh or private data that it otherwise wouldn't have. Importantly, the base model itself isn't changed - you're just feeding it helpful data each time. ## Advantages of Context Injection - **Preserved Capabilities**: Maintains the model's broad abilities (since you don't alter its weights) - **Current Knowledge**: Ensures up-to-date, specific knowledge is available when needed - **Reduced Hallucinations**: RAG provides grounded answers from real documents - **Privacy-Friendly**: Keeps private data out of model weights - documents remain in a separate database - **Easy Updates**: If your knowledge changes, just update documents without retraining ## Disadvantages of Context Injection - **Context Limits**: You can only feed so much text before hitting the prompt length limit (context size is becoming less of a problem, but long context show deteroation in performance) - **Engineering Complexity**: Requires embedding index, vector search, and retrieval infrastructure - **Latency Issues**: Each query requires re-supplying context, which can increase response time and cost - **Inconsistency**: Prompt engineering may not work for very specialized tasks or yield inconsistent results