chromadb 3.3.3 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,6 +54,7 @@ __export(src_exports, {
54
54
  CloudClient: () => CloudClient,
55
55
  Cmek: () => Cmek,
56
56
  CmekProvider: () => CmekProvider,
57
+ CollectionHandle: () => CollectionHandle,
57
58
  DOCUMENT_KEY: () => DOCUMENT_KEY,
58
59
  Div: () => Div,
59
60
  EMBEDDING_KEY: () => EMBEDDING_KEY,
@@ -627,6 +628,22 @@ var CollectionService = class {
627
628
  }
628
629
  });
629
630
  }
631
+ /**
632
+ * Get fork count
633
+ * Returns the number of forks for a collection.
634
+ */
635
+ static forkCount(options) {
636
+ return (options.client ?? client).get({
637
+ security: [
638
+ {
639
+ name: "x-chroma-token",
640
+ type: "apiKey"
641
+ }
642
+ ],
643
+ url: "/api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/fork_count",
644
+ ...options
645
+ });
646
+ }
630
647
  /**
631
648
  * Get number of collections
632
649
  * Returns the total number of collections in a database.
@@ -4539,6 +4556,13 @@ var CollectionImpl = class _CollectionImpl {
4539
4556
  configuration: data.configuration_json
4540
4557
  });
4541
4558
  }
4559
+ async forkCount() {
4560
+ const { data } = await CollectionService.forkCount({
4561
+ client: this.apiClient,
4562
+ path: await this.path()
4563
+ });
4564
+ return data.count;
4565
+ }
4542
4566
  async update({
4543
4567
  ids,
4544
4568
  embeddings,
@@ -4625,6 +4649,75 @@ var CollectionImpl = class _CollectionImpl {
4625
4649
  return data;
4626
4650
  }
4627
4651
  };
4652
+ var HANDLE_EMBEDDING_ERROR = "This operation requires an embedding function, which is not available on a collection obtained via client.collection(id). Provide pre-computed embeddings directly, or use client.getCollection() to get a full collection with embedding support.";
4653
+ var HANDLE_NOT_SUPPORTED_ERROR = "is not supported on a collection obtained via client.collection(id). Use client.getCollection() to get a full collection instance.";
4654
+ var CollectionHandle = class extends CollectionImpl {
4655
+ constructor({ chromaClient, apiClient, id, tenant, database }) {
4656
+ super({
4657
+ chromaClient,
4658
+ apiClient,
4659
+ id,
4660
+ tenant,
4661
+ database,
4662
+ name: "",
4663
+ configuration: {}
4664
+ });
4665
+ }
4666
+ async add(args) {
4667
+ if (!args.embeddings) {
4668
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4669
+ }
4670
+ return super.add(args);
4671
+ }
4672
+ async update(args) {
4673
+ if (!args.embeddings && args.documents) {
4674
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4675
+ }
4676
+ return super.update(args);
4677
+ }
4678
+ async upsert(args) {
4679
+ if (!args.embeddings) {
4680
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4681
+ }
4682
+ return super.upsert(args);
4683
+ }
4684
+ async query(args) {
4685
+ if (!args.queryEmbeddings) {
4686
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4687
+ }
4688
+ return super.query(args);
4689
+ }
4690
+ async search(searches, options) {
4691
+ const items = Array.isArray(searches) ? searches : [searches];
4692
+ for (const search of items) {
4693
+ const payload = toSearch(search).toPayload();
4694
+ if (this.hasStringKnnQuery(payload.rank)) {
4695
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4696
+ }
4697
+ }
4698
+ return super.search(searches, options);
4699
+ }
4700
+ async modify(_args) {
4701
+ throw new ChromaValueError(`modify() ${HANDLE_NOT_SUPPORTED_ERROR}`);
4702
+ }
4703
+ async fork(_args) {
4704
+ throw new ChromaValueError(`fork() ${HANDLE_NOT_SUPPORTED_ERROR}`);
4705
+ }
4706
+ hasStringKnnQuery(obj) {
4707
+ if (!obj || typeof obj !== "object") return false;
4708
+ if (Array.isArray(obj)) {
4709
+ return obj.some((item) => this.hasStringKnnQuery(item));
4710
+ }
4711
+ const record = obj;
4712
+ if ("$knn" in record && isPlainObject(record.$knn)) {
4713
+ const knn = record.$knn;
4714
+ if (typeof knn.query === "string") return true;
4715
+ }
4716
+ return Object.values(record).some(
4717
+ (value) => this.hasStringKnnQuery(value)
4718
+ );
4719
+ }
4720
+ };
4628
4721
 
4629
4722
  // src/next.ts
4630
4723
  function withChroma(userNextConfig = {}) {
@@ -5211,6 +5304,30 @@ var ChromaClient = class {
5211
5304
  schema: serverSchema
5212
5305
  });
5213
5306
  }
5307
+ /**
5308
+ * Returns a lightweight collection handle for the given collection ID.
5309
+ * The handle supports operations that don't require an embedding function
5310
+ * or schema (e.g., add with pre-computed embeddings, get, delete, count, search).
5311
+ * Operations that require an embedding function will throw a clear error
5312
+ * directing you to use {@link getCollection} instead.
5313
+ * @param id - The collection ID
5314
+ * @returns A Collection handle for the given ID
5315
+ * @throws ChromaValueError if tenant or database are not set on the client
5316
+ */
5317
+ collection(id) {
5318
+ if (!this._tenant || !this._database) {
5319
+ throw new ChromaValueError(
5320
+ "tenant and database must be set on the client before calling collection(). Provide them in the ChromaClient constructor or use getCollection() instead."
5321
+ );
5322
+ }
5323
+ return new CollectionHandle({
5324
+ chromaClient: this,
5325
+ apiClient: this.apiClient,
5326
+ id,
5327
+ tenant: this._tenant,
5328
+ database: this._database
5329
+ });
5330
+ }
5214
5331
  /**
5215
5332
  * Deletes a collection and all its data.
5216
5333
  * @param options - Deletion options
@@ -5348,6 +5465,7 @@ var AdminCloudClient = class extends AdminClient {
5348
5465
  CloudClient,
5349
5466
  Cmek,
5350
5467
  CmekProvider,
5468
+ CollectionHandle,
5351
5469
  DOCUMENT_KEY,
5352
5470
  Div,
5353
5471
  EMBEDDING_KEY,