Method SaveSession
SaveSession()
Saves the current session state (conversation, documents, and configuration) to a byte array.
public byte[] SaveSession()
Returns
- byte[]
A byte array containing the serialized session data.
Examples
using var chat = new PdfChat(chatModel, embeddingModel);
await chat.LoadDocumentAsync("report.pdf");
await chat.SubmitAsync("What are the key findings?");
// Save session for later
byte[] sessionData = chat.SaveSession();
File.WriteAllBytes("session.bin", sessionData);
Remarks
The saved state includes the full conversation history, KV cache, all loaded document content, passage retrieval indices, and configuration settings. Identical document content is stored only once regardless of how many times the same file was loaded.
Use with PdfChat(LM, LM, byte[]) or PdfChat(LM, LM, IVectorStore, byte[]) to restore the session later.
Exceptions
- InvalidOperationException
Thrown if the conversation history is empty (no questions have been submitted).
- ObjectDisposedException
Thrown if this instance has been disposed.
SaveSession(string)
Saves the current session state to a file on disk.
public void SaveSession(string path)
Parameters
pathstringThe file path to write the session data to.
Examples
using var chat = new PdfChat(chatModel, embeddingModel);
await chat.LoadDocumentAsync("report.pdf");
await chat.SubmitAsync("What are the key findings?");
// Save to file
chat.SaveSession("session.bin");
Remarks
The saved state includes the full conversation history, KV cache, all loaded document content, passage retrieval indices, and configuration settings. Identical document content is stored only once regardless of how many times the same file was loaded.
Use with PdfChat(LM, LM, string) or PdfChat(LM, LM, IVectorStore, string) to restore the session later.
Exceptions
- InvalidOperationException
Thrown if the conversation history is empty (no questions have been submitted).
- ObjectDisposedException
Thrown if this instance has been disposed.