Black Friday50% off your first month on any monthly plan with EARLY50 See plans
All 29 lessons
  1. Foundations: what RAG is and a working pipeline

    1. 1. Getting started: what RAG is and when to use it
    2. 2. Types of RAG: a map from naive to agentic
    3. 3. Lab: build the smallest RAG pipeline end to end
    4. 4. How embeddings and vector search find meaning
    5. 5. Document types: what each one breaks, and how to prepare it
  2. Better retrieval: chunking and search

    1. 6. Chunking documents so answers survive
    2. 7. Chunking strategies compared: which to use when
    3. 8. Keyword search vs vector search, and fusing both
    4. 9. Retrieval algorithms compared: which to use when
    5. 10. Reranking the top results before the model reads them
    6. 11. Rewriting the question before you search
  3. Answers you can trust, measure and debug

    1. 12. Lab: grounded answers with citations and refusals
    2. 13. Measuring a RAG system with an evaluation set
    3. 14. Lab: evaluation methods and frameworks: Ragas and DeepEval
    4. 15. Troubleshooting a RAG system, symptom by symptom
  4. Production in a company

    1. 16. Access control: only retrieve what the user may see
    2. 17. Defending against prompt injection in retrieved text
    3. 18. Running RAG in production: freshness, cost and monitoring
    4. 19. Real-world RAG: what worked, what failed, and why
  5. Agentic RAG

    1. 20. Lab: from a fixed pipeline to an agent with a search tool
    2. 21. Self-correcting retrieval: grade, retry, fall back
    3. 22. GraphRAG and routing across many sources
    4. 23. Lab: numbers, tables and financial documents
  6. Frameworks: LangChain, LangGraph and LangSmith

    1. 24. The RAG toolbox: what each library does and why you import it
    2. 25. The framework landscape: LangChain, LangGraph, LlamaIndex, Haystack
    3. 26. Lab: Ask Brightline in LangChain
    4. 27. Lab: agentic RAG as a LangGraph graph
    5. 28. Lab: tracing, evaluating and monitoring with LangSmith
    6. 29. Wrap-up: your production agentic RAG checklist
See the leaderboard

20 min

Lab: Ask Brightline in LangChain

Rebuild the RAG pipeline with LangChain's loaders, splitters, vector store, retriever and chat model.

By the end of this lesson you can

  • Build a LangChain RAG pipeline: documents, splitter, embeddings, vector store, retriever, model
  • Map each LangChain component to the plain-Python code from earlier labs
  • Print the exact prompt LangChain sends, and fix a stale import

From earlier lessons · 1 of 2

What's the main cost of using a framework?

Pick one answer.

From earlier lessons · 2 of 2

What does LangGraph add on top of plain components?

Pick one answer.

A 2024 tutorial promises RAG in ten lines of LangChain. You paste it into a fresh project and the very first import fails. The library moved on, and the tutorial didn't.

Lab: Ask Brightline in LangChain

You'll rebuild lab 1's pipeline with LangChain components, checked against langchain 1.5 and langchain-core 1.8 in November 2026. Embeddings run locally, as before; only the answer step calls Claude. These packages change often, so pin the versions you test with.

[25][26]

bash
python3 --version # 3.12 or newer (langchain 1.5 needs 3.11, numpy 2.5 needs 3.12)
pip install "langchain==1.5.*" "langchain-core==1.8.*" langchain-text-splitters \
langchain-anthropic langchain-huggingface sentence-transformers
export ANTHROPIC_API_KEY=... # your own key
export CLAUDE_MODEL=claude-sonnet-5-5
Terminal. On older Pythons, pip quietly installs older versions instead of failing, and later imports break.

Step 1: documents with metadata

A Document is LangChain's unit of text: page_content plus a metadata dict. Metadata carries the source id for citations, and later the groups and dates from lessons 16 and 18.

python
from langchain_core.documents import Document
corpus = {
"travel-hotel": "Hotels: up to $250 per night in Tier 1 cities (New York, San Francisco, Chicago, Boston) and $175 elsewhere. Stays above the limit need a director's written approval before booking.",
"travel-meals": "Meals on business travel are reimbursed up to $75 per day. Alcohol is not reimbursable. Submit receipts within 30 days.",
"it-vpn": "To reset your VPN token, open the Brightline Access app, choose Reset token and confirm with your badge PIN. Error VPN-0x80 means the token expired.",
"hr-pto": "Full-time employees accrue 1.5 days of paid time off per month. Up to 10 unused days carry over to the next year.",
}
docs = [Document(page_content=text, metadata={"source": src}) for src, text in corpus.items()]
print(len(docs), "documents")
Real output: 4 documents

Step 2: split with the recursive splitter

This is lesson 7's recursive splitting: paragraphs first, then lines, then sentences, then words. The chunk size is tiny here, 120 characters, so you can see the cuts and the overlap.

