📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Generative AI Engineering LangChain Fundamentals

LangChain Fundamentals

5 min read
LangChain chains, prompts, retrievers, and LCEL pipe syntax for composing LLM application logic.

LangChain Fundamentals

# pip install langchain langchain-anthropic langchain-openai

from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.vectorstores import Chroma
from langchain_core.runnables import RunnablePassthrough

llm = ChatAnthropic(model='claude-opus-4-5')

# Simple chain with LCEL pipe syntax
prompt = ChatPromptTemplate.from_messages([
    ('system', 'You are a helpful assistant.'),
    ('user', '{question}')
])
chain = prompt | llm
result = chain.invoke({'question': 'What is RAG?'})
print(result.content)

# RAG chain
retriever = Chroma(...).as_retriever(search_kwargs={'k':3})

rag_chain = (
    {'context': retriever, 'question': RunnablePassthrough()}
    | prompt
    | llm
)
response = rag_chain.invoke('What is Docker?')

# Key LangChain concepts
# Chain      -- sequence of operations (LCEL: a | b | c)
# Retriever  -- returns relevant documents
# Memory     -- conversation history management
# Agent      -- LLM decides which tools to use
# Tool       -- callable function with name and description