mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 09:58:00 +00:00
Merge branch 'main' into chunk-data
This commit is contained in:
commit
00b6c98f3b
167 files changed
+8153
-3577
No files matched your search
@@ -0,0 +1,59 @@
|
||||
namespace AIStudio.Tools.Databases;
|
||||
|
||||
public abstract class EmbeddingStore(string name, string path)
|
||||
{
|
||||
public string Name => name;
|
||||
|
||||
public virtual string CacheKey => name;
|
||||
|
||||
public virtual DatabaseClientStatus Status => DatabaseClientStatus.AVAILABLE;
|
||||
|
||||
public bool IsAvailable => this.Status is DatabaseClientStatus.AVAILABLE;
|
||||
|
||||
private string Path => path;
|
||||
|
||||
private ILogger<EmbeddingStore>? logger;
|
||||
|
||||
public abstract IAsyncEnumerable<(string Label, string Value)> GetDisplayInfo();
|
||||
|
||||
protected string GetStorageSize()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(this.Path))
|
||||
{
|
||||
this.logger!.LogError($"Error: Database path '{this.Path}' cannot be null or empty.");
|
||||
return "0 B";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(this.Path))
|
||||
{
|
||||
this.logger!.LogError($"Error: Database path '{this.Path}' does not exist.");
|
||||
return "0 B";
|
||||
}
|
||||
var files = Directory.EnumerateFiles(this.Path, "*", SearchOption.AllDirectories)
|
||||
.Where(file => !System.IO.Path.GetDirectoryName(file)!.Contains("cert", StringComparison.OrdinalIgnoreCase));
|
||||
var size = files.Sum(file => new FileInfo(file).Length);
|
||||
return FormatBytes(size);
|
||||
}
|
||||
|
||||
private static string FormatBytes(long size)
|
||||
{
|
||||
string[] suffixes = { "B", "KB", "MB", "GB", "TB", "PB" };
|
||||
int suffixIndex = 0;
|
||||
double convertedSize = size;
|
||||
|
||||
while (convertedSize >= 1024 && suffixIndex < suffixes.Length - 1)
|
||||
{
|
||||
convertedSize /= 1024;
|
||||
suffixIndex++;
|
||||
}
|
||||
|
||||
return $"{convertedSize:0.##} {suffixes[suffixIndex]}";
|
||||
}
|
||||
|
||||
public void SetLogger(ILogger<EmbeddingStore> logService)
|
||||
{
|
||||
this.logger = logService;
|
||||
}
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
Reference in new issue
Block a user