This is a submission for the Redis AI Challenge: Beyond the Cache.
What I Built
Redis RPG ⚔️ is a multiplayer storytelling game where players can type anything 🤯 they want, and AI responds like an intelligent narrator in real-time. Instead of clicking preset options, players can type ⌨️ 'I try to negotiate with the alien' or 'I use my coffee cup as a megaphone 📢 ☕️' - and the AI decides what happens next based on creativity and logic. But unlike other AI story apps, in this game, there are irreversible consequences for your actions 🧨🙀.
But this is really about a broader paradigm 🌎 with three core components: First, AI preprocessing that constrains responses to relevant context 👮🏻♂️ - in this game, you can only use the equipment you have and interact with the current environment. Second, AI generates contextual responses to any natural language input 🧠. Third, semantic caching stores and reuses similar responses to improve speed ⚡️ and reduce costs 💰.
This same system could power customer service chatbots 🤖, educational platforms 📚 where students can ask questions in their own words, or sales teams/manufacturers communicating details about products and warranties 🚗. It can work anywhere you need AI to respond intelligently and topically to human input while maintaining consistency and efficiency 😎.
Demo
A couple of things you need to know before playing...
- I only put $10 on my Open AI account, so it might run out😭.
- The AI is controlling my code. I've tested it many times, and I've been very specific with the AI, but every now and then the AI decides to throw a wrench in the works🦾🔧.
- Its pretty fun 🙂.
https://rpg.jacobhenning.com/
https://youtu.be/LdaTUGWCo4E
https://github.com/jacobshenning/redis-ai-hackathon
How I Used Redis 8
I used Pub/Sub, Cache, Redis as my primary database💽, and I also setup a redis search engine🔎 (without RediSearch) and a semantic cache using vectors.
The overall impact Redis has on a website with live websockets, constant AI generated data, and a need to access data quickly is huge.
Pub/Sub
I used Pub/Sub to send events over to the WebSocket server 📢. My app is live, and the WebSockets are a huge part of how it works, so this was very important for my app. It made things much quicker 🚀.
Event Streaming
I couldn't figure out how to store my game logs because they came from all over the place (my event system is robust, each event generates text for the player, so it got crazy). And then I found this feature. I didn't even know Redis had this 😂. Its fast and worked perfectly.
Redis as Primary Database
Redis manages all of the game data 📊. Weapons🗡️, characters🤺, locations🏠, etc are all generated by AI and then saved in Redis. The only thing I don't save in Redis is my users table, and its because I want users to persist when the server is off, and I know I can make Redis data persist when the server is off, but I don't actually want the game data to persist when the server is off - So I'm not keeping users in MySQL because Redis can't persist when the server is off, I'm doing it because I want to lose my game data when the server is off. I didn't have a lot of time to build this so I needed to do it this way 😂
(ps I have setup Redis as the primary database for Laravel before and it works great. Super fast).
Semantic Caching
I built a class for saving and managing semantic caches💾. Unfortunately, I wasn't able to build it in such a way it would be used. This is because my app's content is hugely generated by AI 🤖. It creates a vast selection of content. So $5🪙 server will probably crash💥 before that cache gets hit. There is another way I might use it but it takes a while to explain, but is awesome and brilliant 🧠.
Redis Search Engine
I was going to setup a semantic search engine🕵🏼♂️ (sounded cool) but then I realized my content was a little to granular for semantic searching ⏳. So then I build a manual indexing tool that could fuzzy search strings. And then I ended up not using it... It probably doesn't count for the hackathon if you don't use it in your app, but I just want you to know I built it 💪.
About this paradigm (Bonus Section🤩)
You thought I was done huh?🤔
Go to Market Strategy
Every time I build something, I always have scalability in the back of my mind. The problem with Redis RPG⚔️ is that it uses a lot of AI bandwidth, and to scale would require a heft investment 💳. The solution to this is to reuse a portion of our AI generated content. If users get 50% AI generated content, and 50% recycled content ⚖️, its still a fairly dynamic experience. But here is the problem with that. My app isn't just generated a "Character" and a "Location" - Locations and characters are unique to the world they're created in 🤯. My AI prompting and seed 🌱 combinations generate characters with traits that they would acquire from that land. My AI tools won't generate a location on the beach if the game is occurring in the mountains. So I can't get just pull a previously generated location out of my database and expect it to work with the current game's region. But guess what I could do?🤔 Seriously, try to guess🧠, scroll down and comment your guess and then come back.
I can implement Semantic Caching using vectors🤓. What this lets me do is pull previously generated content that matches the game appropriately. So if we're a region of snowy☃️ 🌲 forests, we won't pull a location called "🏝️Oasis" - no we'll pull a "Snow Lodge🏂" out of that database and hit the steam🧖🏻♂️ room. Then I can decide what threshold of new content I want to generate (so long as I have some old content to pull out). App too expensive? Only generate half the content.
Eventually, the semantic cache will fill up enough to start catching similar prompts, and reusing them. When this happens, if you want, you could start replacing old caches with content created by an improved AI.
I'm not sure if this particular app will ever "go to market" in any serious sense but I have to think about it as I build. (ps, if you want me keep building this (or even want to help), say something in the comments).
Top comments (0)