The condense chat engine has two main components
- The query engine/index
- The chat history
The index is easy enough to persist. You can also get the chat history by using
chat_engine.chat_history
. This returns a list of
ChatMessage
objects which are serializable.
Using these two objects, you can load/save and re-create the chat engine.
index.storage_context.persist(persist_dir="./storage")
chat_history = chat_engine.chat_history
chat_history_json_str = [x.json() for x in chat_history]
# write json str to folder?
# load
from llama_index.llms import ChatMessage
from llama_index import StorageContext, load_index_from_storage
index = load_index_from_storage(StorageContext.from_defaults(persist_dir="./storage"))
chat_history = [ChatMessage.parse_raw(x) for x in chat_history_json_str]
chat_engine = CondenseQuestionChatEngine.from_defaults(query_engine=query_engine, chat_history=chat_history)
Kind of tedious tbh. I can probably get a save/load funcationality out in the next few days π