Skip to content
Prev Previous commit
Next Next commit
don't expose FileInfo as source via IngestionResult, as it could be S…
…tream in the future. Just expose the document id
  • Loading branch information
adamsitnik committed Nov 5, 2025
commit c71dc1317d51a81bcae03dfd595e0a45472cb430
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private async IAsyncEnumerable<IngestionResult> ProcessAsync(IEnumerable<FileInf
processFileActivity?.SetTag(ProcessSource.DocumentIdTagName, document.Identifier);
_logger?.ReadDocument(document.Identifier);

await IngestAsync(document, processFileActivity, cancellationToken).ConfigureAwait(false);
document = await IngestAsync(document, processFileActivity, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand All @@ -164,12 +164,13 @@ private async IAsyncEnumerable<IngestionResult> ProcessAsync(IEnumerable<FileInf
failure = ex;
}

yield return new IngestionResult(fileInfo, document, failure);
string documentId = document?.Identifier ?? fileInfo.FullName;
yield return new IngestionResult(documentId, document, failure);
}
}
}

private async Task IngestAsync(IngestionDocument document, Activity? parentActivity, CancellationToken cancellationToken)
private async Task<IngestionDocument> IngestAsync(IngestionDocument document, Activity? parentActivity, CancellationToken cancellationToken)
{
foreach (IngestionDocumentProcessor processor in DocumentProcessors)
{
Expand All @@ -188,5 +189,7 @@ private async Task IngestAsync(IngestionDocument document, Activity? parentActiv
_logger?.WritingChunks(GetShortName(_writer));
await _writer.WriteAsync(chunks, cancellationToken).ConfigureAwait(false);
_logger?.WroteChunks(document.Identifier);

return document;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.DataIngestion;
Expand All @@ -13,9 +12,9 @@ namespace Microsoft.Extensions.DataIngestion;
public sealed class IngestionResult
{
/// <summary>
/// Gets the source file that was ingested.
/// Gets the ID of the document that was ingested.
/// </summary>
public FileInfo Source { get; }
public string DocumentId { get; }

/// <summary>
/// Gets the ingestion document created from the source file, if reading the document has succeeded.
Expand All @@ -32,9 +31,9 @@ public sealed class IngestionResult
/// </summary>
public bool Succeeded => Exception is null;

internal IngestionResult(FileInfo source, IngestionDocument? document, Exception? exception)
internal IngestionResult(string documentId, IngestionDocument? document, Exception? exception)
{
Source = Throw.IfNull(source);
DocumentId = Throw.IfNullOrEmpty(documentId);
Document = document;
Exception = exception;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async Task Verify(IAsyncEnumerable<IngestionResult> results)
List<IngestionResult> ingestionResults = await results.ToListAsync();

Assert.Equal(_sampleFiles.Count, ingestionResults.Count);
Assert.All(ingestionResults, result => Assert.NotNull(result.Source));
Assert.All(ingestionResults, result => Assert.NotEmpty(result.DocumentId));
IngestionResult ingestionResult = Assert.Single(ingestionResults.Where(result => !result.Succeeded));
Assert.IsType<ExpectedException>(ingestionResult.Exception);
AssertErrorActivities(activities, expectedFailedActivitiesCount: 1);
Expand Down Expand Up @@ -246,7 +246,7 @@ private static void AssertAllIngestionsSucceeded(List<IngestionResult> ingestion
{
Assert.NotEmpty(ingestionResults);
Assert.All(ingestionResults, result => Assert.True(result.Succeeded));
Assert.All(ingestionResults, result => Assert.NotNull(result.Source));
Assert.All(ingestionResults, result => Assert.NotEmpty(result.DocumentId));
Assert.All(ingestionResults, result => Assert.NotNull(result.Document));
Assert.All(ingestionResults, result => Assert.Null(result.Exception));
}
Expand Down