Skip to content

Commit

Permalink
PineconeMemoryException 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 38fa1a9 commit 52811a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.SemanticKernel.Connectors.Memory.Pinecone.Http.ApiSchema;
using Microsoft.SemanticKernel.Connectors.Memory.Pinecone.Model;
using Microsoft.SemanticKernel.Diagnostics;

namespace Microsoft.SemanticKernel.Connectors.Memory.Pinecone;

Expand Down Expand Up @@ -258,9 +259,7 @@ public async Task DeleteAsync(
{
if (ids == null && string.IsNullOrEmpty(indexNamespace) && filter == null && !deleteAll)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToRemoveVectorData,
"Must provide at least one of ids, filter, or deleteAll");
throw new SKException("Must provide at least one of ids, filter, or deleteAll");
}

ids = ids?.ToList();
Expand Down Expand Up @@ -578,16 +577,12 @@ private async Task<string> GetIndexHostAsync(string indexName, CancellationToken

if (pineconeIndex == null)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.IndexNotFound,
"Index not found in Pinecone. Create index to perform operations with vectors.");
throw new SKException("Index not found in Pinecone. Create index to perform operations with vectors.");
}

if (string.IsNullOrWhiteSpace(pineconeIndex.Status.Host))
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.UnknownIndexHost,
$"Host of index {indexName} is unknown.");
throw new SKException($"Host of index {indexName} is unknown.");
}

this._logger.LogInformation("Found host {0} for index {1}", pineconeIndex.Status.Host, indexName);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Connectors.Memory.Pinecone.Model;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;

namespace Microsoft.SemanticKernel.Connectors.Memory.Pinecone;
Expand Down Expand Up @@ -65,9 +66,7 @@ public async Task CreateCollectionAsync(string collectionName, CancellationToken
{
if (!await this.DoesCollectionExistAsync(collectionName, cancellationToken).ConfigureAwait(false))
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.IndexNotReady,
"Index creation is not supported within memory store. " +
throw new SKException("Index creation is not supported within memory store. " +
$"It should be created manually or using {nameof(IPineconeClient.CreateIndexAsync)}. " +
$"Ensure index state is {IndexState.Ready}.");
}
Expand Down Expand Up @@ -130,10 +129,7 @@ public async Task<string> UpsertToNamespaceAsync(string indexName, string indexN
}
catch (HttpRequestException ex)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToUpsertVectors,
$"Failed to upsert due to HttpRequestException: {ex.Message}",
ex);
throw new SKException($"Failed to upsert due to HttpRequestException: {ex.Message}", ex);
}

return vectorData.Id;
Expand Down Expand Up @@ -213,10 +209,7 @@ public async IAsyncEnumerable<string> UpsertBatchToNamespaceAsync(
}
catch (HttpRequestException ex)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToUpsertVectors,
$"Failed to upsert due to HttpRequestException: {ex.Message}",
ex);
throw new SKException($"Failed to upsert due to HttpRequestException: {ex.Message}", ex);
}

foreach (PineconeDocument? v in vectorData)
Expand Down Expand Up @@ -261,17 +254,11 @@ public async IAsyncEnumerable<string> UpsertBatchToNamespaceAsync(
}
catch (HttpRequestException ex)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToGetVectorData,
$"Failed to get vector data from Pinecone: {ex.Message}",
ex);
throw new SKException($"Failed to get vector data from Pinecone: {ex.Message}", ex);
}
catch (MemoryException ex)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToConvertPineconeDocumentToMemoryRecord,
$"Failed deserialize Pinecone response to Memory Record: {ex.Message}",
ex);
throw new SKException($"Failed deserialize Pinecone response to Memory Record: {ex.Message}", ex);
}

