Table of Contents

Constructor PdfChat

Namespace
LMKit.Retrieval
Assembly
LM-Kit.NET.dll

PdfChat(LM, LM, int)

Initializes a new instance using separate chat and embedding models.

public PdfChat(LM chatModel, LM embeddingModel, int contextSize = -1)

Parameters

chatModel LM

The language model for generating responses.

embeddingModel LM

The model for computing text embeddings used during document retrieval.

contextSize int

Token context size override, or -1 to 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 chatModel or embeddingModel is null.

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

chatModel LM

The language model for generating responses.

embeddingModel LM

The model for computing text embeddings used during document retrieval.

vectorStore IVectorStore

Optional vector store for caching document embeddings, or null to disable caching. When provided, processed documents are cached and reused on subsequent loads.

contextSize int

Token context size override, or -1 to 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 chatModel or embeddingModel is null.

PdfChat(LM, LM, byte[])

Restores a previous PdfChat session from serialized bytes.

public PdfChat(LM chatModel, LM embeddingModel, byte[] sessionData)

Parameters

chatModel LM

The language model for generating responses (must match the model used when saving).

embeddingModel LM

The model for computing text embeddings used during document retrieval.

sessionData byte[]

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 chatModel or embeddingModel is null.

InvalidDataException

Thrown if sessionData is 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

chatModel LM

The language model for generating responses (must match the model used when saving).

embeddingModel LM

The model for computing text embeddings used during document retrieval.

vectorStore IVectorStore

Optional vector store for caching document embeddings, or null to disable caching.

sessionData byte[]

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 chatModel or embeddingModel is null.

InvalidDataException

Thrown if sessionData is 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

chatModel LM

The language model for generating responses (must match the model used when saving).

embeddingModel LM

The model for computing text embeddings used during document retrieval.

sessionFile string

Path 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 chatModel or embeddingModel is null.

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

chatModel LM

The language model for generating responses (must match the model used when saving).

embeddingModel LM

The model for computing text embeddings used during document retrieval.

vectorStore IVectorStore

Optional vector store for caching document embeddings, or null to disable caching.

sessionFile string

Path 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 chatModel or embeddingModel is null.

InvalidDataException

Thrown if the file is not a valid PdfChat session.

Share