diff --git a/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchVectorRecordStore.cs b/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchVectorRecordStore.cs index 612a93ba64c1..7704613f3ef9 100644 --- a/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchVectorRecordStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.AzureAISearch/AzureAISearchVectorRecordStore.cs @@ -386,27 +386,21 @@ private static async Task RunOperationAsync(string collectionName, string } catch (AggregateException ex) when (ex.InnerException is RequestFailedException innerEx) { - var wrapperException = new VectorStoreOperationException("Call to vector store failed.", ex); - - // Using Open Telemetry standard for naming of these entries. - // https://opentelemetry.io/docs/specs/semconv/attributes-registry/db/ - wrapperException.Data.Add("db.system", DatabaseName); - wrapperException.Data.Add("db.collection.name", collectionName); - wrapperException.Data.Add("db.operation.name", operationName); - - throw wrapperException; + throw new VectorStoreOperationException("Call to vector store failed.", ex) + { + VectorStoreType = DatabaseName, + CollectionName = collectionName, + OperationName = operationName + }; } catch (RequestFailedException ex) { - var wrapperException = new VectorStoreOperationException("Call to vector store failed.", ex); - - // Using Open Telemetry standard for naming of these entries. - // https://opentelemetry.io/docs/specs/semconv/attributes-registry/db/ - wrapperException.Data.Add("db.system", DatabaseName); - wrapperException.Data.Add("db.collection.name", collectionName); - wrapperException.Data.Add("db.operation.name", operationName); - - throw wrapperException; + throw new VectorStoreOperationException("Call to vector store failed.", ex) + { + VectorStoreType = DatabaseName, + CollectionName = collectionName, + OperationName = operationName + }; } } } diff --git a/dotnet/src/Connectors/Connectors.Memory.Qdrant/QdrantVectorRecordStore.cs b/dotnet/src/Connectors/Connectors.Memory.Qdrant/QdrantVectorRecordStore.cs index 6e15df2d46f3..e89492dbc78e 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Qdrant/QdrantVectorRecordStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Qdrant/QdrantVectorRecordStore.cs @@ -368,15 +368,12 @@ private static async Task RunOperationAsync(string collectionName, string } catch (RpcException ex) { - var wrapperException = new VectorStoreOperationException("Call to vector store failed.", ex); - - // Using Open Telemetry standard for naming of these entries. - // https://opentelemetry.io/docs/specs/semconv/attributes-registry/db/ - wrapperException.Data.Add("db.system", DatabaseName); - wrapperException.Data.Add("db.collection.name", collectionName); - wrapperException.Data.Add("db.operation.name", operationName); - - throw wrapperException; + throw new VectorStoreOperationException("Call to vector store failed.", ex) + { + VectorStoreType = DatabaseName, + CollectionName = collectionName, + OperationName = operationName + }; } } } diff --git a/dotnet/src/Connectors/Connectors.Memory.Redis/RedisVectorRecordStore.cs b/dotnet/src/Connectors/Connectors.Memory.Redis/RedisVectorRecordStore.cs index 26b0cd69ac48..4552339b9977 100644 --- a/dotnet/src/Connectors/Connectors.Memory.Redis/RedisVectorRecordStore.cs +++ b/dotnet/src/Connectors/Connectors.Memory.Redis/RedisVectorRecordStore.cs @@ -359,15 +359,12 @@ private static async Task RunOperationAsync(string collectionName, string } catch (RedisConnectionException ex) { - var wrapperException = new VectorStoreOperationException("Call to vector store failed.", ex); - - // Using Open Telemetry standard for naming of these entries. - // https://opentelemetry.io/docs/specs/semconv/attributes-registry/db/ - wrapperException.Data.Add("db.system", DatabaseName); - wrapperException.Data.Add("db.collection.name", collectionName); - wrapperException.Data.Add("db.operation.name", operationName); - - throw wrapperException; + throw new VectorStoreOperationException("Call to vector store failed.", ex) + { + VectorStoreType = DatabaseName, + CollectionName = collectionName, + OperationName = operationName + }; } } } diff --git a/dotnet/src/InternalUtilities/src/Data/VectorStoreErrorHandler.cs b/dotnet/src/InternalUtilities/src/Data/VectorStoreErrorHandler.cs index f2fc3f992de7..aaec06207ef1 100644 --- a/dotnet/src/InternalUtilities/src/Data/VectorStoreErrorHandler.cs +++ b/dotnet/src/InternalUtilities/src/Data/VectorStoreErrorHandler.cs @@ -31,15 +31,12 @@ public static T RunModelConversion(string databaseSystemName, string collecti } catch (Exception ex) { - var wrapperException = new VectorStoreRecordMappingException("Failed to convert vector store record.", ex); - - // Using Open Telemetry standard for naming of these entries. - // https://opentelemetry.io/docs/specs/semconv/attributes-registry/db/ - wrapperException.Data.Add("db.system", databaseSystemName); - wrapperException.Data.Add("db.collection.name", collectionName); - wrapperException.Data.Add("db.operation.name", operationName); - - throw wrapperException; + throw new VectorStoreRecordMappingException("Failed to convert vector store record.", ex) + { + VectorStoreType = databaseSystemName, + CollectionName = collectionName, + OperationName = operationName + }; } } } diff --git a/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreException.cs b/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreException.cs new file mode 100644 index 000000000000..9c481b5b8d55 --- /dev/null +++ b/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreException.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Microsoft.SemanticKernel.Memory; + +/// +/// Base exception type thrown for any type of failure when using vector stores. +/// +[Experimental("SKEXP0001")] +public abstract class VectorStoreException : KernelException +{ + /// + /// Initializes a new instance of the class. + /// + protected VectorStoreException() + { + } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// The error message that explains the reason for the exception. + protected VectorStoreException(string? message) : base(message) + { + } + + /// + /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference if no inner exception is specified. + protected VectorStoreException(string? message, Exception? innerException) : base(message, innerException) + { + } + + /// + /// Gets or sets the type of vector store that the failing operation was performed on. + /// + public string? VectorStoreType { get; init; } + + /// + /// Gets or sets the name of the vector store collection that the failing operation was performed on. + /// + public string? CollectionName { get; init; } + + /// + /// Gets or sets the name of the vector store operation that failed. + /// + public string? OperationName { get; init; } +} diff --git a/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreOperationException.cs b/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreOperationException.cs index 1390f613324c..9533982a96ae 100644 --- a/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreOperationException.cs +++ b/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreOperationException.cs @@ -1,13 +1,15 @@ // Copyright (c) Microsoft. All rights reserved. using System; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.SemanticKernel.Memory; /// /// Exception thrown when a vector store command fails, such as upserting a record or deleting a collection. /// -public class VectorStoreOperationException : KernelException +[Experimental("SKEXP0001")] +public class VectorStoreOperationException : VectorStoreException { /// /// Initializes a new instance of the class. diff --git a/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreRecordMappingException.cs b/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreRecordMappingException.cs index 8955175737e9..6683f3412a17 100644 --- a/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreRecordMappingException.cs +++ b/dotnet/src/SemanticKernel.Abstractions/Memory/VectorStoreRecordMappingException.cs @@ -1,13 +1,15 @@ // Copyright (c) Microsoft. All rights reserved. using System; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.SemanticKernel.Memory; /// /// Exception thrown when a failure occurs while trying to convert models for storage or retrieval. /// -public class VectorStoreRecordMappingException : KernelException +[Experimental("SKEXP0001")] +public class VectorStoreRecordMappingException : VectorStoreException { /// /// Initializes a new instance of the class.