Table of Contents

Method DeleteDocument

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

DeleteDocument(string, string, CancellationToken)

Deletes all sections associated with a specific document from a data source.

public bool DeleteDocument(string documentId, string dataSourceIdentifier, CancellationToken cancellationToken = default)

Parameters

documentId string

The unique identifier of the document to delete. This corresponds to the document ID assigned during import via DocumentRag.DocumentMetadata.

dataSourceIdentifier string

The identifier of the data source containing the document.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

bool

true if the data source was found and the deletion was attempted; false if no matching data source exists.

Examples

// First, import a document with an explicit ID
var attachment = Attachment.FromFile("report.pdf");
var metadata = new DocumentMetadata(attachment, id: "report-2024-q4");
docRag.ImportDocument(attachment, metadata, "financial-reports");

// Later, delete the document using the same ID
bool deleted = docRag.DeleteDocument("report-2024-q4", "financial-reports");

if (deleted)
{
    Console.WriteLine("Document removed from index.");
}

Remarks

This method removes all partitions that were created when the specified document was imported. Documents are identified by their unique document ID stored in partition metadata during import.

When using a IVectorStore, deletions are performed directly against the collection. For in-memory storage, sections are removed from the data source object.

Exceptions

ArgumentException

Thrown if documentId or dataSourceIdentifier is null, empty, or whitespace.