Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Generative AI on Google Cloud with LangChain
Generative AI on Google Cloud with LangChain

Generative AI on Google Cloud with LangChain: Design scalable generative AI solutions with Python, LangChain, and Vertex AI on Google Cloud

Arrow left icon
Profile Icon Leonid Kuligin Profile Icon Jorge Zaldívar Profile Icon Maximilian Tschochohei
Arrow right icon
$9.99 $35.99
eBook Dec 2024 306 pages 1st Edition
eBook
$9.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Leonid Kuligin Profile Icon Jorge Zaldívar Profile Icon Maximilian Tschochohei
Arrow right icon
$9.99 $35.99
eBook Dec 2024 306 pages 1st Edition
eBook
$9.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Generative AI on Google Cloud with LangChain

Using LangChain with Google Cloud

We, as authors, are so happy that you are interested in generative AI and you have decided to read this book. We wrote this book for engineers and practitioners who want to develop their first generative AI application with LangChain, a great open source framework.

In this chapter, you will install the LangChain framework and experiment with its basic primitives using LangChain Expression Language (LCEL).

We will cover the following main topics:

  • The LangChain framework and the company behind it
  • LangChain primitives - chains and runnables
  • Main LangChain building blocks
  • LangChain with Google Cloud
  • LangChain integration with Google

Technical requirements

To be able to work with the code samples in this chapter, install the langchain-core library by running pip install langchain-core in your terminal.

LangChain

Large language models (LLMs) are the fundamental components required to develop generative AI applications. However, as we will discuss in this book, these applications needed to be extended with state management, retrieval of supplementary data, interactions with the API, and so on. Such extended systems are often referred to as LLM-augmented autonomous agents (LAAs), which are computer programs capable of interacting with their environment and solving complex tasks with their underlying LLM by leveraging past observations and actions [1]. LAAs need orchestration, which is a process through which the LAA controls the underlying LLMs and coordinates the planning and step-by-step execution of a task.

LangChain is one of the most popular open source frameworks for LLM orchestration. Harrison Chase launched it as an open source project in 2022, and it attracted a lot of attention and quickly grew in popularity [2]. In February 2024, the LangChain team raised a Series A round...

LangChain primitives – chains and runnables

As we have discussed, LangChain is a framework for orchestrating your generative AI applications. Let’s look at two key LangChain primitives: runnables and chains.

The most basic LangChain abstract interface is langchain_core/runnables/base.Runnable, and it makes it easy to compose different pieces together for the orchestration [4]. A Runnable defines three main methods (there are some more, mainly for asynchronous applications; you can take a look at the full documentation if you’re interested [4]):

  • invoke calls Runnable on an input. It’s an abstract method that should be defined by the specific implementation.
  • stream calls Runnable on an input and streams chunks of the response. With a default implementation, it just calls the invoke method and yields the output, but if you need proper streaming support, your Runnable should implement this method.
  • batch calls Runnable on a list of inputs ...

Main LangChain building blocks

Let’s have a high-level look at key LangChain building blocks. If you need a refresher on terms such as vectorstore, or embeddings are new to you, feel free to check the Index where you can find more details and links to relevant chapters with more detailed explanations.

Data structures

First, let’s explore some key data structures that you might encounter while developing applications. LangChain uses Pydantic, a Python data validation library; therefore, almost all LangChain data structures are Pydantic base models [7]. For those of you who are new to Pydantic, it’s a data validation Python library that allows you to define your data schemas, and if you haven’t heard about it, then you probably used an alternative schema definition library – dataclasses.

Note that LangChain has also its own langchain_core.load.Serializable class that inherits from Basemodel and adds additional control over serialization of...

LangChain with Google Cloud

To get started, you need to have a Google Cloud project with billing and enable the Vertex AI API on it. If you are new to Google Cloud or you’re unfamiliar with some of the Google Cloud services that we mention during this section, take a look at Chapter 4.

You must authenticate yourself on Google Cloud. Most probably, you’ll be trying things out with a Jupyter notebook (and we’ll look into deploying your application to production in Chapter 16). In that case, you have a few options:

  • If you’re running a Jupyter notebook locally, you can use your local credentials. All you need to do is run the following in the terminal:
    gcloud auth application-default login
  • If you’re running a Colab notebook, you can authenticate with your own credentials (but you’ll need to refresh them each time after your instance is stopped):
    from google.colab import auth
    auth.authenticate_user()

If you’re using a Jupyter...

LangChain integration with Google

What is an integration? LangChain exposes a set of interfaces, and different libraries or vendors can integrate with LangChain through their own implementation of these interfaces (of course, they might support additional parameters or features that other providers don’t have). The most obvious example of an interface is an interface for an LLM itself (we’ll discuss this in more detail in Chapter 3). You can think about your LangChain code as being a stateless transformation, and everything that requires I/O or state preservation (e.g., working with your data or storing the history of a chat conversation) will connect to different providers of such services (LLMs, databases, document storage, etc.) through an integration.

