mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-20 23:33:37 +00:00
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
64 lines
2.9 KiB
C#
64 lines
2.9 KiB
C#
using AIStudio.Tools.Databases.IndexStore;
|
|
using AIStudio.Tools.Databases.VectorStore;
|
|
|
|
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,
|
|
IndexStoreClient? indexStore,
|
|
CancellationToken token)
|
|
{
|
|
await this.DeleteCollectionAsync(DataSourceEmbeddingNames.GetCollectionName(dataSourceId), vectorStore, token);
|
|
|
|
indexStore ??= await databaseClientProvider.GetIndexStoreAsync(token);
|
|
if (!indexStore.IsAvailable)
|
|
{
|
|
logger.LogWarning("Could not delete local RAG embedding state for data source '{DataSourceId}' because the database '{DatabaseName}' is unavailable.", dataSourceId, indexStore.Name);
|
|
return;
|
|
}
|
|
|
|
await indexStore.DeleteDataSourceAsync(dataSourceId, token);
|
|
logger.LogInformation("Reset persisted local RAG embedding state for data source '{DataSourceId}'.", dataSourceId);
|
|
}
|
|
}
|