Table of Contents

Method SaveInformationAsync

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

SaveInformationAsync(string, string, string, MetadataCollection, CancellationToken)

Asynchronously saves text information into a designated memory data source.

public Task<DataSource> SaveInformationAsync(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.

text string

The text content to save.

sectionIdentifier string

A unique identifier for this particular piece of information.

additionalMetadata MetadataCollection

Optional metadata to associate with the information.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<DataSource>

A task representing the asynchronous operation. The task result is the DataSource containing the stored data.

Examples

Example: Asynchronously building a knowledge base

using LMKit.Agents;
using LMKit.Model;

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

// Load knowledge from multiple sources concurrently
var tasks = new[]
{
    memory.SaveInformationAsync("faq", "How do I reset my password? Go to Settings > Security.", "faq_001"),
    memory.SaveInformationAsync("faq", "What payment methods are accepted? Visa, MasterCard, PayPal.", "faq_002"),
    memory.SaveInformationAsync("faq", "How long is the free trial? 14 days with full features.", "faq_003")
};

await Task.WhenAll(tasks);
Console.WriteLine($"Loaded {tasks.Length} FAQ entries.");

Remarks

Uses Semantic by default. The asynchronous version is preferred for UI applications to avoid blocking the main thread during embedding generation.

Exceptions

ArgumentException

Thrown when any of the required string parameters is null or empty.

SaveInformationAsync(string, string, string, MemoryType, MetadataCollection, CancellationToken)

Asynchronously saves text information with a specified memory type.

public Task<DataSource> SaveInformationAsync(string dataSourceIdentifier, string text, string sectionIdentifier, MemoryType memoryType, MetadataCollection additionalMetadata = null, CancellationToken cancellationToken = default)

Parameters

dataSourceIdentifier string

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

text string

The text content to be saved.

sectionIdentifier string

A unique identifier for this piece of information.

memoryType MemoryType

The type of memory classification for this information.

additionalMetadata MetadataCollection

Optional metadata to associate with the information.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<DataSource>

A task representing the asynchronous operation. The task result is the DataSource containing the stored data.

Exceptions

ArgumentException

Thrown when required parameters are null or empty, or when the memory type conflicts with an existing data source's type.