-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docstrings for client.go #27
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work getting all of these doc comments written, there was a lot of ground to cover here.
Overall I think the formatting is solid, nice job. I've been reviewing and learning more as I go from https://tip.golang.org/doc/comment.
Most of my feedback is around the NewClient
and NewClientBase
functions and the associated NewClientParams
and NewClientBaseParams
structs, since that's a lot of how folks will configure and work with `Client.
There's a lot of nit formatting and indentation feedback in here too, I was seeing things across the board so tried to leave limited comments for now. I can take another pass when you're ready, but this is looking solid so far. 🎉
pinecone/client.go
Outdated
// The Client is designed to be long-lived and reused across multiple operations. | ||
// | ||
// Fields: | ||
// - headers: A map of additional HTTP headers to include in the API request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We may want to be explicit here:
// - headers: A map of additional HTTP headers to include in the API request. | |
// - headers: An optional map of additional HTTP headers to include in each API request to the control plane. Provided through NewClientParams.Headers or NewClientBaseParams.Headers.. |
godoc
should automatically link to NewClientParams.Headers
. I've also realized this represents what ends up in this field currently, but maybe we'd want to change it at some point to reflect what is actually sent through on requests via clientOptions
as opposed to only what's passed:
go-pinecone/pinecone/client.go
Line 79 in 3278f6d
c := Client{restClient: client, sourceTag: in.SourceTag, headers: in.Headers} |
pinecone/client.go
Outdated
// It encapsulates the necessary authentication, request creation, and response handling for the API's operations. | ||
// | ||
// The Client is designed to be long-lived and reused across multiple operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this needs to be its own line, could it just be part of the first couple sentences / paragraph?
Also, do you think it makes sense to add another paragraph here around using NewClient
or NewClientBase
to instantiate the Client
struct rather than directly? I just want to be clear and explicit about how the structs and functions in the package are used, and we do a lot of the lifting for them.
pinecone/client.go
Outdated
// - headers: A map of additional HTTP headers to include in the API request. | ||
// - restClient: The underlying REST client used to communicate with the Pinecone control plane API. | ||
// This field is internal and managed by Client. | ||
// - sourceTag: An optional string used to help Pinecone attribute API activity to our partners. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Drop the "our" here? Just sounds a bit formal. Also we can link to the relevant fields in the NewClient*
structs.
// - sourceTag: An optional string used to help Pinecone attribute API activity to our partners. | |
// - sourceTag: An optional string used to help Pinecone attribute API activity to partners. Provided through NewClientParams.SourceTag or NewClientBaseParams.SourceTag. |
pinecone/client.go
Outdated
// To use Client, first build the parameters of your request using NewClientParams, | ||
// providing your API key. Then pass those parameters into the NewClient function to create a new Client. | ||
// Once instantiated, you can call Client's methods to perform actions such as creating, deleting, | ||
// and describing indexes and collections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd maybe word things like this here:
// To use Client, first build the parameters of your request using NewClientParams, | |
// providing your API key. Then pass those parameters into the NewClient function to create a new Client. | |
// Once instantiated, you can call Client's methods to perform actions such as creating, deleting, | |
// and describing indexes and collections. | |
// To create a Client instance, use the NewClient function with an instance of NewClientParams to pass | |
// configuration options such as providing your API key. Once instantiated, you can call Client's methods | |
// to perform actions such as creating, deleting, and describing indexes and collections. |
While we use the configuration parameters in requests, they're not really instantiating a Client
on a per-request basis.
pinecone/client.go
Outdated
// if err != nil { | ||
// fmt.Println("Error:", err) | ||
// } | ||
// | ||
// for _, idx := range idxs { | ||
// fmt.Println(idx) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the code should be indented here, should align with the idxs, err
line.
pinecone/client.go
Outdated
// if err != nil { | ||
// fmt.Println("Error:", err) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
pinecone/client.go
Outdated
// } | ||
// | ||
// pc, err := pinecone.NewClient(clientParams) | ||
// if err != nil { | ||
// log.Fatalf("Failed to create Client: %v", err) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Is it just me or are these closing brackets indented one space? I keep thinking I'm seeing indentation problems but it's hard to tell.
pinecone/client.go
Outdated
return c.IndexWithAdditionalMetadata(host, "", nil) | ||
} | ||
|
||
// IndexWithNamespace creates an IndexConnection to the specified host within the specified namespace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add "If namespace is not explicitly provided the default of "" will be used."?
pinecone/client.go
Outdated
// IndexWithAdditionalMetadata creates an IndexConnection to the specified host within the specified namespace, | ||
// with the addition of custom metadata fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additionalMetadata
can be thought of analogous to Headers
in the NewClient
function. They're metadata that's applied to each RPC request to the server: https://grpc.io/docs/guides/metadata/. I think we could be explicit about that here, and maybe even link to some of the supporting gRPC documentation.
pinecone/client.go
Outdated
// } | ||
// | ||
// pc, err := pinecone.NewClient(clientParams) | ||
// if err != nil { | ||
// log.Fatalf("Failed to create Client: %v", err) | ||
// } | ||
// | ||
// idxs, err := pc.ListIndexes(ctx) | ||
// if err != nil { | ||
// fmt.Println("Error:", err) | ||
// } | ||
// | ||
// idx, err := pc.IndexWithAdditionalMetadata( | ||
// idxs[0].Host, | ||
// <"sample-namespace">, | ||
// map[string]string{"custom-request-metadata": "custom-metadata-values"} | ||
// ) // You can now use idx to interact with your index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: More indentation woes 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah my linter doesn't do indentation for comments. Sorry about that!
pinecone/client.go
Outdated
// - Shards: The number of shards to use for the index (defaults to 1). | ||
// - Replicas: The number of replicas to use for the index (defaults to 1). | ||
// - SourceCollection: The Collection from which to create the index. | ||
// - MetadataConfig: The metadata configuration for the index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to include metadata config in the example below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
763fe23
to
669951b
Compare
This reverts commit bfc0d2f.
8382f11
to
f5c63d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Nice work! This looks great, I think we're good to go ahead and merge whenever you're ready. Thanks again for taking all these doc comments on and being so good about iterating and feedback.
Some questions, nits, etc here. I don't think there's anything necessarily blocking though.
pinecone/client.go
Outdated
// Fields: | ||
// - headers: An optional map of additional HTTP headers to include in each API request to the control plane, | ||
// provided through NewClientParams.Headers or NewClientBaseParams.Headers. | ||
// - restClient: The underlying REST client used to communicate with the Pinecone control plane API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could mention the NewClientParams.RestClient
/ NewClientBaseParams.RestClient
like the other values here. Also that it specifically accepts an *http.Client
, and that this is optional and we create the client for you if it isn't provided.
pinecone/client.go
Outdated
// log.Println("IndexConnection created successfully!") | ||
// } | ||
// | ||
// [pinecone.io/docs]: https://docs.pinecone.io/reference/api/control-plane/list_indexes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should the rendered string for this link be:
// [pinecone.io/docs]: https://docs.pinecone.io/reference/api/control-plane/list_indexes | |
// [docs.pinecone.io/reference/api]: https://docs.pinecone.io/reference/api/control-plane/list_indexes |
idk, maybe you were trying to keep it shorter, but it feels like it should align with the underlying URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was just trying to keep it short. Maybe I'll just hyperlink plain text instead of the shortened URL.
pinecone/client.go
Outdated
// NewClientParams holds the parameters for creating a new Client instance while authenticating via an API key. | ||
// | ||
// Fields: | ||
// - ApiKey: The API key used to authenticate with the Pinecone control plane API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would mention that ApiKey
is the only required field here, and that it must be provided unless you're providing it through the environment variable PINECONE_API_KEY
, in which case it's not required here. If the API key is not provided when creating a new Client instance, you'll receive an error
.
Something like that.
// This function sets up the control plane client with the necessary configuration for authentication and communication. | ||
// | ||
// Parameters: | ||
// - in: A NewClientParams object. See NewClientParams for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious - does godoc automatically find the references for these if we're referring to functions or types within the same package, or do we have to link to things manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my IDE rendering, they're auto-found
@@ -59,6 +151,34 @@ func NewClient(in NewClientParams) (*Client, error) { | |||
return NewClientBase(NewClientBaseParams{Headers: clientHeaders, Host: in.Host, RestClient: in.RestClient, SourceTag: in.SourceTag}) | |||
} | |||
|
|||
// NewClientBase creates and initializes a new instance of Client with custom authentication headers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Might be nice to add something like "ApiKey is required when using NewClient, but is not required when using NewClientBase"? That wording feels bad, but just something to stress the "Base" impl requires you to build your own auth a bit more directly.
pinecone/client.go
Outdated
// - Shards: The number of shards to use for the index (defaults to 1). | ||
// - Replicas: The number of [replicas] to use for the index (defaults to 1). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along with my previous comments, I'd take a look at how we represent some of these fields in the OAS documentation and lift that, just for specificity:
replicas
: https://github.com/pinecone-io/apis/blob/fbd9d8d48c95b12c6b28aea4e496b6f28666d2d1/src/release/control/resources/indexes/models/PodSpecReplicas.yaml#L3shards
: https://github.com/pinecone-io/apis/blob/fbd9d8d48c95b12c6b28aea4e496b6f28666d2d1/src/release/control/resources/indexes/models/PodSpecShards.yaml#L3
etc
pinecone/client.go
Outdated
// - Name: The name of the Serverless index. | ||
// - Dimension: The dimension of the index (must match dimensionality of upserted vectors). | ||
// - Metric: The metric used to measure the [similarity] between vectors. | ||
// - Cloud: The [cloud provider] in which the index will be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same feedback regarding the other index fields in the pods-based approach, maybe add a bit more specificity. You can pull directly from the OAS spec: https://github.com/pinecone-io/apis/blob/fbd9d8d48c95b12c6b28aea4e496b6f28666d2d1/src/release/control/resources/indexes/models/ServerlessSpec.yaml#L14
// Name: "my-serverless-index", | ||
// Dimension: 3, | ||
// Metric: pinecone.Cosine, | ||
// Cloud: pinecone.Aws, | ||
// Region: "us-east-1", | ||
// }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think these fields need to be inset just a bit.
// Name: "my-pod-index", | ||
// Dimension: 3, | ||
// Metric: pinecone.Cosine, | ||
// Environment: "us-west1-gcp", | ||
// PodType: "s1", | ||
// MetadataConfig: podIndexMetadata, | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Inset fields a bit.
pinecone/client.go
Outdated
@@ -273,6 +790,47 @@ func (c *Client) DeleteIndex(ctx context.Context, idxName string) error { | |||
return nil | |||
} | |||
|
|||
// ListCollections retrieves a list of all collections in a Pinecone [project]. See Collection for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does "See Collection" here needs []
around "Collection"?
Problem
We do not have docstrings in the public types, functions, and methods in
client.go
.Asana ticket: https://app.asana.com/0/1203260648987893/1207208972408364/f
Solution
Add docstrings!
Type of Change
Test Plan
CI passes.