Method Deserialize
Deserialize(string, LM)
Deserializes memory from a file at the specified path.
public static AgentMemory Deserialize(string agentMemoryPath, LM embeddingModel)
Parameters
agentMemoryPathstringThe file path containing the serialized memory data.
embeddingModelLMThe 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
agentMemoryPathis 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
databyte[]The binary data representing serialized memory.
embeddingModelLMThe embedding model to use with the deserialized memory.
Returns
- AgentMemory
A new AgentMemory instance containing the loaded data.
Exceptions
- ArgumentNullException
Thrown when
dataorembeddingModelisnull.- 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
streamStreamA readable stream containing serialized memory data.
embeddingModelLMThe embedding model to use with the deserialized memory.
Returns
- AgentMemory
A new AgentMemory instance containing the loaded data.
Exceptions
- ArgumentNullException
Thrown when
streamorembeddingModelisnull.- ArgumentException
Thrown when
streamis not readable.- InvalidDataException
Thrown when the stream does not contain valid serialized memory data or the version is unsupported.