Retrieval-augmented generation (RAG) combines a generative language model with an external knowledge base. It retrieves relevant facts at runtime and places them in the input prompt, reducing dependence on internal model knowledge, outdated information, and hallucinations while supporting private or specialized domains. section 1.0 section 1.3.2
A basic RAG workflow separates retrieval from generation:
- Retrieve relevant documents or facts from an external knowledge base or database. section 1.3.2
- Combine the retrieved context with the user’s question in a prompt. section 1.3.2
- Instruct the language model to answer using the supplied documents and task guidelines. section 1.3.2
Vector-similarity RAG commonly divides implementation into data setup and query time. The setup prepares the searchable corpus; query time retrieves information and passes it to the answer-generating function. Retrieval quality remains a practical concern rather than a guarantee of correctness. section 2.2 section 2.2.2
Advanced pipelines can rewrite a question into a broader step-back query, retrieve parent documents, and then answer the original question from those documents. Comparing this pipeline with and without step-back prompting provides a direct evaluation exercise. section 3.3
Knowledge-graph-enhanced RAG adds structured entities, attributes, and relationships to unstructured text retrieval. This supports interconnected, context-rich answers and can connect conversational references with precise records such as products, orders, guidelines, or histories. section 1.0 section 1.5
Einstein patent question
A pipeline turns “When was Einstein granted the patent for his blouse design?” into the broader step-back query “What are some notable achievements in Einstein’s life?”, retrieves parent documents, and answers with October 27, 1936. section 3.3
Listing 3.14 Complete parent document retriever with step-back prompting RAG pipeline
def rag_pipeline(question: str) -> str:
stepback_prompt = generate_stepback(question)
print(f"Stepback prompt: {stepback_prompt}")
documents = parent_retrieval(stepback_prompt)
answer = generate_answer(question, documents)
return answer
Inspect the complete Python-shaped pipeline connecting question rewriting, parent-document retrieval, and grounded answer generation. section 3.3































