Skip to main content

Ongoing Notes on the Next.js AI Chatbot Repo and other Nextjs AI Features

Repo

The repo is Next.js AI Chatbot

Redis Database and Code

The data for the messages is stored in a Redis database on Vercel, which is just Upstash. The file for the storage and retrieval is here: https://github.com/vercel/ai-chatbot/blob/main/app/actions.ts

From what I can tell there are two types of datastores here: Hashes and Sorted Sets. The Sorted Set stores the Chat lists for each user, with a key as in the code. The Hashes store the actual chats (the key/values are the chat message)

A Hash in Redis is: "Hashes are used to store collections of key/value pairs. Contrast a hash with a simple string data type where there is one value corresponding to one key. A hash has one key, but then within that structure are more fields and values." (see Redis PDF - page 36)

A Sorted Set in Redis is: "Sorted sets are used to store data that needs to be ranked, such as a leaderboard. Like a hash, a single key stores several members. The score for each of the members is a number." See: https://redis.com/glossary/sorted-set-time-series/ (as this applies to this repo)