Skip to content

Conversation

@koic
Copy link

@koic koic commented May 9, 2025

Resolves #30.

Summary

To use the Chroma v2 API, Chroma version 0.6.3 or later is required. The v1 API has already been deprecated and is therefore not supported by this chroma-db gem: chroma-core/chroma#3498

This PR includes the following changes:

Existing API

Chroma v2 API URLs are updated to include tenants/#{tenant}/databases/{database}. For compatibility, the Ruby interfaces for Chroma::Resources::Database and Chroma::Resources::Collection remain unchanged.

New API

The following APIs have been added. As these are new APIs, they should not affect the existing ones. The corresponding Ruby implementation methods for each endpoint URL are as follows.

GET /auth/identity

  • Chroma::Resources::Database.auth_identity

GET /healthcheck

  • Chroma::Resources::Database.healthcheck

GET /pre-flight-checks

  • Chroma::Resources::Database.pre_flight_checks

POST /tenants/#{tenant}/databases/#{database}/collections_count

Both an instance method on Database and a class method on Database are provided to retrieve the number of Collections. The latter follows the value set in Chroma.database (default is default_database).

  • Chroma::Resources::Database#collections_count
  • Chroma::Resources::Collection.collections_count

Tenant, Database, and Collection have a parent-child relationship as shown.

Two experimental APIs are currently provided for this functionality, and if the interface useful, the same pattern can be applied to other APIs as well.

Alternatively, if only one approach is sufficient, either can be removed, please feel free to suggest which.

POST /tenants/#{tenant}/databases/#{database}/collections/#{collection_id}/fork

  • Chroma::Resources::Collection#fork

POST /api/v2/tenants

  • Chroma::Resources::Tenant.create(name)

GET /api/v2/tenants/#{tenant}

  • Chroma::Resources::Tenant.get(name)

GET /api/v2/tenants/#{tenant}/databases

  • Chroma::Resources::Database.list

POST /api/v2/tenants/#{tenant}/databases

  • Chroma::Resources::Database.create(name)

GET /api/v2/tenants/#{tenant}/databases/#{database}

  • Chroma::Resources::Database.get(name)

DELETE /api/v2/tenants/#{tenant}/databases/#{database}

  • Chroma::Resources::Database.delete(name)

Additional Information

This PR adds support for the Chroma v2 API in a backward-compatible manner. It may be possible to design a better Ruby API that more explicitly reflects the parent-child relationship between Tenant, Database, and Collection, but such improvements can be explored in a furure step, after ensuring compatibility.

Note that compatibility here refers only to usage of the Ruby API. As noted in the addition to README.md, the Chroma database itself requires version 0.6.3 or higher, which supports Chroma v2 API.

Resolves mariochavez#30.

## Summary

To use the Chroma v2 API, Chroma version 0.6.3 or later is required.
The v1 API has already been deprecated and is therefore not supported by this chroma-db gem:
chroma-core/chroma#3498

This PR includes the following changes:

## Existing API

Chroma v2 API URLs are updated to include `tenants/#{tenant}/databases/{database}`.
For compatibility, the Ruby interfaces for `Chroma::Resources::Database` and `Chroma::Resources::Collection` remain unchanged.

## New API

The following APIs have been added. As these are new APIs, they should not affect the existing ones.
The corresponding Ruby implementation methods for each endpoint URL are as follows.

### GET /auth/identity

- `Chroma::Resources::Database.auth_identity`

### GET /healthcheck

- `Chroma::Resources::Database.healthcheck`

### GET /pre-flight-checks

- `Chroma::Resources::Database.pre_flight_checks`

###  POST /tenants/#{tenant}/databases/#{database}/collections_count

Both an instance method on `Database` and a class method on `Database` are provided to retrieve the number of `Collection`s.
The latter follows the value set in `Chroma.database` (default is `default_database`).

- `Chroma::Resources::Database#collections_count`
- `Chroma::Resources::Collection.collections_count`

`Tenant`, `Database`, and `Collection` have a parent-child relationship as shown.

Two experimental APIs are currently provided for this functionality, and if the interface useful,
the same pattern can be applied to other APIs as well.

Alternatively, if only one approach is sufficient, either can be removed, please feel free to suggest which.

### POST /tenants/#{tenant}/databases/#{database}/collections/#{collection_id}/fork

- `Chroma::Resources::Collection#fork`

### POST /api/v2/tenants

- `Chroma::Resources::Tenant.create(name)`

### GET /api/v2/tenants/#{tenant}

- `Chroma::Resources::Tenant.get(name)`

### GET /api/v2/tenants/#{tenant}/databases

- `Chroma::Resources::Database.list`

### POST /api/v2/tenants/#{tenant}/databases

- `Chroma::Resources::Database.create(name)`

### GET /api/v2/tenants/#{tenant}/databases/#{database}

- `Chroma::Resources::Database.get(name)`

### DELETE /api/v2/tenants/#{tenant}/databases/#{database}

- `Chroma::Resources::Database.delete(name)`

## Additional Information

This PR adds support for the Chroma v2 API in a backward-compatible manner.
It may be possible to design a better Ruby API that more explicitly reflects
the parent-child relationship between `Tenant`, `Database`, and `Collection`,
but such improvements can be explored in a furure step, after ensuring compatibility.

Note that compatibility here refers only to usage of the Ruby API.
As noted in the addition to README.md, the Chroma database itself requires version 0.6.3 or higher,
which supports Chroma v2 API.
@koic koic force-pushed the support_chroma_v2_api branch from fc241da to c457cb0 Compare May 9, 2025 08:53
@Samsinite
Copy link

@mariochavez thoughts?

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.

Bump to v2 API

2 participants