Constructor PdfChat
PdfChat(LM, LM, int)
Initializes a new instance using separate chat and embedding models.
public PdfChat(LM chatModel, LM embeddingModel, int contextSize = -1)
Parameters
chatModelLMThe language model for generating responses.
embeddingModelLMThe model for computing text embeddings used during document retrieval.
contextSizeintToken context size override, or
-1to let the runtime select an optimal size based on hardware and model configuration.
Examples
LM chatModel = LM.LoadFromModelID("gemma4:e4b");
LM embeddingModel = LM.LoadFromModelID("embeddinggemma-300m");
using var chat = new PdfChat(chatModel, embeddingModel);
await chat.LoadDocumentAsync("report.pdf");
var result = await chat.SubmitAsync("What are the key findings?");
Console.WriteLine(result.Response.Completion);
Exceptions
- ArgumentNullException
Thrown if
chatModelorembeddingModelisnull.
PdfChat(LM, LM, IVectorStore, int)
Initializes a new instance using separate chat and embedding models with an optional vector store for caching.
public PdfChat(LM chatModel, LM embeddingModel, IVectorStore vectorStore, int contextSize = -1)
Parameters
chatModelLMThe language model for generating responses.
embeddingModelLMThe model for computing text embeddings used during document retrieval.
vectorStoreIVectorStoreOptional vector store for caching document embeddings, or
nullto disable caching. When provided, processed documents are cached and reused on subsequent loads.contextSizeintToken context size override, or
-1to let the runtime select an optimal size based on hardware and model configuration.
Examples
LM chatModel = LM.LoadFromModelID("gemma4:e4b");
LM embeddingModel = LM.LoadFromModelID("embeddinggemma-300m");
IVectorStore store = new FileSystemVectorStore("pdf_cache");
// Documents will be cached in the vector store for faster subsequent loads
using var chat = new PdfChat(chatModel, embeddingModel, store);
Exceptions
- ArgumentNullException
Thrown if
chatModelorembeddingModelisnull.
PdfChat(LM, LM, byte[])
Restores a previous PdfChat session from serialized bytes.
public PdfChat(LM chatModel, LM embeddingModel, byte[] sessionData)
Parameters
chatModelLMThe language model for generating responses (must match the model used when saving).
embeddingModelLMThe model for computing text embeddings used during document retrieval.
sessionDatabyte[]Bytes produced by SaveSession().
Examples
byte[] sessionData = File.ReadAllBytes("session.bin");
using var chat = new PdfChat(chatModel, embeddingModel, sessionData);
// Continue the conversation where it left off
var result = await chat.SubmitAsync("Can you elaborate on that?");
Console.WriteLine(result.Response.Completion);
Exceptions
- ArgumentNullException
Thrown if
chatModelorembeddingModelisnull.- InvalidDataException
Thrown if
sessionDatais not a valid PdfChat session.
PdfChat(LM, LM, IVectorStore, byte[])
Restores a previous PdfChat session from serialized bytes, with an optional vector store.
public PdfChat(LM chatModel, LM embeddingModel, IVectorStore vectorStore, byte[] sessionData)
Parameters
chatModelLMThe language model for generating responses (must match the model used when saving).
embeddingModelLMThe model for computing text embeddings used during document retrieval.
vectorStoreIVectorStoreOptional vector store for caching document embeddings, or
nullto disable caching.sessionDatabyte[]Bytes produced by SaveSession().
Examples
byte[] sessionData = File.ReadAllBytes("session.bin");
IVectorStore store = new FileSystemVectorStore("pdf_cache");
using var chat = new PdfChat(chatModel, embeddingModel, store, sessionData);
// Continue the conversation
var result = await chat.SubmitAsync("What else can you tell me?");
Exceptions
- ArgumentNullException
Thrown if
chatModelorembeddingModelisnull.- InvalidDataException
Thrown if
sessionDatais not a valid PdfChat session.
PdfChat(LM, LM, string)
Restores a previous PdfChat session from a file on disk.
public PdfChat(LM chatModel, LM embeddingModel, string sessionFile)
Parameters
chatModelLMThe language model for generating responses (must match the model used when saving).
embeddingModelLMThe model for computing text embeddings used during document retrieval.
sessionFilestringPath to a session file created by SaveSession(string).
Examples
using var chat = new PdfChat(chatModel, embeddingModel, "session.bin");
// Continue the conversation
var result = await chat.SubmitAsync("Can you summarize the document?");
Console.WriteLine(result.Response.Completion);
Exceptions
- ArgumentNullException
Thrown if
chatModelorembeddingModelisnull.- InvalidDataException
Thrown if the file is not a valid PdfChat session.
PdfChat(LM, LM, IVectorStore, string)
Restores a previous PdfChat session from a file on disk, with an optional vector store.
public PdfChat(LM chatModel, LM embeddingModel, IVectorStore vectorStore, string sessionFile)
Parameters
chatModelLMThe language model for generating responses (must match the model used when saving).
embeddingModelLMThe model for computing text embeddings used during document retrieval.
vectorStoreIVectorStoreOptional vector store for caching document embeddings, or
nullto disable caching.sessionFilestringPath to a session file created by SaveSession(string).
Examples
IVectorStore store = new FileSystemVectorStore("pdf_cache");
using var chat = new PdfChat(chatModel, embeddingModel, store, "session.bin");
var result = await chat.SubmitAsync("What are the key metrics?");
Exceptions
- ArgumentNullException
Thrown if
chatModelorembeddingModelisnull.- InvalidDataException
Thrown if the file is not a valid PdfChat session.