Tales from the jar side: Java and AI book, Context caching, The greatest organ piece ever, and the usual silly tweets and toots
Solar energy is just nuclear energy from a safe distance. Think about it.
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of June 16 - 23, 2024. This week I taught week two of my Spring in 3 Weeks course on the O’Reilly Learning Platform.
Regular readers of, listeners to, and video viewers of this newsletter are affectionately known as jarheads, and are far more intelligent, sophisticated, and attractive than the average newsletter reader or listener or viewer. If you wish to become a jarhead, please subscribe using this button:
As a reminder, when this message is truncated in email, click on the title to open it in a browser tab formatted properly for both the web and mobile.
First Tech Review for AAtoJ
My upcoming book (working title: Adding AI to Java) went out for its first technical review this week. That means five of the nine chapters were at least ready for that much. Currently the chapter titles are:
Getting Started with AI and Modern Java
I have some basic examples and then review the relevant features added to Java between Java 8 and Java 21.
This chapter uses the Java HTTP client API and Google’s Gson for JSON parsing and generation.
In this chapter I switch to Spring and use its
RestClient
and HTTP exchange interfaces.Install and Use AI Models Locally
That’s the Ollama section, with lots of open source (or at least open weights) models, like llama3, gemma, phi, and more.
Leverage Multi-Modal Vision Models
I use several vision models, meaning you upload an image and the model identifies its features and describes what it finds. In this chapter I also talk about data-oriented programming in Java using records, sealed interfaces, and pattern matching for switch.
The rest of the planned chapters are:
Generating Images
I use DALL-E 3 and Stable Diffusion here. Midjourney is notable for not having a programmatic API at all, but there is a third-party client that can access it if you want. I’m considering including that as an example of how to work through another service like that, especially when it requires polling.
Working with Audio
That covers generating mp3 files from text, as well as both transcription and translation. This chapter is basically done, pending some final revisions.
Java Frameworks for AI Models
Both LangChain4j and Spring AI are awesome, but neither one has reached the version 1.0 release yet, so I’m delaying this chapter as long as possible.
Adding Your Own Data
That’s the chapter on Retrieval Augmented Generation (RAG), but I also hope to talk about context caching (see below) and maybe fine tuning as well. All of those are in principle doable through the REST API (which is how I access them with Java), but honestly it’s probably not worth the effort when a good framework is available. I know both LangChain4j and Spring AI have excellent support for RAG, but I’m not sure about context caching or fine tuning yet.
I hope to complete the book this summer, with an early Fall release. I’d really like it to be a beta release by UberConf in mid-July, but that might be pushing things. We’ll see.
Caching the Context Window
Gemini now supports a whopping 2 million tokens (!) in the context window, which is basically how much of each conversation it can remember. The more data you add to the context window, the more the model understands and the better its accuracy, but that also makes requests slower and more expensive. So the ability to cache that data — so you don’t need to send it on each request — will become increasingly important as the windows grow in size. At the moment, context caching is part of Gemini’s Python API and their Node API only. The REST API has parts of it, but the documentation is, shall we say, very thin.
I spent a couple of days trying to get it to work (I was hoping to make a video on that this week), but never quite succeeded. I may just have to wait until it’s officially supported.
The Greatest Organ Work Ever Written
Yeah, that’s a bold statement, and yeah, I’m not remotely qualified to make it. Still, I have been listening to organ music off and on for decades, and I have an opinion on this. More to the point, I have a favorite that I rediscover every few years.
It’s by Johann Sebastien Bach, because of course it is. His most famous work, and probably the most famous organ piece of all time, is no doubt the Toccata and Fugue in D-minor, BWV 565, and sure, that’s great. For a certain generation of us, that will always be associated with the original Rollerball movie (the original, with James Caan in his best role after The Godfather) which is okay, but a cult classic. Everybody remembers the first few notes, but if you listen to the whole thing it kind of drags in the middle. The fame comes from that opening few bars, and as amazing as they are, my favorite piece is way better.
Speaking of classical pieces that owe at least some of their fame to movie tie-ins, there’s always this one:
Yup, Also Sprach Zarathustra, used in the movie 2001: A Space Odyssey.
But imagine this: it’s 1709, somewhere in Germany, and JS Bach walks into a gothic cathedral in the growing dusk, lit only by candles. He sits down at the organ, with the staff nervously awaiting his judgement. He pulls out all the stops (both figuratively and literally) and launches into this:
OMG. That’s Bach’s Passacaglia and Fugue in C minor, BWV 582. It starts with a haunting theme played on the lowest notes, and grows and grows and grows. About two-thirds of the way through it shifts to a fugue, but the original theme comes right back and he wrings more and more variations out of it. The whole piece builds to a crescendo, followed by one exquisite moment of silence, and then a wonderful finale. I can’t decide whether the onlookers, hearing it for the first time, burst into applause, or tears, or both.
This was, and is, the most metal organ piece of all time. What I wouldn’t give to be able to play it like that even once. (What I wouldn’t give other than the decades of training and practice it no doubt takes to play like that, but you get the idea.)
I just listened to three different versions again in order to share one for you, but don’t hesitate to search for yourself. There are so many great interpretations, and honestly I could probably listen to them all.
The first time I heard it was my freshman year in college. One of the juniors, whose name if I recall correctly was Suk Lee, had this $700 turntable, and I asked him to play something that demonstrated why it was so much better than all the others. At the time, I had a cheap record player (I hesitate to dignify it with the phrase turntable) to go along with my 8-track tape player. My what, I hear you say? I would reply, “kids, ask your parents,” but I’ll be most of them have no idea what that is either. It was a different time.
I sat on the floor in his room while he pulled a record from its sleeve, aimed his static gun at it, and started it up.
That static gun was fun, btw. One day Suk was just walking around with it when he strolled into the next room, where our friend Ron was listening to music on his headphones and bopping up and down in his chair. Suk walked up to the stereo, and without thinking, pulled the trigger on the static gun. There was an audible pop and the music died as every chip in the stereo got fried at once. Suk said, “Oops! I’ll get you a new one,” and Ron took off his headphones, looked up at him, and said, “Yes, you will.” The rest of us, of course, are still laughing about it 40 years later.
Anyway, that was the first time I heard the most amazing organ piece ever written. I used to bug him to play it again day after day until he kicked me out. Every few years I run into that piece again, and for some reason I remembered it last week. I’ve probably listened to a dozen versions over the last couple of weeks. I never get tired of it.
Seriously, if you think classical music is boring, crank that up loud and settle in for a life-altering experience.
Tweets and Toots
Antie Em! Get Toto into the barn!
Let’s be clear on this: there’s a reason The Wizard of Oz is set in Kansas and not in Connecticut. We’re not supposed to get tornadoes here. I wonder why that’s happening? It’s almost like somebody changed the climate.
Yeah, that figures
That explains a lot, but somehow he still accomplishes more than any three people. I’m not sure the world is ready for two of those glorious mustaches, however.
The Say Hey Kid
Here’s a link to that article.
Willie Mays passed away this week, and, to be honest, I was surprised to hear he was still alive at all. I never saw him play, because I was pretty young when he retired and we weren’t a baseball family. He was, however, the subject of the first baseball biography I ever read, with the title above (The Say, Hey Kid).
He could have played for the Red Sox, too. They tried him out, but at the time the ownership was still so staggeringly racist they couldn’t see the talent in Willie Mays. Seriously. There’s a reason they were bad for decades, and it has nothing to do with trading Babe Ruth to the Yankees.
Mays was wonderful and everybody (or at least almost everybody) loved him.
Just a quick reminder
You tell them, Lisa.
World’s Greatest, Again
I can’t believe that didn’t occur to me.
Unread, or not yet sent?
Less spam that way, I hope, but there may be other issues.
Theater kids beware
Blood! Blood!
Speaking of vampires
Good argument.
And finally,
Or the day after that
As someone who used to think his middle name was off-by-one error, I sympathize.
Have a great week, everybody!
Last week:
Week 2 of Spring in 3 Weeks, on the O’Reilly Learning Platform
This week:
Week 3 of Spring in 3 Weeks, on the O’Reilly Learning Platform
No, I get the lifetime off-by-one mistake prize! This was a great issue. Thanks.