Langchain

LLM Application Frameworks

LangChain

Overview
Most popular framework for building LLM applications. Provides abstractions for chains, agents, memory, and tools.

Key Components
| Component | Purpose |
|-----------|---------|
| Chains | Sequential LLM calls |
| Agents | Dynamic tool selection |
| Memory | Conversation history |
| Retrievers | RAG integration |
| Tools | External capabilities |

Example: ReAct Agent

from langchain.agents import create_react_agent
from langchain_openai import ChatOpenAI
from langchain.tools import WikipediaTool

llm = ChatOpenAI(model="gpt-4o")
tools = [WikipediaTool()]
agent = create_react_agent(llm, tools, prompt)

result = agent.invoke({"input": "What is the capital of France?"})

LlamaIndex

Overview
Specialized for data-intensive LLM applications, particularly RAG. Excellent for indexing and querying documents.

Key Components
| Component | Purpose |
|-----------|---------|
| Documents | Data containers |
| Nodes | Chunked text units |
| Indices | Search structures |
| Query Engines | RAG pipelines |
| Response Synthesizers | Answer generation |

Example: RAG

from llama_index import VectorStoreIndex, SimpleDirectoryReader

# Load and index documents
documents = SimpleDirectoryReader("data/").load_data()
index = VectorStoreIndex.from_documents(documents)

# Query
query_engine = index.as_query_engine()
response = query_engine.query("What is the main topic?")

Comparison
| Feature | LangChain | LlamaIndex |
|---------|-----------|------------|
| Primary focus | General LLM apps | Data/RAG |
| Agent support | Excellent | Good |
| RAG capabilities | Good | Excellent |
| Community size | Largest | Large |
| Complexity | Higher | Lower |

Other Frameworks
| Framework | Highlights |
|-----------|------------|
| Haystack | Production RAG |
| Semantic Kernel | Microsoft, enterprise |
| DSPy | Prompt optimization |
| CrewAI | Multi-agent |

When to Use
- LangChain: Complex agents, diverse tools, general LLM apps
- LlamaIndex: Document QA, knowledge bases, RAG-heavy apps
- Both together: LangChain agents + LlamaIndex for data

Take langchain further

Ask the copilot about this term, or have our engineers assess it against your process.