Skip to content

Commit

Permalink
MemoryException is replaced by SKException.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMenshykh committed Jul 18, 2023
1 parent 440de93 commit ef8ee07
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ await foreach (string id in this.UpsertBatchToNamespaceAsync(collectionName, str
{
throw new SKException($"Failed to get vector data from Pinecone: {ex.Message}", ex);
}
catch (MemoryException ex)
catch (SKException)
{
throw new SKException($"Failed deserialize Pinecone response to Memory Record: {ex.Message}", ex);
throw;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ public async Task<string> UpsertAsync(string collectionName, MemoryRecord record
{
throw new SKException("Failed to get vector data", ex);
}
catch (MemoryException ex)
catch (SKException)
{
throw new SKException("Failed to convert Qdrant vector record to memory record", ex);
throw;
}
}

Expand Down Expand Up @@ -209,9 +209,9 @@ public async Task<string> UpsertAsync(string collectionName, MemoryRecord record
{
throw new SKException("Failed to get vector data", ex);
}
catch (MemoryException ex)
catch (SKException)
{
throw new SKException("Failed to convert Qdrant vector record to memory record", ex);
throw;
}
}

Expand Down
87 changes: 0 additions & 87 deletions dotnet/src/SemanticKernel.Abstractions/Memory/MemoryException.cs

This file was deleted.

7 changes: 3 additions & 4 deletions dotnet/src/SemanticKernel.Abstractions/Memory/MemoryRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Diagnostics;

namespace Microsoft.SemanticKernel.Memory;

Expand Down Expand Up @@ -120,7 +121,7 @@ public class MemoryRecord : DataEntryBase
/// <param name="key">Optional existing database key.</param>
/// <param name="timestamp">optional timestamp.</param>
/// <returns>Memory record</returns>
/// <exception cref="MemoryException"></exception>
/// <exception cref="SKException"></exception>
public static MemoryRecord FromJsonMetadata(
string json,
Embedding<float>? embedding,
Expand All @@ -130,9 +131,7 @@ public class MemoryRecord : DataEntryBase
var metadata = JsonSerializer.Deserialize<MemoryRecordMetadata>(json);
return metadata != null
? new MemoryRecord(metadata, embedding ?? Embedding<float>.Empty, key, timestamp)
: throw new MemoryException(
MemoryException.ErrorCodes.UnableToDeserializeMetadata,
"Unable to create memory record from serialized metadata");
: throw new SKException("Unable to create memory record from serialized metadata");
}

/// <summary>
Expand Down
63 changes: 0 additions & 63 deletions dotnet/src/SemanticKernel.UnitTests/Memory/MemoryExceptionTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;
using Xunit;

Expand Down Expand Up @@ -85,7 +86,7 @@ public async Task ItCannotCreateDuplicateCollectionAsync()
await this._db.CreateCollectionAsync(collection);

// Assert
await Assert.ThrowsAsync<MemoryException>(async () => await this._db.CreateCollectionAsync(collection));
await Assert.ThrowsAsync<SKException>(async () => await this._db.CreateCollectionAsync(collection));
}

[Fact]
Expand All @@ -103,7 +104,7 @@ public async Task ItCannotInsertIntoNonExistentCollectionAsync()
this._collectionNum++;

// Assert
await Assert.ThrowsAsync<MemoryException>(async () => await this._db.UpsertAsync(collection, testRecord));
await Assert.ThrowsAsync<SKException>(async () => await this._db.UpsertAsync(collection, testRecord));
}

[Fact]
Expand Down Expand Up @@ -590,6 +591,6 @@ public async Task ItThrowsWhenDeletingNonExistentCollectionAsync()
this._collectionNum++;

// Act
await Assert.ThrowsAsync<MemoryException>(() => this._db.DeleteCollectionAsync(collection));
await Assert.ThrowsAsync<SKException>(() => this._db.DeleteCollectionAsync(collection));
}
}
7 changes: 3 additions & 4 deletions dotnet/src/SemanticKernel/Memory/VolatileMemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Task CreateCollectionAsync(string collectionName, CancellationToken cance
{
if (!this._store.TryAdd(collectionName, new ConcurrentDictionary<string, MemoryRecord>()))
{
return Task.FromException(new MemoryException(MemoryException.ErrorCodes.FailedToCreateCollection, $"Could not create collection {collectionName}"));
return Task.FromException(new SKException($"Could not create collection {collectionName}"));
}

return Task.CompletedTask;
Expand All @@ -47,7 +47,7 @@ public Task DeleteCollectionAsync(string collectionName, CancellationToken cance
{
if (!this._store.TryRemove(collectionName, out _))
{
return Task.FromException(new MemoryException(MemoryException.ErrorCodes.FailedToDeleteCollection, $"Could not delete collection {collectionName}"));
return Task.FromException(new SKException($"Could not delete collection {collectionName}"));
}

return Task.CompletedTask;
Expand All @@ -66,8 +66,7 @@ public Task<string> UpsertAsync(string collectionName, MemoryRecord record, Canc
}
else
{
return Task.FromException<string>(new MemoryException(MemoryException.ErrorCodes.AttemptedToAccessNonexistentCollection,
$"Attempted to access a memory collection that does not exist: {collectionName}"));
return Task.FromException<string>(new SKException($"Attempted to access a memory collection that does not exist: {collectionName}"));
}

return Task.FromResult(record.Key);
Expand Down

0 comments on commit ef8ee07

Please sign in to comment.