-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
2,734 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Momento.Sdk.Config.Transport; | ||
|
||
namespace Momento.Sdk.Config; | ||
|
||
/// <summary> | ||
/// Contract for the Vector Index SDK configurables. | ||
/// </summary> | ||
public interface IVectorIndexConfiguration | ||
{ | ||
/// <inheritdoc cref="Microsoft.Extensions.Logging.ILoggerFactory" /> | ||
public ILoggerFactory LoggerFactory { get; } | ||
/// <inheritdoc cref="Momento.Sdk.Config.Transport.IVectorIndexTransportStrategy" /> | ||
public IVectorIndexTransportStrategy TransportStrategy { get; } | ||
|
||
/// <summary> | ||
/// Creates a new instance of the VectorIndexConfiguration object, updated to use the specified transport strategy. | ||
/// </summary> | ||
/// <param name="transportStrategy">This is responsible for configuring network tunables.</param> | ||
/// <returns>A VectorIndexConfiguration object using the provided transport strategy.</returns> | ||
public IVectorIndexConfiguration WithTransportStrategy(IVectorIndexTransportStrategy transportStrategy); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Momento.Sdk/Config/Transport/IVectorIndexTransportStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
|
||
namespace Momento.Sdk.Config.Transport; | ||
|
||
/// <summary> | ||
/// This is responsible for configuring network tunables for the vector index client. | ||
/// </summary> | ||
public interface IVectorIndexTransportStrategy | ||
{ | ||
/// <summary> | ||
/// Configures the low-level gRPC settings for the Momento Vector Index client's communication | ||
/// with the Momento server. | ||
/// </summary> | ||
public IGrpcConfiguration GrpcConfig { get; } | ||
|
||
/// <summary> | ||
/// Copy constructor to update the gRPC configuration | ||
/// </summary> | ||
/// <param name="grpcConfig"></param> | ||
/// <returns>A new IVectorIndexTransportStrategy with the specified grpcConfig</returns> | ||
public IVectorIndexTransportStrategy WithGrpcConfig(IGrpcConfiguration grpcConfig); | ||
|
||
/// <summary> | ||
/// Copy constructor to update the client timeout | ||
/// </summary> | ||
/// <param name="clientTimeout"></param> | ||
/// <returns>A new IVectorIndexTransportStrategy with the specified client timeout</returns> | ||
public IVectorIndexTransportStrategy WithClientTimeout(TimeSpan clientTimeout); | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Momento.Sdk/Config/Transport/StaticVectorIndexTransportStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Momento.Sdk.Config.Transport; | ||
|
||
/// <summary> | ||
/// The simplest way to configure the transport layer for the Momento Vector Index client. | ||
/// Provides static values for the gRPC configuration. | ||
/// </summary> | ||
public class StaticVectorIndexTransportStrategy : IVectorIndexTransportStrategy | ||
{ | ||
private readonly ILoggerFactory _loggerFactory; | ||
|
||
/// <inheritdoc /> | ||
public IGrpcConfiguration GrpcConfig { get; } | ||
|
||
/// <summary> | ||
/// Configures the transport layer for the Momento client. | ||
/// </summary> | ||
/// <param name="loggerFactory"></param> | ||
/// <param name="grpcConfig">Configures how Momento Vector Index client interacts with the Momento service via gRPC</param> | ||
public StaticVectorIndexTransportStrategy(ILoggerFactory loggerFactory, IGrpcConfiguration grpcConfig) | ||
{ | ||
_loggerFactory = loggerFactory; | ||
GrpcConfig = grpcConfig; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IVectorIndexTransportStrategy WithGrpcConfig(IGrpcConfiguration grpcConfig) | ||
{ | ||
return new StaticVectorIndexTransportStrategy(_loggerFactory, grpcConfig); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IVectorIndexTransportStrategy WithClientTimeout(TimeSpan clientTimeout) | ||
{ | ||
return new StaticVectorIndexTransportStrategy(_loggerFactory, GrpcConfig.WithDeadline(clientTimeout)); | ||
} | ||
|
||
/// <summary> | ||
/// Test equality by value. | ||
/// </summary> | ||
/// <param name="obj"></param> | ||
/// <returns></returns> | ||
public override bool Equals(object obj) | ||
{ | ||
if ((obj == null) || !this.GetType().Equals(obj.GetType())) | ||
{ | ||
return false; | ||
} | ||
|
||
var other = (StaticVectorIndexTransportStrategy)obj; | ||
return GrpcConfig.Equals(other.GrpcConfig); | ||
} | ||
|
||
/// <summary> | ||
/// Trivial hash code implementation. | ||
/// </summary> | ||
/// <returns></returns> | ||
public override int GetHashCode() | ||
{ | ||
return base.GetHashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Momento.Sdk.Config.Transport; | ||
|
||
namespace Momento.Sdk.Config; | ||
|
||
/// <inheritdoc cref="IVectorIndexConfiguration" /> | ||
public class VectorIndexConfiguration : IVectorIndexConfiguration | ||
{ | ||
/// <inheritdoc /> | ||
public ILoggerFactory LoggerFactory { get; } | ||
/// <inheritdoc /> | ||
public IVectorIndexTransportStrategy TransportStrategy { get; } | ||
|
||
|
||
/// <summary> | ||
/// Create a new instance of a Vector Index Configuration object with provided arguments: | ||
/// <see cref="Momento.Sdk.Config.IVectorIndexConfiguration.TransportStrategy"/>, | ||
/// and <see cref="Momento.Sdk.Config.IVectorIndexConfiguration.LoggerFactory"/> | ||
/// </summary> | ||
/// <param name="transportStrategy">This is responsible for configuring network tunables.</param> | ||
/// <param name="loggerFactory">This is responsible for configuring logging.</param> | ||
public VectorIndexConfiguration(ILoggerFactory loggerFactory, IVectorIndexTransportStrategy transportStrategy) | ||
{ | ||
LoggerFactory = loggerFactory; | ||
TransportStrategy = transportStrategy; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IVectorIndexConfiguration WithTransportStrategy(IVectorIndexTransportStrategy transportStrategy) | ||
{ | ||
return new VectorIndexConfiguration(LoggerFactory, transportStrategy); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object obj) | ||
{ | ||
if ((obj == null) || !this.GetType().Equals(obj.GetType())) | ||
{ | ||
return false; | ||
} | ||
|
||
var other = (VectorIndexConfiguration)obj; | ||
return TransportStrategy.Equals(other.TransportStrategy) && | ||
LoggerFactory.Equals(other.LoggerFactory); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() | ||
{ | ||
return base.GetHashCode(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Momento.Sdk.Config.Transport; | ||
|
||
namespace Momento.Sdk.Config; | ||
|
||
/// <summary> | ||
/// Provide pre-built vector index client configurations. | ||
/// </summary> | ||
public class VectorIndexConfigurations | ||
{ | ||
/// <summary> | ||
/// Laptop config provides defaults suitable for a medium-to-high-latency dev environment. Permissive timeouts, retries, and | ||
/// relaxed latency and throughput targets. | ||
/// </summary> | ||
public class Laptop : VectorIndexConfiguration | ||
{ | ||
private Laptop(ILoggerFactory loggerFactory, IVectorIndexTransportStrategy transportStrategy) | ||
: base(loggerFactory, transportStrategy) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Provides the latest recommended configuration for a Laptop environment. | ||
/// </summary> | ||
/// <remark> | ||
/// This configuration may change in future releases to take advantage of | ||
/// improvements we identify for default configurations. | ||
/// </remark> | ||
/// <param name="loggerFactory"></param> | ||
/// <returns></returns> | ||
public static IVectorIndexConfiguration Latest(ILoggerFactory? loggerFactory = null) | ||
{ | ||
return V1(loggerFactory); | ||
} | ||
|
||
/// <summary> | ||
/// Provides version 1 configuration for a Laptop environment. | ||
/// </summary> | ||
/// <remark> | ||
/// This configuration is guaranteed not to change in future | ||
/// releases of the Momento .NET SDK. | ||
/// </remark> | ||
/// <param name="loggerFactory"></param> | ||
/// <returns></returns> | ||
public static IVectorIndexConfiguration V1(ILoggerFactory? loggerFactory = null) | ||
{ | ||
var finalLoggerFactory = loggerFactory ?? NullLoggerFactory.Instance; | ||
IVectorIndexTransportStrategy transportStrategy = new StaticVectorIndexTransportStrategy( | ||
loggerFactory: finalLoggerFactory, | ||
grpcConfig: new StaticGrpcConfiguration(deadline: TimeSpan.FromMilliseconds(15000)) | ||
); | ||
return new Laptop(finalLoggerFactory, transportStrategy); | ||
} | ||
} | ||
} |
Oops, something went wrong.