mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-10-31 22:00:20 +00:00 
			
		
		
		
	Added a common retrieval context with text and image implementations
This commit is contained in:
		
							parent
							
								
									53dd6a6144
								
							
						
					
					
						commit
						55f55dab86
					
				
							
								
								
									
										45
									
								
								app/MindWork AI Studio/Tools/RAG/IRetrievalContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								app/MindWork AI Studio/Tools/RAG/IRetrievalContext.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | |||||||
|  | namespace AIStudio.Tools.RAG; | ||||||
|  | 
 | ||||||
|  | /// <summary> | ||||||
|  | /// The common interface for any retrieval context. | ||||||
|  | /// </summary> | ||||||
|  | public interface IRetrievalContext | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// The name of the data source. | ||||||
|  |     /// </summary> | ||||||
|  |     /// <remarks> | ||||||
|  |     /// Depending on the configuration, the AI is selecting the appropriate data source. | ||||||
|  |     /// In order to inform the user about where the information is coming from, the data | ||||||
|  |     /// source name is necessary. | ||||||
|  |     /// </remarks> | ||||||
|  |     public string DataSourceName { get; init; } | ||||||
|  | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// The category of the content, like e.g., text, audio, image, etc. | ||||||
|  |     /// </summary> | ||||||
|  |     public RetrievalContentCategory Category { get; init; } | ||||||
|  | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// What type of content is being retrieved? Like e.g., a project proposal, spreadsheet, art, etc. | ||||||
|  |     /// </summary> | ||||||
|  |     public RetrievalContentType Type { get; init; } | ||||||
|  | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// The path to the content, e.g., a URL, a file path, a path in a graph database, etc. | ||||||
|  |     /// </summary> | ||||||
|  |     public string Path { get; init; } | ||||||
|  | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// Links to related content, e.g., links to Wikipedia articles, links to sources, etc. | ||||||
|  |     /// </summary> | ||||||
|  |     /// <remarks> | ||||||
|  |     /// Why would you need links for retrieval? You are right that not all retrieval | ||||||
|  |     /// contexts need links. But think about a web search feature, where we want to | ||||||
|  |     /// query a search engine and get back a list of links to the most relevant | ||||||
|  |     /// matches. Think about a continuous web crawler that is constantly looking for | ||||||
|  |     /// new information and adding it to the knowledge base. In these cases, links | ||||||
|  |     /// are essential. | ||||||
|  |     /// </remarks> | ||||||
|  |     public IReadOnlyList<string> Links { get; init; } | ||||||
|  | } | ||||||
							
								
								
									
										33
									
								
								app/MindWork AI Studio/Tools/RAG/RetrievalImageContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								app/MindWork AI Studio/Tools/RAG/RetrievalImageContext.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | |||||||
|  | using AIStudio.Chat; | ||||||
|  | 
 | ||||||
|  | namespace AIStudio.Tools.RAG; | ||||||
|  | 
 | ||||||
|  | public sealed class RetrievalImageContext : IRetrievalContext | ||||||
|  | { | ||||||
|  |     #region Implementation of IRetrievalContext | ||||||
|  | 
 | ||||||
|  |     public required string DataSourceName { get; init; } | ||||||
|  | 
 | ||||||
|  |     public required RetrievalContentCategory Category { get; init; } | ||||||
|  | 
 | ||||||
|  |     public required RetrievalContentType Type { get; init; } | ||||||
|  | 
 | ||||||
|  |     public required string Path { get; init; } | ||||||
|  | 
 | ||||||
|  |     public IReadOnlyList<string> Links { get; init; } = []; | ||||||
|  | 
 | ||||||
|  |     #endregion | ||||||
|  | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// The type of the image source. | ||||||
|  |     /// </summary> | ||||||
|  |     /// <remarks> | ||||||
|  |     /// Is the image source a URL, a local file path, a base64 string, etc.? | ||||||
|  |     /// </remarks> | ||||||
|  |     public required ContentImageSource SourceType { get; init; } | ||||||
|  | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// The image source. | ||||||
|  |     /// </summary> | ||||||
|  |     public required string Source { get; set; } | ||||||
|  | } | ||||||
							
								
								
									
										38
									
								
								app/MindWork AI Studio/Tools/RAG/RetrievalTextContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								app/MindWork AI Studio/Tools/RAG/RetrievalTextContext.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | |||||||
|  | namespace AIStudio.Tools.RAG; | ||||||
|  | 
 | ||||||
|  | /// <summary> | ||||||
|  | /// The retrieval context for text data. | ||||||
|  | /// </summary> | ||||||
|  | public sealed class RetrievalTextContext : IRetrievalContext | ||||||
|  | { | ||||||
|  |     #region Implementation of IRetrievalContext | ||||||
|  |      | ||||||
|  |     public required string DataSourceName { get; init; } | ||||||
|  |      | ||||||
|  |     public required RetrievalContentCategory Category { get; init; } | ||||||
|  |      | ||||||
|  |     public required RetrievalContentType Type { get; init; } | ||||||
|  |      | ||||||
|  |     public required string Path { get; init; } | ||||||
|  | 
 | ||||||
|  |     public IReadOnlyList<string> Links { get; init; } = []; | ||||||
|  | 
 | ||||||
|  |     #endregion | ||||||
|  | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// The text content. | ||||||
|  |     /// </summary> | ||||||
|  |     /// <remarks> | ||||||
|  |     /// Should contain the matched text and some small context around it. | ||||||
|  |     /// </remarks> | ||||||
|  |     public required string MatchedText { get; set; } | ||||||
|  | 
 | ||||||
|  |     /// <summary> | ||||||
|  |     /// The surrounding content of the matched text. | ||||||
|  |     /// </summary> | ||||||
|  |     /// <remarks> | ||||||
|  |     /// Might give the user some context about the matched text. | ||||||
|  |     /// For example, one sentence or paragraph before and after the matched text. | ||||||
|  |     /// </remarks> | ||||||
|  |     public IReadOnlyList<string> SurroundingContent { get; set; } = []; | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user