I’m trying to understand how “Chat history” works in Google Gemini models.
With OpenAI’s ChatGPT, their API doesn’t store conversation history. We have to manage that ourselves, but we have control over where the history goes.
However, Gemini seems to have built-in chat history that automatically starts multi-turn conversations. I have a few questions about it:
-
How long does the conversation history persist? What happens to it if the model crashes or the program ends?(it seems everything just gone, but where… ? )
-
Where does the chat history go? Does Google store it, and if so, how is it cached?
-
I’m planning to implement this using Vertex Ai Gemini API + Google Cloud Functions (which are stateless). How can I maintain conversations across multiple user IDs and chat sessions via multiple call into a single google cloud function ?
Any help would be greatly appreciated !
Chat history is with the Gemini API exactly as stateless as with OpenAI. The ChatSession.history
property stores a chronological record of the conversation between the user and the Gemini model in-memory and automatically prepends the whole history on each subsequent chat turn. Nothing magic about it. Since it’s in-memory, if the process crashes, it is gone.
To maintain chat history for longer, it is up to the client to store the history
object in a database (relational or object database).
Hope that helps!
2 Likes
I think OP has mixed two questions into one. First being confusion with the ChatSession he/she must have come across in the SDK docs, which they probably think it’s somewhat going off their device and Google doing the storing of the history.
Second is using one google account to have multiple users interact with their vertex ai model. This should be straight-forward if he/she is able to achieve the same with Gemini API. I don’t see why second scenario should present any challenges because currently there’s no way to have conversation history stored (haven’t checked availability of Vertex Ai context caching).
1 Like
Hi everyone , been developing with the Gemini API , Just wanted to know if there was a way to save the history to some file or some online store. What is the best way to achive this. I have been think of link the history to a GoogleDrive Store. ?? any comments would be wonderful.
Firebase (Gemini API Firebase 擴充功能 | Google for Developers) is a popular choice, especially if you are working on the Vertex platform. Any object database will be sufficient for history, Wikipedia (NoSQL - Wikipedia) has a decently non-biased list of products (not biased by commercial interests, I mean).
If you want to follow general popularity trends when picking a product, you might get an idea from these trend charts DB-Engines Ranking - popularity ranking of object oriented DBMS
Relational databases can be used too, and are just fine, especially if you are more familiar with traditional RDBMs.
Hope that helps.
2 Likes
Thanks all, I was a bit confused about the in-memory aspect of the chat session, but now I understand it.
I’ll stick to my original workflow, somewhere like this:
User↔ Call to My Chatbot ↔ Gemini ↔ Firestore .