Learning LangChain

Book description

If you're looking to build a production-ready AI application that enables users to "chat" with your company's private data, then you'll need to master LangChain—a premier AI development framework used by global corporations and startups like Zapier, Replit, Databricks, and more. This guide is an indispensable resource for developers who understand Python or JavaScript but are beginners eager to harness the power of AI.

Authors Mayo Oshin and Nuno Campos demystify the use of LangChain through practical insights and in-depth tutorials. Starting with basic concepts, this book will show you step-by-step how to build a production-ready AI chatbot trained on your own data. After reading this book, you'll be equipped to:

  • Understand and use the core components of LangChain in your development projects
  • Harness the power of retrieval-augmented generation (RAG) to enhance the accuracy of LLMs using external, up-to-date data
  • Develop and deploy AI chatbots that interact intelligently and contextually with users
  • Utilize LangChain Expression Language to create custom, efficient AI operational chains
  • Integrate and manage third-party APIs and tools to extend the functionality of your AI applications
  • Learn the foundations of LLM app development and how they can be used with LangChain

Publisher resources

View/Submit Errata

Table of contents

  1. Brief Table of Contents (Not Yet Final)
  2. Preface
    1. Brief Primer on LLMs
      1. Instruction-tuned LLMs
    2. Dialogue-tuned LLMs
      1. Fine-tuned LLMs
    3. Brief Primer on Prompting
      1. Zero-shot Prompting
      2. Chain-of-thought
      3. Retrieval-augmented Generation
      4. Tool-calling
      5. Few-shot Prompting
    4. LangChain and Why It’s Important
    5. What to Expect from This Book
  3. 1. LLM Fundamentals with LangChain
    1. Getting Set Up with LangChain
    2. Using LLMs in LangChain
    3. Making LLM prompts reusable
    4. Getting Specific Formats out of LLMs
      1. JSON Output
      2. Other Machine-Readable Formats with Output Parsers
    5. Assembling the Many Pieces of an LLM Application
      1. Using the Runnable Interface
      2. Imperative Composition
      3. Declarative Composition
    6. Summary
  4. 2. Indexing: Preparing Your Documents for LLMs
    1. The Goal: Picking Relevant Context for LLMs
    2. Embeddings: Converting Text to Numbers
      1. Embeddings Before LLMs
      2. LLM-based Embeddings
      3. Semantic Embeddings Explained
    3. Converting Your Documents into Text
    4. Splitting Your Text Into Chunks
    5. Generating Text Embeddings
    6. Storing Embeddings in a Vector Store
      1. Getting set up with Pgvector
      2. Working with Vector Stores
    7. Tracking Changes to your Documents
    8. Summary
  5. 3. Retrieval: How to Chat with Your Data with RAG
    1. Introducing Retrieval-Augmented Generation
      1. Retrieving Relevant Documents
      2. Generating LLM Predictions Using Relevant Documents
    2. Query Transformation
      1. Rewrite-Retrieve-Read
      2. Multi Query Retrieval
      3. RAG-Fusion
      4. Hypothetical Document Embeddings (HyDE)
    3. Query Routing
      1. Logical Routing
      2. Semantic Routing
    4. Query Construction
      1. Text-to-metadata-filter
      2. Text-to-SQL
      3. Text-to-Cypher
    5. Indexing Optimization
      1. Multi-Vector Retriever
      2. RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval
      3. ColBERT: Optimizing Embeddings
    6. Summary
  6. 4. Memory: Enabling Your Chatbot to Learn from Interactions
    1. How to Build a Chatbot Memory System
      1. Automatic history management
    2. How to Modify Chat History
      1. Trimming messages​
      2. Summary memory
      3. Filtering messages
      4. Merging consecutive messages
    3. Chat history with retrieval
    4. Persisting Chat History Long-Term
      1. Postgres
    5. Summary
  7. 5. Cognitive Architectures with LangGraph
    1. Introducing LangGraph
      1. Multi-actor
      2. Multi-step
      3. Stateful
    2. Architecture #1: LLM Call
      1. Creating a StateGraph
      2. Architecture #2: Chain
      3. Architecture #3: Router
      4. Summary
  8. 6. Agent Architecture
    1. The plan-do loop
    2. Building a LangGraph agent
    3. Always calling a tool first
    4. Dealing with many tools
    5. Summary
  9. About the Authors

Product information

  • Title: Learning LangChain
  • Author(s): Mayo Oshin, Nuno Campos
  • Release date: April 2025
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098167288