mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-07 13:29:40 +00:00
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
45 lines
1.9 KiB
C#
45 lines
1.9 KiB
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace AIStudio.Tools.Services.Indexing;
|
|
|
|
/// <summary>
|
|
/// The ids under which documents and their chunks are stored.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Derived rather than random, so the same document of the same data source always ends up under
|
|
/// the same ids, in the vector store as well as in the index store. The formats must stay as they
|
|
/// are: every stored id was made with them.
|
|
/// </remarks>
|
|
internal static class IndexedDocumentIds
|
|
{
|
|
/// <summary>
|
|
/// The id of one chunk, which is also the id of its point in the vector store.
|
|
/// </summary>
|
|
/// <param name="dataSourceId">The data source the document belongs to.</param>
|
|
/// <param name="fingerprint">The fingerprint of the document as it was read.</param>
|
|
/// <param name="chunkIndex">The position of the chunk within the document.</param>
|
|
/// <returns>The chunk id.</returns>
|
|
public static string CreateChunkId(string dataSourceId, string fingerprint, int chunkIndex) =>
|
|
CreateStableGuid($"{dataSourceId}:chunk:{fingerprint}:{chunkIndex}");
|
|
|
|
/// <summary>
|
|
/// The id of a document's row in the index store, which its chunks point at.
|
|
/// </summary>
|
|
/// <param name="dataSourceId">The data source the document belongs to.</param>
|
|
/// <param name="absolutePath">What the row is stored under. For a file, its absolute path.</param>
|
|
/// <returns>The document id.</returns>
|
|
public static string CreateParentId(string dataSourceId, string absolutePath) =>
|
|
CreateStableGuid($"{dataSourceId}:parent-file:{absolutePath}");
|
|
|
|
private static string CreateStableGuid(string source)
|
|
{
|
|
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(source));
|
|
var guidBytes = hash[..16].ToArray();
|
|
|
|
guidBytes[6] = (byte)((guidBytes[6] & 0x0F) | 0x40);
|
|
guidBytes[8] = (byte)((guidBytes[8] & 0x3F) | 0x80);
|
|
|
|
return new Guid(guidBytes).ToString();
|
|
}
|
|
} |