mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-24 20:52:11 +00:00
disabled images for RAG for now
This commit is contained in:
parent
c92e83ee59
commit
d95487aa6e
@ -15,6 +15,7 @@ public sealed partial class DataSourceEmbeddingService
|
|||||||
{
|
{
|
||||||
private const string OFFICE_LOCK_FILE_PREFIX = "~$";
|
private const string OFFICE_LOCK_FILE_PREFIX = "~$";
|
||||||
private const int DEFAULT_CHUNK_OVERLAP_TOKEN_LENGTH = 300;
|
private const int DEFAULT_CHUNK_OVERLAP_TOKEN_LENGTH = 300;
|
||||||
|
private const bool IMAGE_EMBEDDING_ENABLED = false;
|
||||||
|
|
||||||
private static readonly string[] RAG_DELIMITED_TABLE_FILE_EXTENSIONS = ["csv", "tsv"];
|
private static readonly string[] RAG_DELIMITED_TABLE_FILE_EXTENSIONS = ["csv", "tsv"];
|
||||||
private static readonly string[] RAG_SPREADSHEET_FILE_EXTENSIONS = ["ods", "xlsm", "xlsb"];
|
private static readonly string[] RAG_SPREADSHEET_FILE_EXTENSIONS = ["ods", "xlsm", "xlsb"];
|
||||||
@ -46,17 +47,7 @@ public sealed partial class DataSourceEmbeddingService
|
|||||||
{
|
{
|
||||||
var options = this.GetChunkingOptions(dataSource, embeddingProvider);
|
var options = this.GetChunkingOptions(dataSource, embeddingProvider);
|
||||||
var strategy = this.GetChunkingStrategy(filePath);
|
var strategy = this.GetChunkingStrategy(filePath);
|
||||||
ExtractedFileContent content;
|
var content = await this.ReadExtractedFileContentAsync(filePath, embeddingProvider, token);
|
||||||
|
|
||||||
if (this.IsImageFilePath(filePath))
|
|
||||||
{
|
|
||||||
var imageIndexText = this.BuildImageIndexText(filePath);
|
|
||||||
content = new(imageIndexText, [new(imageIndexText, null)]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
content = await this.ReadExtractedFileContentAsync(filePath, embeddingProvider, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
await foreach (var chunk in this.SplitByChunkingStrategyAsync(content, strategy, options, embeddingProvider, token))
|
await foreach (var chunk in this.SplitByChunkingStrategyAsync(content, strategy, options, embeddingProvider, token))
|
||||||
yield return chunk;
|
yield return chunk;
|
||||||
@ -567,12 +558,6 @@ public sealed partial class DataSourceEmbeddingService
|
|||||||
|
|
||||||
private ChunkingStrategy GetChunkingStrategy(string filePath)
|
private ChunkingStrategy GetChunkingStrategy(string filePath)
|
||||||
{
|
{
|
||||||
if (this.IsImageFilePath(filePath))
|
|
||||||
return new("image", [
|
|
||||||
new("Whitespace", SplitByWhitespace),
|
|
||||||
new("Hard cut", null),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (this.IsPresentationFilePath(filePath))
|
if (this.IsPresentationFilePath(filePath))
|
||||||
return new("presentation", [
|
return new("presentation", [
|
||||||
new("Slide", SplitBySourceSegments, true),
|
new("Slide", SplitBySourceSegments, true),
|
||||||
@ -917,7 +902,7 @@ public sealed partial class DataSourceEmbeddingService
|
|||||||
private bool IsSupportedRagFilePath(string filePath)
|
private bool IsSupportedRagFilePath(string filePath)
|
||||||
{
|
{
|
||||||
var extension = Path.GetExtension(filePath).TrimStart('.');
|
var extension = Path.GetExtension(filePath).TrimStart('.');
|
||||||
return FileTypes.IsAllowedPath(filePath, FileTypes.DOCUMENT, FileTypes.IMAGE)
|
return FileTypes.IsAllowedPath(filePath, FileTypes.DOCUMENT)
|
||||||
|| RAG_DELIMITED_TABLE_FILE_EXTENSIONS.Contains(extension, StringComparer.OrdinalIgnoreCase)
|
|| RAG_DELIMITED_TABLE_FILE_EXTENSIONS.Contains(extension, StringComparer.OrdinalIgnoreCase)
|
||||||
|| RAG_SPREADSHEET_FILE_EXTENSIONS.Contains(extension, StringComparer.OrdinalIgnoreCase)
|
|| RAG_SPREADSHEET_FILE_EXTENSIONS.Contains(extension, StringComparer.OrdinalIgnoreCase)
|
||||||
|| RAG_SPREADSHEET_ADD_IN_FILE_EXTENSIONS.Contains(extension, StringComparer.OrdinalIgnoreCase);
|
|| RAG_SPREADSHEET_ADD_IN_FILE_EXTENSIONS.Contains(extension, StringComparer.OrdinalIgnoreCase);
|
||||||
@ -928,6 +913,9 @@ public sealed partial class DataSourceEmbeddingService
|
|||||||
if (this.IsSkippedRagFile(file))
|
if (this.IsSkippedRagFile(file))
|
||||||
return RagFileIndexingDecision.EXCLUDED;
|
return RagFileIndexingDecision.EXCLUDED;
|
||||||
|
|
||||||
|
if (!IMAGE_EMBEDDING_ENABLED && this.IsImageFilePath(file.FullName))
|
||||||
|
return RagFileIndexingDecision.EXCLUDED;
|
||||||
|
|
||||||
return this.IsSupportedRagFilePath(file.FullName)
|
return this.IsSupportedRagFilePath(file.FullName)
|
||||||
? RagFileIndexingDecision.INDEXABLE
|
? RagFileIndexingDecision.INDEXABLE
|
||||||
: RagFileIndexingDecision.UNSUPPORTED;
|
: RagFileIndexingDecision.UNSUPPORTED;
|
||||||
@ -975,26 +963,6 @@ public sealed partial class DataSourceEmbeddingService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string BuildImageIndexText(string filePath)
|
|
||||||
{
|
|
||||||
var fileName = Path.GetFileName(filePath);
|
|
||||||
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);
|
|
||||||
var extension = Path.GetExtension(filePath).TrimStart('.');
|
|
||||||
var normalizedName = fileNameWithoutExtension
|
|
||||||
.Replace('_', ' ')
|
|
||||||
.Replace('-', ' ')
|
|
||||||
.Trim();
|
|
||||||
|
|
||||||
return $$"""
|
|
||||||
Image asset
|
|
||||||
File name: {{fileName}}
|
|
||||||
Type: {{extension}}
|
|
||||||
Search terms: {{normalizedName}}
|
|
||||||
Path: {{filePath}}
|
|
||||||
Note: The current RAG embedding pipeline stores image files by metadata only. Visual content is not OCRed or captioned yet.
|
|
||||||
""";
|
|
||||||
}
|
|
||||||
|
|
||||||
private string BuildEmbeddingSignature(IDataSource dataSource, EmbeddingProvider embeddingProvider, ChunkingOptions chunkingOptions)
|
private string BuildEmbeddingSignature(IDataSource dataSource, EmbeddingProvider embeddingProvider, ChunkingOptions chunkingOptions)
|
||||||
{
|
{
|
||||||
return string.Join('|',
|
return string.Join('|',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user