Skip to content

Commit

Permalink
Fixed some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRamosEs committed Jun 7, 2024
1 parent 84acbf7 commit 73e1e25
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public sealed class MemoryContent
/// <summary>
/// Gets the metadata of the memory.
/// </summary>
public IDictionary<string, string>? Metadata { get; init; }
public IDictionary<string, string> Metadata { get; init; }

/// <summary>
/// Gets the chunks of the memory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Encamina.Enmarcha.SemanticKernel.Abstractions;
using Encamina.Enmarcha.SemanticKernel.Plugins.Chat.Options;

using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.Options;

using Microsoft.SemanticKernel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private static string GetResourceNameFromPluginInfoByFileName(IGrouping<(string

private static string ReadResource(Assembly assembly, string resourceName)
{
using var stream = assembly.GetManifestResourceStream(resourceName);
using var stream = assembly.GetManifestResourceStream(resourceName) ?? throw new InvalidOperationException($"The resource stream for '{resourceName}' is null. Ensure the resource name is correct and the resource is embedded in the assembly.");
using var streamReader = new StreamReader(stream!);

return streamReader.ReadToEnd();
Expand Down
10 changes: 6 additions & 4 deletions src/Encamina.Enmarcha.SemanticKernel/MemoryStoreExtender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ public virtual async Task DeleteMemoryAsync(string memoryId, string collectionNa
var memoryRecords = await MemoryStore.GetBatchAsync(collectionName, keys, cancellationToken: cancellationToken).ToListAsync(cancellationToken);
RaiseMemoryStoreEvent(new() { EventType = MemoryStoreEventTypes.GetMemory, MemoryIds = [memoryId], CollectionName = collectionName });

var metadata = JsonSerializer.Deserialize<Dictionary<string, string>>(memoryRecords[0].Metadata.AdditionalMetadata);
metadata ??= new Dictionary<string, string>();

return new MemoryContent
{
Metadata = JsonSerializer.Deserialize<Dictionary<string, string>>(memoryRecords[0].Metadata.AdditionalMetadata),
Metadata = metadata,
Chunks = memoryRecords.Select(m => m.Metadata.Text),
};
}
Expand Down Expand Up @@ -107,7 +110,7 @@ public virtual async IAsyncEnumerable<string> BatchUpsertMemoriesAsync(string co

if (totalChunks > 0)
{
memoryContent.Metadata?.Add(Constants.MetadataTotalChunksCount, totalChunks.ToString());
memoryContent.Metadata.Add(Constants.MetadataTotalChunksCount, totalChunks.ToString());

var embeddingTasks = memoryContent.Chunks.Select(async (chunk, i) =>
{
Expand All @@ -126,8 +129,7 @@ public virtual async IAsyncEnumerable<string> BatchUpsertMemoriesAsync(string co

await foreach (var key in asyncKeys)
{
var message = @"Processed memory record {item}.";
logger.LogInformation(message, key);
logger.LogInformation(@"Processed memory record {Item}.", key);

keys.Add(key);

Expand Down

0 comments on commit 73e1e25

Please sign in to comment.