Skip to content

Commit

Permalink
RavenDB-23471 Changed configuration option
Browse files Browse the repository at this point in the history
Lwiel committed Jan 10, 2025
1 parent 00b008a commit 6310123
Showing 2 changed files with 13 additions and 17 deletions.
17 changes: 12 additions & 5 deletions src/Raven.Server/Config/Categories/IndexingConfiguration.cs
Original file line number Diff line number Diff line change
@@ -91,6 +91,14 @@ public IndexingConfiguration(RavenConfiguration root)

EncryptedTransactionSizeLimit = defaultEncryptedTransactionSizeLimit;
MaxAllocationsAtDictionaryTraining = defaultMaxAllocationsAtDictionaryTraining;

MaxNumberOfCoresForLocalEmbeddingsGeneration = Environment.ProcessorCount switch
{
<= 2 => 1,
<= 8 => 2,
<= 16 => 4,
_ => 6
};
}

private static HashSet<string> GetValidIndexingConfigurationKeys()
@@ -620,12 +628,11 @@ public virtual bool RunInMemory
[ConfigurationEntry("Indexing.Corax.VectorSearch.OrderByScoreAutomatically", ConfigurationEntryScope.ServerWideOrPerDatabaseOrPerIndex)]
public bool CoraxVectorSearchOrderByScoreAutomatically { get; set; }

[Description("MaxPercentageOfThreadsForEmbeddings")]
[DefaultValue(25)]
[Description("Maximum number of processor cores that will be used for generating embedding from text locally.")]
[DefaultValue(DefaultValueSetInConstructor)]
[IndexUpdateType(IndexUpdateType.None)]
[ConfigurationEntry("Indexing.Corax.VectorSearch.MaxPercentageOfThreadsForEmbeddings", ConfigurationEntryScope.ServerWideOnly)]
public int MaxPercentageOfThreadsForEmbeddings { get; set; }

[ConfigurationEntry("Indexing.Corax.VectorSearch.MaxNumberOfCoresForLocalEmbeddingsGeneration", ConfigurationEntryScope.ServerWideOnly)]
public int MaxNumberOfCoresForLocalEmbeddingsGeneration { get; set; }

protected override void ValidateProperty(PropertyInfo property)
{
Original file line number Diff line number Diff line change
@@ -43,18 +43,7 @@ public static void Configure(RavenConfiguration configuration)
if (Embedder.IsValueCreated)
throw new InvalidOperationException("Embedder has already been initialized.");

var numberOfCoresToUse = CalculateNumberOfCoresForOnnx(configuration);

OnnxSessionOptions = new SessionOptions() { IntraOpNumThreads = numberOfCoresToUse };
}

private static int CalculateNumberOfCoresForOnnx(RavenConfiguration configuration)
{
var cores = (int)MathF.Floor(Environment.ProcessorCount * ((float)configuration.Indexing.MaxPercentageOfThreadsForEmbeddings / 100));

var numberOfCoresToUse = int.Max(1, cores);

return numberOfCoresToUse;
OnnxSessionOptions = new SessionOptions() { IntraOpNumThreads = configuration.Indexing.MaxNumberOfCoresForLocalEmbeddingsGeneration };
}

[ThreadStatic]

0 comments on commit 6310123

Please sign in to comment.