using System.Text.Json.Serialization; using AIStudio.Chat; using AIStudio.Settings.DataModel; using AIStudio.Tools.PluginSystem; using AIStudio.Tools.RAG; namespace AIStudio.Settings; /// /// The common interface for all data sources. /// [JsonPolymorphic(TypeDiscriminatorPropertyName = "$type_discriminator")] [JsonDerivedType(typeof(DataSourceLocalDirectory), nameof(DataSourceType.LOCAL_DIRECTORY))] [JsonDerivedType(typeof(DataSourceLocalFile), nameof(DataSourceType.LOCAL_FILE))] [JsonDerivedType(typeof(DataSourceERI_V1), nameof(DataSourceType.ERI_V1))] public interface IDataSource : IConfigurationObject { /// /// Which type of data source is this? /// public DataSourceType Type { get; init; } /// /// The maximum number of matches one retrieval returns. Searched page by page, it is the size of a page. /// public ushort MaxMatches { get; init; } /// /// Perform the data retrieval process. /// /// The last user prompt from the chat. /// The chat thread. /// The cancellation token. /// The retrieved data context. public Task> RetrieveDataAsync(IContent lastUserPrompt, ChatThread thread, CancellationToken token = default); /// /// Search the data source for a query of its own, one page at a time. /// /// /// Unlike the retrieval above, the query need not be what the user wrote last: Semantic Search /// lets the model work it out from the conversation, and search as often as it takes. The first /// page holds what the retrieval above finds for the same text. How the pages are cut is /// described in RetrievalPaging. /// /// Since the user did not write the query, the user is not told about problems with it. They /// arrive in RetrievalPage.Gaps instead, together with everything else which kept the search /// from covering the whole data source. /// /// What to search for. /// The page to retrieve, from 1 up to RetrievalPaging.GetLastPage for MaxMatches. /// The chat thread. /// The cancellation token. /// The retrieved data contexts of this page, whether the next page is worth asking for, and what the search could not cover. /// The page is below 1 or beyond the last page. public Task RetrieveDataAsync(string query, int page, ChatThread thread, CancellationToken token = default); }