Building AI Agents with LLMs, RAG, and Knowledge Graphs - Salvatore Raieli - E-Book

Building AI Agents with LLMs, RAG, and Knowledge Graphs E-Book

Salvatore Raieli

0,0
43,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

This AI agents book addresses the challenge of building AI that not only generates text but also grounds its responses in real data and takes action. Authored by AI specialists with deep expertise in drug discovery and systems optimization, this guide empowers you to leverage retrieval-augmented generation (RAG), knowledge graphs, and agent-based architectures to engineer truly intelligent behavior. By combining large language models (LLMs) with up-to-date information retrieval and structured knowledge, you'll create AI agents capable of deeper reasoning and more reliable problem-solving.
Inside, you'll find a practical roadmap from concept to implementation. You’ll discover how to connect language models with external data via RAG pipelines for increasing factual accuracy and incorporate knowledge graphs for context-rich reasoning. The chapters will help you build and orchestrate autonomous agents that combine planning, tool use, and knowledge retrieval to achieve complex goals. Concrete Python examples built on popular libraries, along with real-world case studies, reinforce each concept and show you how these techniques come together.
By the end of this book, you’ll be well-equipped to build intelligent AI agents that reason, retrieve, and interact dynamically, empowering you to deploy powerful AI solutions across industries.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 828

Veröffentlichungsjahr: 2025

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Building AI Agents with LLMs, RAG, and Knowledge Graphs

A practical guide to autonomous and modern AI agents

Salvatore Raieli | Gabriele Iuculano

Building AI Agents with LLMs, RAG, and Knowledge Graphs

Copyright © 2025 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Portfolio Director: Gebin George

Relationship Lead: Ali Abdi

Project Manager: Prajakta Naik

Content Engineer: Mark D’Souza

Technical Editor: Irfa Ansari

Copy Editor: Safis Editing

Indexer: Tejal Soni

Production Designer: Alishon Falcon

Growth Lead: Kunal Sawant

First published: July 2025

Production reference: 1300625>

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK

ISBN 978-1-83508-706-0

www.packtpub.com

To Dorotea, Maria, Vincenzo, and Chiara, with love. A small thank you for the immense support.

– Salvatore Raieli

To Marta, for your strength when mine wavered, and for your light in difficult times. Thank you for walking with me through the storms. This book echoes the path we walked together.

– Gabriele Iuculano

The author acknowledges the use of cutting-edge AI, in this case, ChatGPT and Grammarly, with the sole aim of enhancing the language and clarity within the book, thereby ensuring a smooth reading experience for readers. It's important to note that the content itself has been crafted by the author and edited by a professional publishing team.

Contributors

About the authors

Salvatore Raieli is a senior data scientist in a pharmaceutical company with a focus on using AI for drug discovery against cancer. He has led different multidisciplinary projects with LLMs, agents, NLP, and other AI techniques. He has an MSc in AI and a PhD in immunology and has experience in building neural networks to solve complex problems with large datasets. He enjoys building AI applications for concrete challenges that can lead to societal benefits. In his spare time, he writes on his popularization blog on AI (on Medium).

 

Gabriele Iuculano boasts extensive expertise in embedded systems and AI. Leading a team as the test platform architect, Gabriele has been instrumental in architecting a sophisticated simulation system that underpins a cutting-edge test automation platform.

He is committed to integrating AI-driven solutions, focusing on predictive maintenance systems to anticipate needs and prevent downtimes. He obtained his MSc in AI from the University of Leeds, demonstrating expertise in leveraging AI for system efficiencies. Gabriele aims to revolutionize current business through the power of new disruptive technologies such as AI.

About the reviewers

Malhar Deshpande serves as the director and principal product owner of the AI Center of Excellence at Clean Harbors, where he leads AI initiatives, blending data science, machine learning, and generative AI to transform environmental services. With expertise in technology, innovation, and extensive experience in building AI teams, Malhar Deshpande is recognized for driving innovative solutions. He holds a Bachelor of Engineering, a master’s in information systems, and an MBA from Northeastern University. As a technical reviewer, he is honored to contribute to this book, the AI and technology community, and the future of AI.

I am grateful to my parents, Mohan and Asha Deshpande, for their unwavering support and focus on education. Thanks to my wife, Shruti; my daughter, Tara; and my brother, Dr. Rupak, his wife, Dr. Riteeka, and their daughter, Samaira, for their love and encouragement throughout this journey.

Lalit Chourey is a seasoned software engineer with over a decade of experience in developing scalable backend services and distributed systems, specializing in AI infrastructure for LLM training. Currently a software engineer at Meta Platforms, Lalit leads a team in architecting robust systems for machine learning training. Previously at Microsoft, he led the development of several large-scale cloud services on Azure. Lalit holds a BTech in information technology from the National Institute of Technology, Bhopal, India.

Table of Contents

Preface

Part 1: The AI Agent Engine: From Text to Large Language Models

1

Analyzing Text Data with Deep Learning

Technical requirements

Representing text for AI

One-hot encoding

Bag-of-words

TF-IDF

Embedding, application, and representation

Word2vec

A notion of similarity for text

Properties of embeddings

RNNs, LSTMs, GRUs, and CNNs for text

RNNs

LSTMs

GRUs

CNNs for text

Performing sentiment analysis with embedding and deep learning

Summary

2

The Transformer: The Model Behind the Modern AI Revolution

Technical requirements

Exploring attention and self-attention

Introducing the transformer model

Training a transformer

Exploring masked language modeling

