Method AddDataSource
AddDataSource(DataSource)
Registers a new DataSource with this engine for retrieval operations.
public void AddDataSource(DataSource dataSource)
Parameters
dataSourceDataSourceThe DataSource to register. Must not be
nullor 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
dataSourceisnull.- ArgumentException
Thrown if
dataSourceis 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
dataSourceIdentifierstringThe unique identifier of the DataSource to load from the vector store.
cancellationTokenCancellationTokenA 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
dataSourceIdentifierisnull, 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.