Skip to content

Commit

Permalink
refactor: improve UX of the constructor overload that accepts an Http…
Browse files Browse the repository at this point in the history
…Client instance
  • Loading branch information
neon-sunset committed Sep 27, 2024
1 parent f82b555 commit beb28b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ static class Constants
{
public const string RestApiKey = "Api-Key";
public const string GrpcApiKey = "api-key";

public const string ApiVersion = "2024-07";

public static readonly Uri BaseUrl = new("https://api.pinecone.io");
public static readonly string UserAgent =
$"lang=C#; Pinecone.NET/{typeof(Constants).Assembly.GetName().Version?.ToString(3) ?? "0.0.0"}";

Expand Down
10 changes: 8 additions & 2 deletions src/PineconeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed class PineconeClient : IDisposable
/// <param name="apiKey">API key used to connect to Pinecone.</param>
/// <param name="loggerFactory">The logger factory to be used.</param>
public PineconeClient(string apiKey, ILoggerFactory? loggerFactory = null)
: this(apiKey, new Uri("https://api.pinecone.io"), loggerFactory)
: this(apiKey, Constants.BaseUrl, loggerFactory)
{
}

Expand All @@ -51,16 +51,22 @@ public PineconeClient(string apiKey, Uri baseUrl, ILoggerFactory? loggerFactory
/// <summary>
/// Creates a new instance of the <see cref="PineconeClient" /> class.
/// </summary>
/// <remarks>
/// If <see cref="HttpClient.BaseAddress" /> is not set, the default base address is used.
/// <para/>
/// The logger factory, if provided, will be used to instrument the <see cref="Index{TTransport}" /> objects
/// created by the client but will not apply to the specified <paramref name="client" /> instance.
/// </remarks>
/// <param name="apiKey">API key used to connect to Pinecone.</param>
/// <param name="client">HTTP client used to connect to Pinecone.</param>
/// <param name="loggerFactory">The logger factory to be used.</param>
public PineconeClient(string apiKey, HttpClient client, ILoggerFactory? loggerFactory = null)
{
ThrowHelpers.CheckNullOrWhiteSpace(apiKey);
ThrowHelpers.CheckNull(client);
ThrowHelpers.CheckNull(client.BaseAddress);

Http = client;
Http.BaseAddress ??= Constants.BaseUrl;
Http.AddPineconeHeaders(apiKey);
LoggerFactory = loggerFactory;
}
Expand Down

0 comments on commit beb28b7

Please sign in to comment.