python
from langchain_text_splitters import RecursiveCharacterTextSplitter
splitter = RecursiveCharacterTextSplitter(chunk_size=120, chunk_overlap=20, add_start_index=True)
chunks = splitter.split_documents(docs)
for c in chunks:
print(c.metadata, c.page_content[:60])
text
{'source': 'travel-hotel', 'start_index': 0} Hotels: up to $250 per night in Tier 1 cities (New York, San
{'source': 'travel-hotel', 'start_index': 109} Stays above the limit need a director's written approval bef
{'source': 'travel-meals', 'start_index': 0} Meals on business travel are reimbursed up to $75 per day. Al
{'source': 'it-vpn', 'start_index': 0} To reset your VPN token, open the Brightline Access app, choos
{'source': 'it-vpn', 'start_index': 98} badge PIN. Error VPN-0x80 means the token expired.
{'source': 'hr-pto', 'start_index': 0} Full-time employees accrue 1.5 days of paid time off per mon
Real output. Six chunks; each keeps its source metadata, and the overlap repeats words like "badge PIN. Error" across a boundary.

Step 3: embeddings and a vector store

python
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_core.vectorstores import InMemoryVectorStore
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
vector_store = InMemoryVectorStore(embeddings)
vector_store.add_documents(chunks)
for doc, score in vector_store.similarity_search_with_score("What is the hotel limit in Boston?", k=2):
print(round(score, 3), doc.metadata["source"], doc.page_content[:50])
Real output: 0.605 travel-hotel Hotels: up to $250 per night... then 0.42 travel-hotel Stays above the limit... Scores are cosine similarity: higher is closer.

Same model and same scores as lesson 4, behind a standard interface. To move to a real vector database, you swap InMemoryVectorStore for that store's LangChain class. The rest of the code stays the same.

Step 4: prompt, model and retriever

python
import os
from langchain_core.prompts import ChatPromptTemplate
from langchain_anthropic import ChatAnthropic
prompt = ChatPromptTemplate.from_messages([
("system", "Answer using only the context below. Cite sources in brackets. "
"If the answer is not there, say you don't know.\n\nContext:\n{context}"),
("human", "{question}"),
])
model = ChatAnthropic(model=os.environ["CLAUDE_MODEL"]) # don't set temperature on newer models
retriever = vector_store.as_retriever(search_kwargs={"k": 2})
The docs note newer Claude models reject a non-default temperature, so leave it out.

Step 5: retrieve, show the prompt, answer

python
def answer(question):
found = retriever.invoke(question)
context = "\n\n".join(f"[{d.metadata['source']}] {d.page_content}" for d in found)
messages = prompt.invoke({"context": context, "question": question})
print(messages.to_messages()[0].content) # exactly what the model will read
return model.invoke(messages).text
print(answer("What is the hotel limit in Boston?"))
Expected output: the system prompt with both travel-hotel chunks, then an answer like "Up to $250 per night, since Boston is a Tier 1 city [travel-hotel]." Your wording will differ. One model call.

Printing the rendered prompt gets back the visibility a framework takes away. Keep that print while you develop, then move it to tracing in lesson 28. Note .text is a property in LangChain 1.x; calling .text() still works but warns.

Issue: the 2024 tutorial import

python
from langchain.chains import RetrievalQA # from an older tutorial
Real output on langchain 1.5: ModuleNotFoundError: No module named 'langchain.chains'. Legacy chains moved to the separate langchain-classic package.

LangChain 1.0 slimmed down the main package. Old chains like RetrievalQA, the old retrievers and the hub moved to langchain-classic. Splitters live in langchain-text-splitters, and agents are built with create_agent from langchain.agents. The fix is to use the current components, as this lab does, not to install the legacy package.

[29]

Match

Match each LangChain piece to the plain code it replaces

Pick an item on the left, then its match on the right.

Worth keeping

  1. LangChain packages the same pipeline: Document, splitter, embeddings, vector store, retriever, model.
  2. Swapping a vector store or model changes one line, which is the framework's main payoff.
  3. Print the rendered prompt while developing, so the abstraction doesn't hide it.
  4. Pin versions; 1.x moved legacy chains to langchain-classic.

This pipeline searches once and answers. Lesson 21's agent graded results and retried. Next lab draws that agent as a LangGraph graph, with a counter that guarantees it stops.

Leaderboard

Loading…

50 XP for each lesson you finish, 10 for each right answer. Names show only for learners who turn on Show me on leaderboards.

Sources for this lesson (3)

Each fact in the lesson is marked with the number of the page it comes from.

  1. [25]LangChain docs: Build a RAG agent
  2. [26]LangChain docs: Retrieval
  3. [29]LangChain docs: Migrating to LangChain v1