using AIStudio.Settings;
namespace AIStudio.Tools.Services;
///
/// Answers whether an edit throws the stored index of a data source away.
///
///
/// Nothing here knows which settings matter. Both questions are answered by building the embedding
/// signature twice and comparing the two, so the single place which decides stays
/// BuildEmbeddingSignature and this cannot drift away from what an indexing run then does.
///
internal static class EmbeddingChangeImpact
{
///
/// Whether an edited embedding provider invalidates what is stored for one of its data sources.
///
/// The data source, which the edit leaves alone.
/// The embedding provider as it is stored.
/// The embedding provider as it would be stored.
/// True when the stored index would be discarded.
public static bool AffectsStoredIndex(IDataSource dataSource, EmbeddingProvider before, EmbeddingProvider after) =>
!string.Equals(
DataSourceEmbeddingService.BuildEmbeddingSignature(dataSource, before),
DataSourceEmbeddingService.BuildEmbeddingSignature(dataSource, after),
StringComparison.Ordinal);
///
/// Whether an edited data source invalidates what is stored for it.
///
/// The embedding provider, which the edit leaves alone.
/// The data source as it is stored.
/// The data source as it would be stored.
/// True when the stored index would be discarded.
public static bool AffectsStoredIndex(EmbeddingProvider embeddingProvider, IDataSource before, IDataSource after) =>
!string.Equals(
DataSourceEmbeddingService.BuildEmbeddingSignature(before, embeddingProvider),
DataSourceEmbeddingService.BuildEmbeddingSignature(after, embeddingProvider),
StringComparison.Ordinal);
}