Table of Contents

Method AddDataSource

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

AddDataSource(DataSource)

Registers a new DataSource with this engine for retrieval operations.

public void AddDataSource(DataSource dataSource)

Parameters

dataSource DataSource

The DataSource to register. Must not be null or already registered.

Examples

LM embeddingModel = LM.LoadFromModelID("embeddinggemma-300m");
RagEngine ragEngine = new RagEngine(embeddingModel);

DataSource dataSource = new DataSource("myUniqueData");
ragEngine.AddDataSource(dataSource);

Console.WriteLine("DataSource added successfully.");

Exceptions

ArgumentNullException

Thrown if dataSource is null.

ArgumentException

Thrown if dataSource is already registered with this engine.

InvalidModelException

Thrown if the DataSource model is incompatible with the engine's embedding model.

AddDataSource(string, CancellationToken)

Loads and registers an existing DataSource from the configured vector store.

public void AddDataSource(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.

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
ragEngine.AddDataSource("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 ImportText(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.