Skip to content
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

Merged
merged 20 commits into from
Jul 9, 2024
Merged

Add docstrings for client.go #27

merged 20 commits into from
Jul 9, 2024

Conversation

aulorbe
Copy link
Contributor

@aulorbe aulorbe commented Jun 20, 2024

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

CI passes.

pinecone/client.go Outdated Show resolved Hide resolved
@aulorbe aulorbe changed the title Sample docstring for Client struct Add docstrings for client.go Jun 24, 2024
pinecone/client.go Outdated Show resolved Hide resolved
@aulorbe aulorbe marked this pull request as ready for review June 24, 2024 18:01
Copy link
Contributor

@austin-denoble austin-denoble left a 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. 🎉

// 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.
Copy link
Contributor

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:

Suggested change
// - 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:

c := Client{restClient: client, sourceTag: in.SourceTag, headers: in.Headers}

Comment on lines 20 to 22
// 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.
Copy link
Contributor

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.

// - 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.
Copy link
Contributor

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.

Suggested change
// - 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.

Comment on lines 30 to 33
// 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.
Copy link
Contributor

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:

Suggested change
// 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.

Comment on lines 49 to 55
// if err != nil {
// fmt.Println("Error:", err)
// }
//
// for _, idx := range idxs {
// fmt.Println(idx)
// }
Copy link
Contributor

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.

Comment on lines 231 to 233
// if err != nil {
// fmt.Println("Error:", err)
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Comment on lines 223 to 228
// }
//
// pc, err := pinecone.NewClient(clientParams)
// if err != nil {
// log.Fatalf("Failed to create Client: %v", err)
// }
Copy link
Contributor

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.

return c.IndexWithAdditionalMetadata(host, "", nil)
}

// IndexWithNamespace creates an IndexConnection to the specified host within the specified namespace.
Copy link
Contributor

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."?

Comment on lines 281 to 282
// IndexWithAdditionalMetadata creates an IndexConnection to the specified host within the specified namespace,
// with the addition of custom metadata fields.
Copy link
Contributor

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.

Comment on lines 298 to 314
// }
//
// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: More indentation woes 😬

Copy link
Contributor Author

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!

// - 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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

pinecone/client.go Outdated Show resolved Hide resolved
@aulorbe aulorbe force-pushed the Audrey/client-documentation branch from 763fe23 to 669951b Compare June 27, 2024 18:51
@aulorbe aulorbe force-pushed the Audrey/client-documentation branch from 8382f11 to f5c63d6 Compare June 28, 2024 22:12
Copy link
Contributor

@austin-denoble austin-denoble left a 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.

// 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.
Copy link
Contributor

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.

// log.Println("IndexConnection created successfully!")
// }
//
// [pinecone.io/docs]: https://docs.pinecone.io/reference/api/control-plane/list_indexes
Copy link
Contributor

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:

Suggested change
// [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.

Copy link
Contributor Author

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.

// 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.
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor Author

@aulorbe aulorbe Jul 9, 2024

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.
Copy link
Contributor

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.

Comment on lines 411 to 412
// - 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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// - 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.
Copy link
Contributor

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

Comment on lines +612 to +617
// Name: "my-serverless-index",
// Dimension: 3,
// Metric: pinecone.Cosine,
// Cloud: pinecone.Aws,
// Region: "us-east-1",
// },
Copy link
Contributor

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.

Comment on lines +520 to +526
// Name: "my-pod-index",
// Dimension: 3,
// Metric: pinecone.Cosine,
// Environment: "us-west1-gcp",
// PodType: "s1",
// MetadataConfig: podIndexMetadata,
// }
Copy link
Contributor

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.

@@ -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.
Copy link
Contributor

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"?

@aulorbe aulorbe merged commit 479d6c7 into main Jul 9, 2024
3 checks passed
@aulorbe aulorbe deleted the Audrey/client-documentation branch July 9, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants