Table of Contents

Method AddDataSourceAsync

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

AddDataSourceAsync(string, CancellationToken)

Asynchronously loads and registers an existing DataSource from the configured vector store.

public Task AddDataSourceAsync(string dataSourceIdentifier, CancellationToken cancellationToken = default)

Parameters

dataSourceIdentifier string

The unique identifier of the DataSource to load from the vector store.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task

A task representing the asynchronous operation.

Examples

// Create a RagEngine with a vector store
LM embeddingModel = LM.LoadFromModelID("embeddinggemma-300m");
IVectorStore vectorStore = new QdrantVectorStore("http://localhost:6333");
RagEngine ragEngine = new RagEngine(embeddingModel, vectorStore);

// Load a previously persisted data source
await ragEngine.AddDataSourceAsync("myPersistedDataSource");

Console.WriteLine("DataSource loaded and registered successfully.");

Remarks

This method retrieves a previously persisted DataSource from the external vector store and registers it with the engine for retrieval operations. The data source must already exist in the vector store; use ImportTextAsync(string, string, string, CancellationToken) or similar import methods to create new data sources.

A vector store must be configured when constructing the RagEngine for this method to work.

Exceptions

ArgumentNullException

Thrown if dataSourceIdentifier is null, empty, or whitespace.

InvalidOperationException

Thrown if no vector store was configured when constructing the RagEngine.

KeyNotFoundException

Thrown if no DataSource with the specified identifier exists in the vector store.

ArgumentException

Thrown if a DataSource with the same identifier is already registered with this engine.

OperationCanceledException

Thrown if the operation is canceled.