Table of Contents

Class DocumentRag.DocumentMetadata

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

Represents metadata associated with a document during import into a DocumentRag instance.

public sealed class DocumentRag.DocumentMetadata
Inheritance
DocumentRag.DocumentMetadata
Inherited Members

Examples

// Basic usage - auto-generated ID (useful for one-time imports)
var attachment = Attachment.FromFile("report.pdf");
var simpleMetadata = new DocumentMetadata(attachment);
await docRag.ImportDocumentAsync(attachment, simpleMetadata, "reports");

// With explicit ID - recommended for document lifecycle management
// The ID can be used later to delete or update the document
var metadata = new DocumentMetadata(attachment, id: "quarterly-report-2024-q4");
await docRag.ImportDocumentAsync(attachment, metadata, "reports");

// Later, delete the document using the same ID
await docRag.DeleteDocumentAsync("quarterly-report-2024-q4", "reports");

// With source URI for reference links
var metadataWithUri = new DocumentMetadata(
    attachment, 
    id: "policy-handbook-v2",
    sourceUri: "https://intranet.example.com/docs/policy-handbook.pdf");

// With custom metadata for filtering or categorization
var customMetadata = new MetadataCollection
{
    { "author", "John Smith" },
    { "department", "Finance" },
    { "version", "2.1" }
};
var fullMetadata = new DocumentMetadata(
    attachment,
    id: "finance-guidelines-2024",
    sourceUri: "internal://docs/finance/guidelines",
    customMetadata: customMetadata);
await docRag.ImportDocumentAsync(attachment, fullMetadata, "finance-docs");

Remarks

Document metadata is attached to each section created during document import, enabling source attribution when generating responses. The metadata includes a unique document identifier, the document name, an optional source URI, and any custom metadata fields.

The Id property is particularly important for document lifecycle management. Use it with DeleteDocument(string, string, CancellationToken) or DeleteDocumentAsync(string, string, CancellationToken) to remove a document from the index. When you need to update a document, delete the existing version using its ID and re-import.

When querying partitions via QueryPartitions(string, IEnumerable<PartitionSimilarity>, IConversation, CancellationToken) or QueryPartitionsAsync(string, IEnumerable<PartitionSimilarity>, IConversation, CancellationToken), the metadata is used to construct DocumentReference instances that identify the source document and page for each matched partition.

Constructors

DocumentMetadata(Attachment, string, string, MetadataCollection)

Initializes a new instance of the DocumentRag.DocumentMetadata class.

DocumentMetadata(string, string, string, MetadataCollection)

Initializes a new instance of the DocumentRag.DocumentMetadata class with a specified name.

Properties

CustomMetadata

Gets or sets custom metadata to attach to all sections from this document.

Id

Gets or sets the unique identifier for the document.

Name

Gets or sets the display name of the document.

SourceUri

Gets or sets an optional URI for the document source.

Methods

IsReservedMetadataKey(string)

Determines whether the specified metadata key is reserved for internal use by the document RAG system.