Understanding Langchain4j by @agoncalv
Here we go again, the @agoncal 2024, which imminent release have been disclosed by the author himself, a couple of weeks ago, on this same site, is now available on Amazon. “Yet another AI book”, you might be tempted to think. But no, make no mistake, this one is different as the author manages to demystify, in less than 200 pages (not to mention the appendixes), the essential of what everything is about in GenAI, ML, DL, LLM, FM and I could go on best.
This isn’t an AI book as you might have seen at Manning or Packt, in fact it isn’t even an AI book but, as its title suggests to the insightful readers that you are, a book or, even better, a fascicle, dedicated to you, Java developers, demonstrating how to integrate GenAI in your preferred ecosystem, on the behalf of the Langchain4j library.
The book is structured in 5 parts. The first one, titled First Steps, addresses the GenAI’s most fundamentals concepts and terms. It goes from the AI basics to RAG (Retrival Augmented Generation) passing through models, prompts, hallucinations, tokens, embeddings and vector databases, everything sprinkled by Langchain4j code examples.
The second part, named Models, is a panorama of the different LLMs supported by Langchain4j, classified in accordance to their main destination, be them language, chat, moderation or image models. The notion of model provider is introduced as well, together with their full list supported by Langchain4j. The most important classes and interfaces are presented here in the form of class diagrams, giving this way a very concise, compact and, in the same time, exhaustive view of the Langchain4j REST and Java client API (Application Program Interface).
In the third part, Retrieval Augmented Generation, the author takes us in a journey to RAG and its subtleties like parsing, loading, transforming and splitting documents. An important section is dedicated to embedding models, embedding stores, and their counterpart in Langchain4j. The list of all the supported embedding stores is provided, together with their associated specialized APIs and illustrated with examples demonstrating how to use the Java client API in order to access these vector databases.
The fourth part, Simplifying Generative AI, moves us away from the lower-level components, explained in the previous chapters, to more abstract and complex interactions into higher level AiServices. Here is where we’re introduced to advanced techniques like facilitating the AI models access, streamlining message handling or using extension tools able to improve the models capabilities.
Last but not least, the fifth part, Conclusions, is the practical application of all the terms, notions, concepts and principles learned throughout the book. The author remains attached to his sample application, Vintage Store, that he’s using since his very first book to illustrate the talk and, icing on the cake, even provides a full chatbot application. 60 pages of appendixes follow showing how to install the development environment, the local model providers and how to register with the remote ones.
In his foreword, Dmytro Liubarskyi, the Langchain4j creator, mentions Antonio’s exceptional capacity to resume things, as complicated as they might be, in a consistent and easy to understand manner. And as a matter of fact, I was once again impressed of how Antonio handles highly theoretical scientific concepts in a discourse of style the “AI explained to my son”.
To be honest, I was expecting myself to find a text that falls out of my hands, full of complicated and tiresome explanations on NLP, encoding - decoding and other “attention is all you need” stuff. I was so pleased to find an interesting book which reads itself in a couple of hours.
In conclusion, I couldn’t recommend more this book which should stay on any Java developer bookshelf.
And in order to avoid being too ecstatic and lyrical, I have to add a note of caution concerning the book presentation. The author has made the choice of the self-publishing, probably consecutive to some setbacks with Apress at the occasion of his previous book. While this is more than understandable, it impacts negatively on the cover presentation, the paper quality as well as the page layout. Publishing books is a profession in its own right. :-)