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. /// /// /// Each side is asked with the embedding provider it points at, never both with the same one. A /// data source carries only the id of its provider, while the signature carries what that provider /// is, so comparing both sides against one of them would report a changed embedding as no change /// at all -- and the next indexing run would then rebuild everything unannounced. /// /// The data source as it is stored. /// The embedding provider it points at today. /// The data source as it would be stored. /// The embedding provider it would point at. /// True when the stored index would be discarded. public static bool AffectsStoredIndex(IDataSource before, EmbeddingProvider beforeProvider, IDataSource after, EmbeddingProvider afterProvider) => !string.Equals( DataSourceEmbeddingService.BuildEmbeddingSignature(before, beforeProvider), DataSourceEmbeddingService.BuildEmbeddingSignature(after, afterProvider), StringComparison.Ordinal); }