Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -386,27 +386,21 @@ private static async Task<T> RunOperationAsync<T>(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
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,12 @@ private static async Task<T> RunOperationAsync<T>(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
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,12 @@ private static async Task<T> RunOperationAsync<T>(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
};
}
}
}
15 changes: 6 additions & 9 deletions dotnet/src/InternalUtilities/src/Data/VectorStoreErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ public static T RunModelConversion<T>(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
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.SemanticKernel.Memory;

/// <summary>
/// Base exception type thrown for any type of failure when using vector stores.
/// </summary>
[Experimental("SKEXP0001")]
public abstract class VectorStoreException : KernelException
{
/// <summary>
/// Initializes a new instance of the <see cref="VectorStoreException"/> class.
/// </summary>
protected VectorStoreException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="VectorStoreException"/> class with a specified error message.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
protected VectorStoreException(string? message) : base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="VectorStoreException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
protected VectorStoreException(string? message, Exception? innerException) : base(message, innerException)
{
}

/// <summary>
/// Gets or sets the type of vector store that the failing operation was performed on.
/// </summary>
public string? VectorStoreType { get; init; }

/// <summary>
/// Gets or sets the name of the vector store collection that the failing operation was performed on.
/// </summary>
public string? CollectionName { get; init; }

/// <summary>
/// Gets or sets the name of the vector store operation that failed.
/// </summary>
public string? OperationName { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.SemanticKernel.Memory;

/// <summary>
/// Exception thrown when a vector store command fails, such as upserting a record or deleting a collection.
/// </summary>
public class VectorStoreOperationException : KernelException
[Experimental("SKEXP0001")]
public class VectorStoreOperationException : VectorStoreException
{
/// <summary>
/// Initializes a new instance of the <see cref="VectorStoreOperationException"/> class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.SemanticKernel.Memory;

/// <summary>
/// Exception thrown when a failure occurs while trying to convert models for storage or retrieval.
/// </summary>
public class VectorStoreRecordMappingException : KernelException
[Experimental("SKEXP0001")]
public class VectorStoreRecordMappingException : VectorStoreException
{
/// <summary>
/// Initializes a new instance of the <see cref="VectorStoreRecordMappingException"/> class.
Expand Down