mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 11:53:48 +00:00
Offer a repair for data sources with an unreadable index
This commit is contained in:
7 files changed
+163
-2
No files matched your search
@@ -5,6 +5,43 @@ namespace AIStudio.Tools.Services;
|
||||
|
||||
public sealed partial class DataSourceEmbeddingService
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws away everything stored for one data source and starts a fresh indexing run.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The one way out of an index which cannot be read, and nothing in the app takes it by itself:
|
||||
/// a rebuild sends every document of the data source to the embedding provider once more, which
|
||||
/// costs money with a cloud provider and hours with a large data source. It happens because the
|
||||
/// user asked for it, after being told both.
|
||||
///
|
||||
/// An active run is stopped first, the same way deleting a data source does it. The repair is
|
||||
/// offered for a failed data source only, so there should be none -- but a file watcher may
|
||||
/// well have queued one between the click and this call, and discarding the index next to a
|
||||
/// live run would leave it half thrown away.
|
||||
/// </remarks>
|
||||
/// <param name="dataSourceId">The data source to build anew.</param>
|
||||
public async Task RepairDataSourceAsync(string dataSourceId)
|
||||
{
|
||||
if (!this.TryGetConfiguredDataSource(dataSourceId, out var dataSource) || !this.IsSupportedInternalDataSource(dataSource))
|
||||
return;
|
||||
|
||||
logger.LogWarning(
|
||||
"Repairing data source '{DataSourceName}' ({DataSourceId}) on the user's request: the stored index is discarded and built anew.",
|
||||
dataSource.Name,
|
||||
dataSource.Id);
|
||||
|
||||
var activeRun = this.CancelActiveDataSourceRun(dataSource);
|
||||
this.ClearQueuedDataSourceState(dataSourceId);
|
||||
if (activeRun is not null)
|
||||
await activeRun.Completion.Task;
|
||||
|
||||
await this.ResetPersistedStateAsync(dataSourceId, null, null, CancellationToken.None);
|
||||
this.statuses.TryRemove(dataSourceId, out _);
|
||||
this.PublishStatusChanged();
|
||||
|
||||
await this.QueueDataSourceAsync(dataSource, true, DataSourceEmbeddingRefreshMode.MANUAL_RETRY);
|
||||
}
|
||||
|
||||
private async Task ResetPersistedStateAsync(
|
||||
string dataSourceId,
|
||||
VectorStoreClient? vectorStore,
|
||||
|
||||
Reference in new issue
Block a user