improved stability of embedding chunks

This commit is contained in:
PaulKoudelka committed 2026-07-28 17:36:06 +02:00
1 parent 1bf9328fb9
commit 759c7f9d89
3 files changed
+37 -3

No files matched your search

@@ -25,6 +25,7 @@ public sealed record EmbeddingProvider(
int TokenLimit = 8_191) : ConfigurationBaseObject, ISecretId
{
public const int DEFAULT_TOKEN_LIMIT = 8_191;
private const int ASSUMED_TOKEN_LIMIT_SAFETY_PERCENT = 80;
private static readonly ILogger<EmbeddingProvider> LOGGER = Program.LOGGER_FACTORY.CreateLogger<EmbeddingProvider>();
@@ -57,6 +58,16 @@ public sealed record EmbeddingProvider(
[JsonIgnore]
public int EffectiveTokenLimit => this.TokenLimit > 0 ? this.TokenLimit : DEFAULT_TOKEN_LIMIT;
[JsonIgnore]
public bool UsesAssumedTokenSizing => string.IsNullOrWhiteSpace(this.TokenizerPath)
|| this.TokenLimit <= 0
|| this.TokenLimit == DEFAULT_TOKEN_LIMIT;
[JsonIgnore]
public int EffectiveChunkTokenLimit => this.UsesAssumedTokenSizing
? Math.Max(1, (int)Math.Ceiling(this.EffectiveTokenLimit * ASSUMED_TOKEN_LIMIT_SAFETY_PERCENT / 100d) - 1)
: this.EffectiveTokenLimit;
#endregion
public static bool TryParseEmbeddingProviderTable(int idx, LuaTable table, Guid configPluginId, out ConfigurationBaseObject provider)