All 29 lessons
Foundations: what RAG is and a working pipeline
Better retrieval: chunking and search
Answers you can trust, measure and debug
Production in a company
Agentic RAG
Frameworks: LangChain, LangGraph and LangSmith
- 24. The RAG toolbox: what each library does and why you import it
- 25. The framework landscape: LangChain, LangGraph, LlamaIndex, Haystack
- 26. Lab: Ask Brightline in LangChain
- 27. Lab: agentic RAG as a LangGraph graph
- 28. Lab: tracing, evaluating and monitoring with LangSmith
- 29. Wrap-up: your production agentic RAG checklist
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.
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-transformersexport ANTHROPIC_API_KEY=... # your own keyexport CLAUDE_MODEL=claude-sonnet-5-5
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.
from langchain_core.documents import Documentcorpus = {"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")
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.
from langchain_text_splitters import RecursiveCharacterTextSplittersplitter = 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])
{'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
Step 3: embeddings and a vector store
from langchain_huggingface import HuggingFaceEmbeddingsfrom langchain_core.vectorstores import InMemoryVectorStoreembeddings = 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])
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
import osfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_anthropic import ChatAnthropicprompt = 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 modelsretriever = vector_store.as_retriever(search_kwargs={"k": 2})
Step 5: retrieve, show the prompt, answer
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 readreturn model.invoke(messages).textprint(answer("What is the hotel limit in Boston?"))
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
from langchain.chains import RetrievalQA # from an older tutorial
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.
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
- LangChain packages the same pipeline: Document, splitter, embeddings, vector store, retriever, model.
- Swapping a vector store or model changes one line, which is the framework's main payoff.
- Print the rendered prompt while developing, so the abstraction doesn't hide it.
- 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.