The open source community and Google continuously work together on bringing the LangChain experience to Google Cloud services:

  • langchain-google-vertexai – Contains integrations that use Vertex AI (a...

Summary

In this chapter, we look into the landscape of LangChain products and libraries. We explained that LangChain is an open source framework for developing generative AI applications, and how they integrate with service providers. We also briefly looked at LangChain itself, the start-up behind this great framework.

Then, we discussed key LangChain primitives – the data structures that are based on Pydantic models and the main interfaces that are used in chains. We looked into what a chain is and at key primitives of LCEL – a declarative language to develop new chains. Now, you should be able to easily read LangChain code and understand what’s happening behind the scenes.

Finally, we looked at the integrations available with Google products, and we’ll explore their practical usage throughout the book.

Having the big picture in front of us, let’s start to dive deeper. In the next chapter, we’ll look into the basics of how to use...

References

  1. BOLAA: Benchmarking and Orchestrating LLM-augmented Autonomous Agents, Z. Liu et al., 2023:

    https://arxiv.org/abs/2308.05960

  2. LangChain, Wikipedia:

    https://en.wikipedia.org/wiki/LangChain

  3. Announcing the General Availability of LangSmith and Our Series A Led By Sequoia Capital, Langchain blog:

    https://blog.langchain.dev/langsmith-ga/

  4. LangChain Expression Language Interface, Langchain:

    https://python.langchain.com/docs/expression_language/interface

  5. Evaluation order, Python Language Reference:

    https://docs.python.org/3/reference/expressions.html#evaluation-order

  6. Service accounts overview, Google Cloud documentation:

    https://cloud.google.com/iam/docs/service-account-overview

  7. Pydantic, product documentation:

    https://docs.pydantic.dev/latest/

  8. Gemma: Introducing new state-of-the-art open models, J. Banks, T. Warkentin:

    https://blog.google/technology/developers/gemma-open-models/

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Solve real-world business problems with hands-on examples of GenAI applications on Google Cloud
  • Learn repeatable design patterns for Gen AI on Google Cloud with a focus on architecture and AI ethics
  • Build and implement GenAI agents and workflows, such as RAG and NL2SQL, using LangChain and Vertex AI
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

The rapid transformation and enterprise adoption of GenAI has created an urgent demand for developers to quickly build and deploy AI applications that deliver real value. Written by three distinguished Google AI engineers and LangChain contributors who have shaped Google Cloud’s integration with LangChain and implemented AI solutions for Fortune 500 companies, this book bridges the gap between concept and implementation, exploring LangChain and Google Cloud’s enterprise-ready tools for scalable AI solutions. You'll start by exploring the fundamentals of large language models (LLMs) and how LangChain simplifies the development of AI workflows by connecting LLMs with external data and services. This book guides you through using essential tools like the Gemini and PaLM 2 APIs, Vertex AI, and Vertex AI Search to create sophisticated, production-ready GenAI applications. You'll also overcome the context limitations of LLMs by mastering advanced techniques like Retrieval-Augmented Generation (RAG) and external memory layers. Through practical patterns and real-world examples, you’ll gain everything you need to harness Google Cloud’s AI ecosystem, reducing the time to market while ensuring enterprise scalability. You’ll have the expertise to build robust GenAI applications that can be tailored to solve real-world business challenges.

Who is this book for?

If you’re an application developer or ML engineer eager to dive into GenAI, this book is for you. Whether you're new to LangChain or Google Cloud, you'll learn how to use these tools to build scalable AI solutions. This book is ideal for developers familiar with Python and machine learning basics looking to apply their skills in GenAI. Professionals who want to explore Google Cloud's powerful suite of enterprise-grade GenAI products and their implementation will also find this book useful.

What you will learn

  • Build enterprise-ready applications with LangChain and Google Cloud
  • Navigate and select the right Google Cloud generative AI tools
  • Apply modern design patterns for generative AI applications
  • Plan and execute proof-of-concepts for enterprise AI solutions
  • Gain hands-on experience with LangChain's and Google Cloud's AI products
  • Implement advanced techniques for text generation and summarization
  • Leverage Vertex AI Search and other tools for scalable AI solutions

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 20, 2024
Length: 306 pages
Edition : 1st
Language : English
ISBN-13 : 9781835889336
Category :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 20, 2024
Length: 306 pages
Edition : 1st
Language : English
ISBN-13 : 9781835889336
Category :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
Banner background image

Table of Contents

19 Chapters
Part 1: Intro to LangChain and Generative AI on Google Cloud Chevron down icon Chevron up icon
Chapter 1: Using LangChain with Google Cloud Chevron down icon Chevron up icon
Chapter 2: Foundational Models on Google Cloud Chevron down icon Chevron up icon
Part 2: Hallucinations and Grounding Responses Chevron down icon Chevron up icon
Chapter 3: Grounding Responses Chevron down icon Chevron up icon
Chapter 4: Vector Search on Google Cloud Chevron down icon Chevron up icon
Chapter 5: Ingesting Documents Chevron down icon Chevron up icon
Chapter 6: Multimodality Chevron down icon Chevron up icon
Part 3: Common Generative AI Architectures Chevron down icon Chevron up icon
Chapter 7: Working with Long Context Chevron down icon Chevron up icon
Chapter 8: Building Chatbots Chevron down icon Chevron up icon
Chapter 9: Tools and Function Calling Chevron down icon Chevron up icon
Chapter 10: Agents Chevron down icon Chevron up icon
Chapter 11: Agentic Workflows Chevron down icon Chevron up icon
Part 4: Designing Generative AI Applications Chevron down icon Chevron up icon
Chapter 12: Evaluating GenAI Applications Chevron down icon Chevron up icon
Chapter 13: Generative AI System Design Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.