Skip to content
Merged
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
16 changes: 12 additions & 4 deletions clients/new-js/packages/chromadb/src/cloud-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class CloudClient extends ChromaClient {
args: Partial<{
/** API key for authentication (or set CHROMA_API_KEY env var) */
apiKey?: string;
/** Host address of the Chroma cloud server. Defaults to 'api.trychroma.com' */
host?: string;
/** Port number of the Chroma cloud server. Defaults to 443 */
port?: number;
/** Tenant name for multi-tenant deployments */
tenant?: string;
/** Database name to connect to */
Expand All @@ -35,8 +39,8 @@ export class CloudClient extends ChromaClient {
const database = args.database || process.env.CHROMA_DATABASE;

super({
host: "api.trychroma.com",
port: 8000,
host: args.host || "api.trychroma.com",
port: args.port || 443,
ssl: true,
tenant,
database,
Expand All @@ -63,6 +67,10 @@ export class AdminCloudClient extends AdminClient {
args: Partial<{
/** API key for authentication (or set CHROMA_API_KEY env var) */
apiKey?: string;
/** Host address of the Chroma cloud server. Defaults to 'api.trychroma.com' */
host?: string;
/** Port number of the Chroma cloud server. Defaults to 443 */
port?: number;
/** Additional fetch options for HTTP requests */
fetchOptions?: RequestInit;
}> = {},
Comment on lines 67 to 76
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommended

[Maintainability] To improve maintainability and reduce code duplication, consider defining a shared interface for the cloud client constructor arguments. Both CloudClient and AdminCloudClient now share several configuration options (apiKey, host, port, fetchOptions).

You could create a base interface for these common options and then extend it for CloudClient, which has additional properties.

For example:

interface BaseCloudClientArgs {
  /** API key for authentication (or set CHROMA_API_KEY env var) */
  apiKey?: string;
  /** Host address of the Chroma cloud server. Defaults to 'api.trychroma.com' */
  host?: string;
  /** Port number of the Chroma cloud server. Defaults to 443 */
  port?: number;
  /** Additional fetch options for HTTP requests */
  fetchOptions?: RequestInit;
}

interface CloudClientArgs extends BaseCloudClientArgs {
  /** Tenant name for multi-tenant deployments */
  tenant?: string;
  /** Database name to connect to */
  database?: string;
}

This would allow you to use Partial<CloudClientArgs> and Partial<BaseCloudClientArgs> in the respective constructors, making the code more DRY.

Context for Agents
To improve maintainability and reduce code duplication, consider defining a shared interface for the cloud client constructor arguments. Both `CloudClient` and `AdminCloudClient` now share several configuration options (`apiKey`, `host`, `port`, `fetchOptions`).

You could create a base interface for these common options and then extend it for `CloudClient`, which has additional properties.

For example:
```typescript
interface BaseCloudClientArgs {
  /** API key for authentication (or set CHROMA_API_KEY env var) */
  apiKey?: string;
  /** Host address of the Chroma cloud server. Defaults to 'api.trychroma.com' */
  host?: string;
  /** Port number of the Chroma cloud server. Defaults to 443 */
  port?: number;
  /** Additional fetch options for HTTP requests */
  fetchOptions?: RequestInit;
}

interface CloudClientArgs extends BaseCloudClientArgs {
  /** Tenant name for multi-tenant deployments */
  tenant?: string;
  /** Database name to connect to */
  database?: string;
}
```

This would allow you to use `Partial<CloudClientArgs>` and `Partial<BaseCloudClientArgs>` in the respective constructors, making the code more DRY.

File: clients/new-js/packages/chromadb/src/cloud-client.ts
Line: 76

Expand All @@ -75,8 +83,8 @@ export class AdminCloudClient extends AdminClient {
}

super({
host: "api.trychroma.com",
port: 8000,
host: args.host || "api.trychroma.com",
port: args.port || 443,
ssl: true,
headers: { "x-chroma-token": apiKey },
fetchOptions: args.fetchOptions,
Expand Down
Loading