Skip to content

Commit

Permalink
WeaviateMemoryException 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 95b2156 commit a6d2c49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 152 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.SemanticKernel.AI;
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Connectors.Memory.Weaviate.Diagnostics;
using Microsoft.SemanticKernel.Connectors.Memory.Weaviate.Http.ApiSchema;
using Microsoft.SemanticKernel.Connectors.Memory.Weaviate.Model;
using Microsoft.SemanticKernel.Diagnostics;
Expand Down Expand Up @@ -116,16 +115,14 @@ public async Task CreateCollectionAsync(string collectionName, CancellationToken

if (result == null || result.Description != description)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.CollectionNameConflict,
$"Name conflict for collection: {collectionName} with class name: {className}");
throw new SKException($"Name conflict for collection: {collectionName} with class name: {className}");
}

this._logger.LogTrace("Created collection: {0}, with class name: {1}", collectionName, className);
}
catch (HttpRequestException e)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToCreateCollection,
$"Unable to create collection: {collectionName}, with class name: {className}", e);
throw new SKException($"Unable to create collection: {collectionName}, with class name: {className}", e);
}
}

Expand Down Expand Up @@ -159,15 +156,15 @@ public async Task<bool> DoesCollectionExistAsync(string collectionName, Cancella
// For example a collectionName of '__this_collection' and 'this_collection' are
// both transformed to the class name of <classNamePrefix>thiscollection - even though the external
// system could consider them as unique collection names.
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.CollectionNameConflict, $"Unable to verify existing collection: {collectionName} with class name: {className}");
throw new SKException($"Unable to verify existing collection: {collectionName} with class name: {className}");
}
}

return exists;
}
catch (Exception e)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToGetClass, "Unable to get class from Weaviate", e);
throw new SKException("Unable to get class from Weaviate", e);
}
}

Expand All @@ -185,13 +182,13 @@ public async IAsyncEnumerable<string> GetCollectionsAsync([EnumeratorCancellatio
}
catch (Exception e)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToListCollections, "Unable to list collections", e);
throw new SKException("Unable to list collections", e);
}

GetSchemaResponse? getSchemaResponse = JsonSerializer.Deserialize<GetSchemaResponse>(responseContent, s_jsonSerializerOptions);
if (getSchemaResponse == null)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToListCollections, "Unable to deserialize list collections response");
throw new SKException("Unable to deserialize list collections response");
}

foreach (GetClassResponse? @class in getSchemaResponse.Classes!)
Expand All @@ -218,7 +215,7 @@ public async Task DeleteCollectionAsync(string collectionName, CancellationToken
}
catch (Exception e)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToDeleteCollection, "Collection deletion failed", e);
throw new SKException("Collection deletion failed", e);
}
}
}
Expand Down Expand Up @@ -256,14 +253,14 @@ public async IAsyncEnumerable<string> UpsertBatchAsync(string collectionName, IE
}
catch (HttpRequestException e)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToUpsertVectors, e);
throw new SKException("Failed to upsert vectors", e);
}

BatchResponse[]? result = JsonSerializer.Deserialize<BatchResponse[]>(responseContent, s_jsonSerializerOptions);

if (result == null)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToUpsertVectors, "Unable to deserialize batch response");
throw new SKException("Unable to deserialize batch response");
}

foreach (BatchResponse batchResponse in result)
Expand Down Expand Up @@ -363,7 +360,7 @@ public async Task RemoveAsync(string collectionName, string key, CancellationTok
}
catch (HttpRequestException e)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToRemoveVectorData, "Vector delete request failed", e);
throw new SKException("Vector delete request failed", e);
}
}

Expand Down Expand Up @@ -420,7 +417,7 @@ public async Task RemoveBatchAsync(string collectionName, IEnumerable<string> ke
}
catch (Exception e)
{
throw new WeaviateMemoryException(WeaviateMemoryException.ErrorCodes.FailedToGetVectorData, "Unable to deserialize Weaviate object", e);
throw new SKException("Unable to deserialize Weaviate object", e);
}

foreach ((MemoryRecord, double) kv in result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Connectors.Memory.Weaviate;
using Microsoft.SemanticKernel.Connectors.Memory.Weaviate.Diagnostics;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;
using Xunit;

Expand Down Expand Up @@ -42,7 +42,7 @@ public async Task EnsureConflictingCollectionNamesAreHandledForCreateAsync()
Assert.True(await this.weaviateMemoryStore.DoesCollectionExistAsync(collectionName));

var conflictingCollectionName = $"___{collectionName}";
await Assert.ThrowsAsync<WeaviateMemoryException>(async () =>
await Assert.ThrowsAsync<SKException>(async () =>
await this.weaviateMemoryStore.CreateCollectionAsync(conflictingCollectionName));
}

Expand All @@ -55,7 +55,7 @@ public async Task EnsureConflictingCollectionNamesAreHandledForDoesExistAsync()
Assert.True(await this.weaviateMemoryStore.DoesCollectionExistAsync(collectionName));

var conflictingCollectionName = $"___{collectionName}";
await Assert.ThrowsAsync<WeaviateMemoryException>(async () =>
await Assert.ThrowsAsync<SKException>(async () =>
await this.weaviateMemoryStore.DoesCollectionExistAsync(conflictingCollectionName));
}

Expand All @@ -68,7 +68,7 @@ public async Task EnsureConflictingCollectionNamesAreHandledForDeleteAsync()
Assert.True(await this.weaviateMemoryStore.DoesCollectionExistAsync(collectionName));

var conflictingCollectionName = $"___{collectionName}";
await Assert.ThrowsAsync<WeaviateMemoryException>(async () =>
await Assert.ThrowsAsync<SKException>(async () =>
await this.weaviateMemoryStore.DeleteCollectionAsync(conflictingCollectionName));
}

Expand Down

0 comments on commit a6d2c49

Please sign in to comment.