Table of Contents

Method SaveInformation

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

SaveInformation(string, string, string, MetadataCollection, CancellationToken)

Saves text information into a designated memory data source using semantic memory type.

public DataSource SaveInformation(string dataSourceIdentifier, string text, string sectionIdentifier, MetadataCollection additionalMetadata = null, CancellationToken cancellationToken = default)

Parameters

dataSourceIdentifier string

The unique identifier of the data source where the information will be stored. If the data source does not exist, it is created automatically.

text string

The text content to store.

sectionIdentifier string

A unique identifier for this piece of information within the data source.

additionalMetadata MetadataCollection

Optional metadata to associate with the stored information.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

DataSource

The DataSource containing the stored information.

Examples

Example: Storing general knowledge

using LMKit.Agents;
using LMKit.Model;

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

// Store company information
memory.SaveInformation(
    dataSourceIdentifier: "company_info",
    text: "Our company was founded in 2020 and specializes in AI solutions.",
    sectionIdentifier: "company_overview");

memory.SaveInformation(
    dataSourceIdentifier: "company_info",
    text: "The headquarters is located in San Francisco, California.",
    sectionIdentifier: "location");

Console.WriteLine($"Stored {memory.DataSources.Count} data source(s).");

Remarks

This method uses Semantic by default, which is appropriate for general knowledge and facts. For other memory types, use the overload that accepts a MemoryType parameter.

Exceptions

ArgumentException

Thrown when dataSourceIdentifier, text, or sectionIdentifier is null or empty.

SaveInformation(string, string, string, MemoryType, MetadataCollection, CancellationToken)

Saves text information into a designated memory data source with a specified memory type.

public DataSource SaveInformation(string dataSourceIdentifier, string text, string sectionIdentifier, MemoryType memoryType, MetadataCollection additionalMetadata = null, CancellationToken cancellationToken = default)

Parameters

dataSourceIdentifier string

The unique identifier of the data source where the information will be stored.

text string

The text content to store.

sectionIdentifier string

A unique identifier for this piece of information within the data source.

memoryType MemoryType

The type of memory to use, which affects how the information is categorized and potentially how it is retrieved.

additionalMetadata MetadataCollection

Optional metadata to associate with the stored information.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

DataSource

The DataSource containing the stored information.

Examples

Example: Storing different types of memory

using LMKit.Agents;
using LMKit.Model;

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

// Semantic: General knowledge
memory.SaveInformation(
    "knowledge_base",
    "C# is a statically typed programming language developed by Microsoft.",
    "csharp_overview",
    MemoryType.Semantic);

// Episodic: Personal experiences/events
memory.SaveInformation(
    "user_interactions",
    "On March 15, the user asked about async programming patterns.",
    "interaction_001",
    MemoryType.Episodic);

// Procedural: How-to knowledge
memory.SaveInformation(
    "procedures",
    "To deploy: 1) Build solution, 2) Run tests, 3) Push to staging.",
    "deployment_steps",
    MemoryType.Procedural);

Remarks

A data source can only have one memory type. If you attempt to save information with a different memory type than what was originally used for that data source, an exception is thrown.

Exceptions

ArgumentException

Thrown when dataSourceIdentifier, text, or sectionIdentifier is null or empty, or when the provided memory type conflicts with the existing memory type of the data source.