Method ImportAsync
ImportAsync(Attachment, string, string, CancellationToken)
Asynchronously imports content from a single Attachment into a DataSource, creating a new section.
public Task<DataSource> ImportAsync(Attachment attachment, string dataSourceIdentifier, string sectionIdentifier, CancellationToken cancellationToken = default)
Parameters
attachmentAttachmentThe attachment containing the content to import.
dataSourceIdentifierstringThe unique identifier for the target DataSource. If a matching data source exists, the content is added as a new section; otherwise, a new data source is created.
sectionIdentifierstringThe identifier for the new section created from the attachment's content.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the DataSource containing the imported content.
Exceptions
- ArgumentNullException
Thrown if
attachment,dataSourceIdentifier, orsectionIdentifierisnullor empty.
ImportAsync(Attachment, IChunking, string, string, CancellationToken)
Asynchronously imports content from a single Attachment into a DataSource, creating a new section with a custom chunking strategy.
public Task<DataSource> ImportAsync(Attachment attachment, IChunking chunker, string dataSourceIdentifier, string sectionIdentifier, CancellationToken cancellationToken = default)
Parameters
attachmentAttachmentThe attachment containing the content to import.
chunkerIChunkingThe chunking strategy for splitting the extracted text. If
null, DefaultIChunking is used.dataSourceIdentifierstringThe unique identifier for the target DataSource. If a matching data source exists, the content is added as a new section; otherwise, a new data source is created.
sectionIdentifierstringThe identifier for the new section created from the attachment's content.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the DataSource containing the imported content.
Exceptions
- ArgumentNullException
Thrown if
attachment,dataSourceIdentifier, orsectionIdentifierisnullor empty.
ImportAsync(Attachment, string, string, MetadataCollection, CancellationToken)
Asynchronously imports content from a single Attachment into a DataSource, creating a new section and attaching additional metadata.
public Task<DataSource> ImportAsync(Attachment attachment, string dataSourceIdentifier, string sectionIdentifier, MetadataCollection additionalMetadata, CancellationToken cancellationToken = default)
Parameters
attachmentAttachmentThe attachment containing the content to import.
dataSourceIdentifierstringThe unique identifier for the target DataSource. If a matching data source exists, the content is added as a new section; otherwise, a new data source is created.
sectionIdentifierstringThe identifier for the new section created from the attachment's content.
additionalMetadataMetadataCollectionMetadata to associate with the imported section.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the DataSource containing the imported content.
Exceptions
- ArgumentNullException
Thrown if
attachment,dataSourceIdentifier, orsectionIdentifierisnullor empty.
ImportAsync(Attachment, IChunking, string, string, MetadataCollection, CancellationToken)
Asynchronously imports content from a single Attachment into a DataSource, creating a new section with a custom chunking strategy and attaching additional metadata.
public Task<DataSource> ImportAsync(Attachment attachment, IChunking chunker, string dataSourceIdentifier, string sectionIdentifier, MetadataCollection additionalMetadata, CancellationToken cancellationToken = default)
Parameters
attachmentAttachmentThe attachment containing the content to import.
chunkerIChunkingThe chunking strategy for splitting the extracted text. If
null, DefaultIChunking is used.dataSourceIdentifierstringThe unique identifier for the target DataSource. If a matching data source exists, the content is added as a new section; otherwise, a new data source is created.
sectionIdentifierstringThe identifier for the new section created from the attachment's content.
additionalMetadataMetadataCollectionMetadata to associate with the imported section.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the DataSource containing the imported content.
Exceptions
- ArgumentNullException
Thrown if
attachment,dataSourceIdentifier, orsectionIdentifierisnullor empty.
ImportAsync(IList<Attachment>, string, IList<string>, IList<MetadataCollection>, CancellationToken)
Asynchronously imports content from multiple Attachment instances into a DataSource, creating a new section for each attachment.
public Task<DataSource> ImportAsync(IList<Attachment> attachments, string dataSourceIdentifier, IList<string> sectionIdentifiers, IList<MetadataCollection> metadataCollections = null, CancellationToken cancellationToken = default)
Parameters
attachmentsIList<Attachment>A list of attachments containing the content to import.
dataSourceIdentifierstringThe unique identifier for the target DataSource. If a matching data source exists, the content is added as new sections; otherwise, a new data source is created.
sectionIdentifiersIList<string>A list of unique identifiers for the sections corresponding to each attachment. The count must match the number of attachments.
metadataCollectionsIList<MetadataCollection>An optional list of metadata collections to associate with each imported section. If provided, the count must match the number of attachments.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the DataSource containing the imported content.
Exceptions
- ArgumentNullException
Thrown if
attachments,dataSourceIdentifier, orsectionIdentifiersisnullor empty.- ArgumentOutOfRangeException
Thrown if the count of
sectionIdentifiers(ormetadataCollections, if provided) does not match the number of attachments.
ImportAsync(IList<Attachment>, IChunking, string, IList<string>, IList<MetadataCollection>, CancellationToken)
Asynchronously imports content from multiple Attachment instances into a DataSource, creating a new section for each attachment with a custom chunking strategy.
public Task<DataSource> ImportAsync(IList<Attachment> attachments, IChunking chunker, string dataSourceIdentifier, IList<string> sectionIdentifiers, IList<MetadataCollection> metadataCollections = null, CancellationToken cancellationToken = default)
Parameters
attachmentsIList<Attachment>A list of attachments containing the content to import.
chunkerIChunkingThe chunking strategy for splitting the extracted text. If
null, DefaultIChunking is used.dataSourceIdentifierstringThe unique identifier for the target DataSource. If a matching data source exists, the content is added as new sections; otherwise, a new data source is created.
sectionIdentifiersIList<string>A list of unique identifiers for the sections corresponding to each attachment. The count must match the number of attachments.
metadataCollectionsIList<MetadataCollection>An optional list of metadata collections to associate with each imported section. If provided, the count must match the number of attachments.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the DataSource containing the imported content.
Exceptions
- ArgumentNullException
Thrown if
attachments,dataSourceIdentifier, orsectionIdentifiersisnullor empty.- ArgumentOutOfRangeException
Thrown if the count of
sectionIdentifiers(ormetadataCollections, if provided) does not match the number of attachments.
ImportAsync(ImageBuffer, string, string, CancellationToken)
Asynchronously imports a single image into a DataSource, creating a new section.
public Task<DataSource> ImportAsync(ImageBuffer image, string dataSourceIdentifier, string sectionIdentifier, CancellationToken cancellationToken = default)
Parameters
imageImageBufferThe image buffer to import.
dataSourceIdentifierstringThe unique identifier for the target DataSource. If the identifier exists, the image is added as a new section; otherwise, a new data source is created.
sectionIdentifierstringThe identifier for the new section.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the DataSource containing the imported image.
Remarks
This method requires a vision-enabled embedding model to be registered with the engine.
Exceptions
- ArgumentNullException
Thrown if
imageordataSourceIdentifierisnullor empty.- ArgumentException
Thrown if no vision-enabled embedding model is registered with the engine.
ImportAsync(ImageBuffer, string, string, MetadataCollection, CancellationToken)
Asynchronously imports a single image into a DataSource, creating a new section and attaching additional metadata.
public Task<DataSource> ImportAsync(ImageBuffer image, string dataSourceIdentifier, string sectionIdentifier, MetadataCollection additionalMetadata, CancellationToken cancellationToken = default)
Parameters
imageImageBufferThe image buffer to import.
dataSourceIdentifierstringThe unique identifier for the target DataSource. If the identifier exists, the image is added as a new section; otherwise, a new data source is created.
sectionIdentifierstringThe identifier for the new section.
additionalMetadataMetadataCollectionMetadata to associate with the imported section.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the DataSource containing the imported image.
Remarks
This method requires a vision-enabled embedding model to be registered with the engine.
Exceptions
- ArgumentNullException
Thrown if
imageordataSourceIdentifierisnullor empty.- ArgumentException
Thrown if no vision-enabled embedding model is registered with the engine.
ImportAsync(IList<ImageBuffer>, string, IList<string>, IList<MetadataCollection>, CancellationToken)
Asynchronously imports multiple images into a DataSource, creating a new section for each.
public Task<DataSource> ImportAsync(IList<ImageBuffer> images, string dataSourceIdentifier, IList<string> sectionIdentifiers, IList<MetadataCollection> metadataCollections = null, CancellationToken cancellationToken = default)
Parameters
imagesIList<ImageBuffer>A list of image buffers to import, each representing a separate section.
dataSourceIdentifierstringThe unique identifier for the target DataSource. If the data source exists, new sections are added; otherwise, a new data source is created.
sectionIdentifiersIList<string>A list of unique identifiers for the new sections. The count must match the number of images.
metadataCollectionsIList<MetadataCollection>An optional list of metadata collections to associate with each imported section. If provided, the count must match the number of images.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<DataSource>
A task that resolves to the updated or newly created DataSource.
Examples
// Create a RagEngine with a vision-enabled embedding model
LM visionModel = LM.LoadFromModelID("nomic-embed-vision");
RagEngine ragEngine = new RagEngine(visionModel);
// Load images
var images = new List<ImageBuffer>
{
ImageBuffer.Load("photo1.jpg"),
ImageBuffer.Load("photo2.jpg")
};
var sectionIds = new List<string> { "image1", "image2" };
// Import images
DataSource ds = await ragEngine.ImportAsync(
images: images,
dataSourceIdentifier: "imageCollection",
sectionIdentifiers: sectionIds);
Remarks
This method requires a vision-enabled embedding model to be registered with the engine.
Exceptions
- ArgumentNullException
Thrown if
images,dataSourceIdentifier, orsectionIdentifiersisnullor empty.- ArgumentOutOfRangeException
Thrown if the count of
sectionIdentifiers(ormetadataCollections, if provided) does not match the number of images.- ArgumentException
Thrown if no vision-enabled embedding model is registered with the engine.