Visualizing internal mechanisms

Applying a transformer

Summary

3

Exploring LLMs as a Powerful AI Engine

Technical requirements

Discovering the evolution of LLMs

The scaling law

Emergent properties

Context length

Mixture of experts

Instruction tuning, fine-tuning, and alignment

Exploring smaller and more efficient LLMs

Exploring multimodal models

Understanding hallucinations and ethical and legal issues

Prompt engineering

Summary

Further reading

Part 2: AI Agents and Retrieval of Knowledge

4

Building a Web Scraping Agent with an LLM

Technical requirements

Understanding the brain, perception, and action paradigm

The brain

The perception

Action

Classifying AI agents

Understanding the abilities of single-agent and multiple-agent systems

Exploring the principal libraries

LangChain

Haystack

LlamaIndex

Semantic Kernel

AutoGen

Choosing an LLM agent framework

Creating an agent to search the web

Summary

Further reading

5

Extending Your Agent with RAG to Prevent Hallucinations

Technical requirements

Exploring naïve RAG

Retrieval, optimization, and augmentation

Chunking strategies

Embedding strategies

Embedding databases

Evaluating the output

Comparison between RAG and fine-tuning

Using RAG to build a movie recommendation agent

Summary

Further reading

6

Advanced RAG Techniques for Information Retrieval and Augmentation

Technical requirements

Discussing naïve RAG issues

Exploring the advanced RAG pipeline

Hierarchical indexing

Hypothetical questions and HyDE

Context enrichment

Query transformation

Keyword-based search and hybrid search

Query routing

Reranking

Response optimization

Modular RAG and its integration with other systems

Training and training-free approaches

Implementing an advanced RAG pipeline

Understanding the scalability and performance of RAG

Data scalability, storage, and preprocessing

Parallel processing

Security and privacy

Open questions and future perspectives

Summary

Further reading

7

Creating and Connecting a Knowledge Graph to an AI Agent

Technical requirements

Introduction to knowledge graphs

A formal definition of graphs and knowledge graphs

Taxonomies and ontologies

Creating a knowledge graph with your LLM

Knowledge creation

Creating a knowledge graph with an LLM

Knowledge assessment

Knowledge cleaning

Knowledge enrichment

Knowledge hosting and deployment

Retrieving information with a knowledge graph and an LLM

Graph-based indexing

Graph-guided retrieval

GraphRAG applications

Understanding graph reasoning

Knowledge graph embeddings

Graph neural networks

LLMs reasoning on knowledge graphs

Ongoing challenges in knowledge graphs and GraphRAG

Summary

Further reading

8

Reinforcement Learning and AI Agents

Technical requirements

Introduction to reinforcement learning

The multi-armed bandit problem

Markov decision processes

Deep reinforcement learning

Model-free versus model-based approaches

On-policy versus off-policy methods

Exploring deep RL in detail

Challenges and future direction for deep RL

Learning how to play a video game with reinforcement learning

LLM interactions with RL models

RL-enhanced LLMs

LLM-enhanced RL

Key takeaways

Summary

Further reading

Part 3: Creating Sophisticated AI to Solve Complex Scenarios

9

Creating Single- and Multi-Agent Systems

Technical requirements

Introduction to autonomous agents

Toolformer

HuggingGPT

ChemCrow

SwiftDossier

ChemAgent

Multi-agent for law

Multi-agent for healthcare applications

Working with HuggingGPT

Using HuggingGPT locally

Using HuggingGPT on the web

Multi-agent system

SaaS, MaaS, DaaS, and RaaS

Software as a Service (SaaS)

Model as a Service (MaaS)

Data as a Service (DaaS)

Results as a Service (RaaS)

A comparison of the different paradigms

Summary

Further reading

10

Building an AI Agent Application

Technical requirements

Introduction to Streamlit

Starting with Streamlit

Caching the results

Developing our frontend with Streamlit

Adding the text elements

Inserting images in a Streamlit app

Creating a dynamic app

Creating an application with Streamlit and AI agents

Machine learning operations and LLM operations

Model development

Model training

Model testing

Inference optimization

Handling errors in production

Security considerations for production

Asynchronous programming

asyncio

Asynchronous programming and ML

Docker

Kubernetes

Docker with ML

Summary

Further reading

11

The Future Ahead

AI agents in healthcare

Biomedical AI agents

AI agents in other sectors

Physical agents

LLM agents for gaming

Web agents

Challenges and open questions

Challenges in human-agent communication

No clear superiority of multi-agents

Limits of reasoning

Creativity in LLM

Mechanistic interpretability

The road to artificial general intelligence

Ethical questions

Summary

Further reading

Index

Other Books You May Enjoy

Part 1: The AI Agent Engine: From Text to Large Language Models

This part lays the foundation for understanding how modern AI agents process and generate language. It begins by exploring how raw text can be represented in numerical form suitable for deep learning models, introducing techniques such as word embeddings and basic neural architectures. The focus then shifts to the Transformer model and explains how attention mechanisms revolutionized natural language processing. Finally, it examines how large language models (LLMs) are built by scaling transformers, discussing training strategies, instruction tuning, fine-tuning, and the evolution toward models capable of general-purpose reasoning. Together, these chapters provide the technical and conceptual groundwork for building intelligent AI agents.

This part has the following chapters:

Chapter 1, Analyzing Text Data with Deep LearningChapter 2, The Transformer: The Model Behind the Modern AI RevolutionChapter 3, Exploring LLMs as a Powerful AI Engine