Status callback for import methods #708
Replies: 4 comments 3 replies
-
@dluc Currently I use the bellow method to get the document status. But since the data ingestion process has the status anyway, it would be more efficient if we could pass a Any thoughts on this? public static async Task CheckDocumentStatusAsync(
this IKernelMemory kernelMemory,
string documentId,
string? index = null,
Func<int, int, DocumentStatus, CancellationToken, Task>? progressCallback = null,
int millisecondsDelay = 1000,
CancellationToken cancellationToken = default)
{
while (true)
{
var pipelineStatus = await kernelMemory
.GetDocumentStatusAsync(documentId, index, cancellationToken)
.ConfigureAwait(false);
var step = 0;
var stepsTotal = 0;
var status = DocumentStatus.None;
if (pipelineStatus is not null)
{
step = pipelineStatus.CompletedSteps.Count;
stepsTotal = pipelineStatus.Steps.Count;
if (step < stepsTotal)
{
step++;
}
if (pipelineStatus.Empty)
{
status = DocumentStatus.Empty;
}
else if (pipelineStatus.Failed)
{
status = DocumentStatus.Failed;
}
else if (pipelineStatus.Completed)
{
status = DocumentStatus.Completed;
}
else
{
status = DocumentStatus.InProgress;
}
}
if (progressCallback is not null)
{
await progressCallback(step, stepsTotal, status, cancellationToken).ConfigureAwait(false);
}
if (status == DocumentStatus.InProgress)
{
await Task.Delay(millisecondsDelay, cancellationToken).ConfigureAwait(false);
}
else
{
break;
}
}
}
´´´ |
Beta Was this translation helpful? Give feedback.
-
Hi @akordowski, I appreciate that this is a recurring scenario, in fact it comes up from time to time. KM API (
If we introduce a callback into On the other hand, you can easily introduce a custom callback using a custom handler. The default ingestion pipeline goes through these steps:
The list can be overridden using the
|
Beta Was this translation helpful? Give feedback.
-
As I understand this approach would only have one callback at the end of the process. What I have in mind is rather a progress callback everytime the status of the pipeline changes. As showed in my example this progress callback would be an optional
I don't see why this would necessarily have to be implemented also in the Web API, as this would be optional and just a helper so we can get the progress without calling the I hope I could explain my idea and intentions better. |
Beta Was this translation helpful? Give feedback.
-
The pipeline is fully customizable, the list of steps is... well... a list :-). To receive a call back after each action, the list would look like: extract text, callback 1, chunk, callback 2, generate embeddings, callback 3, store records, callback 4. |
Beta Was this translation helpful? Give feedback.
-
As I understand there is no way to determine if the ingestion pipeline is running in process or distributed. The only way I see is to call the
GetDocumentStatusAsync
orIsDocumentReadyAsync
methods periodically.How to provide a optional status callback parameter to the import methods (eg.
Func<DataPipelineStatus>? statusCallback = null
) or aOrchestrationType
property to theIKernelMemory
interface?Beta Was this translation helpful? Give feedback.
All reactions