Table of Contents

Method Deserialize

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

Deserialize(string, LM)

Deserializes memory from a file at the specified path.

public static AgentMemory Deserialize(string agentMemoryPath, LM embeddingModel)

Parameters

agentMemoryPath string

The file path containing the serialized memory data.

embeddingModel LM

The embedding model to use with the deserialized memory.

Returns

AgentMemory

A new AgentMemory instance containing the loaded data.

Examples

Example: Loading memory from a file

using LMKit.Agents;
using LMKit.Model;

using var embeddingModel = new LM("path/to/embedding-model.gguf");

string memoryPath = "agent_memory.bin";

if (File.Exists(memoryPath))
{
    var memory = AgentMemory.Deserialize(memoryPath, embeddingModel);
    Console.WriteLine($"Loaded memory with {memory.DataSources.Count} data sources.");
}
else
{
    Console.WriteLine("No saved memory found.");
}

Remarks

The embedding model provided should be the same model (or a compatible one) that was used when the memory was originally created. Using a different model may result in degraded retrieval quality.

Exceptions

ArgumentNullException

Thrown when agentMemoryPath is null or empty.

FileNotFoundException

Thrown when the specified file does not exist.

InvalidDataException

Thrown when the file does not contain valid serialized memory data or the version is unsupported.

Deserialize(byte[], LM)

Deserializes memory from a byte array.

public static AgentMemory Deserialize(byte[] data, LM embeddingModel)

Parameters

data byte[]

The binary data representing serialized memory.

embeddingModel LM

The embedding model to use with the deserialized memory.

Returns

AgentMemory

A new AgentMemory instance containing the loaded data.

Exceptions

ArgumentNullException

Thrown when data or embeddingModel is null.

InvalidDataException

Thrown when the data does not contain valid serialized memory.

Deserialize(Stream, LM)

Deserializes memory from a stream.

public static AgentMemory Deserialize(Stream stream, LM embeddingModel)

Parameters

stream Stream

A readable stream containing serialized memory data.

embeddingModel LM

The embedding model to use with the deserialized memory.

Returns

AgentMemory

A new AgentMemory instance containing the loaded data.

Exceptions

ArgumentNullException

Thrown when stream or embeddingModel is null.

ArgumentException

Thrown when stream is not readable.

InvalidDataException

Thrown when the stream does not contain valid serialized memory data or the version is unsupported.