liveBook · Manning

Retrieval-augmented generation

As explained in Essential GraphRAG

A retrieval-augmented generation pipeline combines information retrieval with language-model generation to produce responses grounded in retrieved information.

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

How Essential GraphRAG covers it

How deep it goes
Explains retrieval and generation, implements vector and advanced pipelines, and extends the pattern with knowledge graphs.
Examples
Uses an Einstein inventions paper, an Einstein patent question, prompt templates, vector-search data flows, and The Odyssey graph pipeline.
What it assumes
Assumes familiarity with language models and prompts while introducing external knowledge injection and retrieval stages.
What you can do after
Build it from scratch as a vector-search RAG pipeline and evaluate step-back prompting against a simpler retrieval approach.
How it connects
Connects language models with external knowledge bases, vector similarity search, query rewriting, parent document retrieval, and knowledge graphs.

Also explained in

Compare how 32 books explain retrieval-augmented generation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential GraphRAG. The section links point to the parts of the book it draws on.