return null;
Expand Down Expand Up @@ -323,7 +310,7 @@ public async IAsyncEnumerable<MemoryRecord> GetBatchFromNamespaceAsync(
/// <param name="withEmbedding">If true, the embedding will be returned in the memory record.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns></returns>
/// <exception cref="PineconeMemoryException"></exception>
/// <exception cref="SKException"></exception>
public async IAsyncEnumerable<MemoryRecord?> GetWithDocumentIdAsync(string indexName,
string documentId,
int limit = 3,
Expand Down Expand Up @@ -423,10 +410,7 @@ await this._pineconeClient.DeleteAsync(indexName, new[]
}
catch (HttpRequestException ex)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToRemoveVectorData,
$"Failed to remove vector data from Pinecone {ex.Message}",
ex);
throw new SKException($"Failed to remove vector data from Pinecone {ex.Message}", ex);
}
}

Expand Down Expand Up @@ -463,10 +447,7 @@ await this._pineconeClient.DeleteAsync(
}
catch (HttpRequestException ex)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToRemoveVectorData,
$"Failed to remove vector data from Pinecone {ex.Message}",
ex);
throw new SKException($"Failed to remove vector data from Pinecone {ex.Message}", ex);
}
}

Expand All @@ -478,7 +459,7 @@ await this._pineconeClient.DeleteAsync(
/// <param name="indexNamespace">The name associated with a collection of embeddings.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns></returns>
/// <exception cref="PineconeMemoryException"></exception>
/// <exception cref="SKException"></exception>
public async Task RemoveWithDocumentIdAsync(string indexName, string documentId, string indexNamespace, CancellationToken cancellationToken = default)
{
try
Expand All @@ -490,10 +471,7 @@ public async Task RemoveWithDocumentIdAsync(string indexName, string documentId,
}
catch (HttpRequestException ex)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToRemoveVectorData,
$"Failed to remove vector data from Pinecone {ex.Message}",
ex);
throw new SKException($"Failed to remove vector data from Pinecone {ex.Message}", ex);
}
}

Expand All @@ -505,7 +483,7 @@ public async Task RemoveWithDocumentIdAsync(string indexName, string documentId,
/// <param name="indexNamespace">The name associated with a collection of embeddings.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns></returns>
/// <exception cref="PineconeMemoryException"></exception>
/// <exception cref="SKException"></exception>
public async Task RemoveWithDocumentIdBatchAsync(
string indexName,
IEnumerable<string> documentIds,
Expand All @@ -522,10 +500,7 @@ public async Task RemoveWithDocumentIdBatchAsync(
}
catch (HttpRequestException ex)
{
throw new PineconeMemoryException(
PineconeMemoryException.ErrorCodes.FailedToRemoveVectorData,
$"Error in batch removing data from Pinecone {ex.Message}",
ex);
throw new SKException($"Error in batch removing data from Pinecone {ex.Message}", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.SemanticKernel.AI.Embeddings;
using Microsoft.SemanticKernel.Connectors.Memory.Pinecone;
using Microsoft.SemanticKernel.Connectors.Memory.Pinecone.Model;
using Microsoft.SemanticKernel.Diagnostics;
using Microsoft.SemanticKernel.Memory;
using Moq;
using Xunit;
Expand Down Expand Up @@ -62,13 +63,13 @@ public async Task ItThrowsExceptionOnIndexCreationAsync()
.ReturnsAsync(false);

// Act
var exception = await Assert.ThrowsAsync<PineconeMemoryException>(async () => await this._pineconeMemoryStore.CreateCollectionAsync("test"));
var exception = await Assert.ThrowsAsync<SKException>(async () => await this._pineconeMemoryStore.CreateCollectionAsync("test"));

// Assert
this._mockPineconeClient
.Verify<Task<bool>>(x => x.DoesIndexExistAsync("test", It.IsAny<CancellationToken>()), Times.Once());

Assert.Equal(PineconeMemoryException.ErrorCodes.IndexNotReady, exception.ErrorCode);
Assert.NotNull(exception);
}

[Fact]
Expand Down

0 comments on commit 52811a3

Please sign in to comment.