← Back to blog
2026.2.10|Article

Building RAG Systems with LangChain

RAGLangChainPythonAI

What is RAG?

Retrieval-Augmented Generation (RAG) combines a vector search step with an LLM to ground responses in your own documents. Instead of relying solely on the model's training data, RAG fetches relevant context at query time.

Quick Example with LangChain

from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI

embeddings = OpenAIEmbeddings()
vectorstore = Chroma.from_documents(documents, embeddings)

qa_chain = RetrievalQA.from_chain_type(
    llm=OpenAI(),
    retriever=vectorstore.as_retriever(search_kwargs={"k": 4}),
)

result = qa_chain.run("What does the document say about AI?")
print(result)

Key Components

  • Document loader — ingest PDFs, web pages, databases
  • Text splitter — chunk documents into overlapping segments
  • Embedding model — convert text to dense vectors
  • Vector store — fast approximate nearest-neighbour search
  • LLM — synthesise an answer from retrieved context