chromadb 3.3.2 → 3.4.0

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.
package/dist/chromadb.mjs CHANGED
@@ -508,6 +508,22 @@ var CollectionService = class {
508
508
  }
509
509
  });
510
510
  }
511
+ /**
512
+ * Get fork count
513
+ * Returns the number of forks for a collection.
514
+ */
515
+ static forkCount(options) {
516
+ return (options.client ?? client).get({
517
+ security: [
518
+ {
519
+ name: "x-chroma-token",
520
+ type: "apiKey"
521
+ }
522
+ ],
523
+ url: "/api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/fork_count",
524
+ ...options
525
+ });
526
+ }
511
527
  /**
512
528
  * Get number of collections
513
529
  * Returns the total number of collections in a database.
@@ -1516,7 +1532,9 @@ var pythonEmbeddingFunctions = {
1516
1532
  default: "default-embed",
1517
1533
  together_ai: "together-ai",
1518
1534
  sentence_transformer: "sentence-transformer",
1535
+ google_gemini: "google-gemini",
1519
1536
  google_genai: "google-gemini"
1537
+ // Backward compatibility alias
1520
1538
  };
1521
1539
  var unsupportedEmbeddingFunctions = /* @__PURE__ */ new Set([
1522
1540
  "amazon_bedrock",
@@ -1555,32 +1573,11 @@ var registerSparseEmbeddingFunction = (name, fn) => {
1555
1573
  knownSparseEmbeddingFunctions.set(name, fn);
1556
1574
  };
1557
1575
  var getEmbeddingFunction = async (args) => {
1558
- const { collectionName, client: client2, efConfig } = args;
1559
- if (!efConfig) {
1560
- console.warn(
1561
- `No embedding function configuration found for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
1562
- );
1563
- return void 0;
1564
- }
1565
- if (efConfig.type === "legacy") {
1566
- console.warn(
1567
- `No embedding function configuration found for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
1568
- );
1569
- return void 0;
1570
- }
1571
- if (efConfig.type === "unknown") {
1572
- console.warn(
1573
- `Unknown embedding function configuration for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
1574
- );
1575
- return void 0;
1576
- }
1577
- if (efConfig.type !== "known") {
1576
+ const { client: client2, efConfig } = args;
1577
+ if (efConfig?.type !== "known") {
1578
1578
  return void 0;
1579
1579
  }
1580
1580
  if (unsupportedEmbeddingFunctions.has(efConfig.name)) {
1581
- console.warn(
1582
- `Embedding function ${efConfig.name} is not supported in the JS/TS SDK. 'add' and 'query' will fail unless you provide them embeddings directly.`
1583
- );
1584
1581
  return void 0;
1585
1582
  }
1586
1583
  const packageName = pythonEmbeddingFunctions[efConfig.name] || efConfig.name;
@@ -1596,42 +1593,24 @@ var getEmbeddingFunction = async (args) => {
1596
1593
  } catch (error) {
1597
1594
  }
1598
1595
  if (!embeddingFunction) {
1599
- console.warn(
1600
- `Collection ${collectionName} was created with the ${packageName} embedding function. However, the @chroma-core/${packageName} package is not installed. 'add' and 'query' will fail unless you provide them embeddings directly, or install the @chroma-core/${packageName} package.`
1601
- );
1602
1596
  return void 0;
1603
1597
  }
1604
1598
  }
1605
- let constructorConfig = efConfig.type === "known" ? efConfig.config : {};
1599
+ const constructorConfig = efConfig.config ?? {};
1606
1600
  try {
1607
1601
  if (embeddingFunction.buildFromConfig) {
1608
1602
  return embeddingFunction.buildFromConfig(constructorConfig, client2);
1609
1603
  }
1610
- console.warn(
1611
- `Embedding function ${packageName} does not define a 'buildFromConfig' function. 'add' and 'query' will fail unless you provide them embeddings directly.`
1612
- );
1613
1604
  return void 0;
1614
1605
  } catch (e) {
1615
- console.warn(
1616
- `Embedding function ${packageName} failed to build with config: ${constructorConfig}. 'add' and 'query' will fail unless you provide them embeddings directly. Error: ${e}`
1617
- );
1618
1606
  return void 0;
1619
1607
  }
1620
1608
  };
1621
- var getSparseEmbeddingFunction = async (collectionName, client2, efConfig) => {
1622
- if (!efConfig) {
1623
- return void 0;
1624
- }
1625
- if (efConfig.type === "legacy") {
1626
- return void 0;
1627
- }
1628
- if (efConfig.type !== "known") {
1609
+ var getSparseEmbeddingFunction = async (client2, efConfig) => {
1610
+ if (efConfig?.type !== "known") {
1629
1611
  return void 0;
1630
1612
  }
1631
1613
  if (unsupportedSparseEmbeddingFunctions.has(efConfig.name)) {
1632
- console.warn(
1633
- "Embedding function ${efConfig.name} is not supported in the JS/TS SDK. 'add' and 'query' will fail unless you provide them embeddings directly."
1634
- );
1635
1614
  return void 0;
1636
1615
  }
1637
1616
  const packageName = pythonSparseEmbeddingFunctions[efConfig.name] || efConfig.name;
@@ -1644,25 +1623,16 @@ var getSparseEmbeddingFunction = async (collectionName, client2, efConfig) => {
1644
1623
  } catch (error) {
1645
1624
  }
1646
1625
  if (!sparseEmbeddingFunction) {
1647
- console.warn(
1648
- `Collection ${collectionName} was created with the ${packageName} sparse embedding function. However, the @chroma-core/${packageName} package is not installed.`
1649
- );
1650
1626
  return void 0;
1651
1627
  }
1652
1628
  }
1653
- let constructorConfig = efConfig.type === "known" ? efConfig.config : {};
1629
+ const constructorConfig = efConfig.config ?? {};
1654
1630
  try {
1655
1631
  if (sparseEmbeddingFunction.buildFromConfig) {
1656
1632
  return sparseEmbeddingFunction.buildFromConfig(constructorConfig, client2);
1657
1633
  }
1658
- console.warn(
1659
- `Sparse embedding function ${packageName} does not define a 'buildFromConfig' function.`
1660
- );
1661
1634
  return void 0;
1662
1635
  } catch (e) {
1663
- console.warn(
1664
- `Sparse embedding function ${packageName} failed to build with config: ${constructorConfig}. Error: ${e}`
1665
- );
1666
1636
  return void 0;
1667
1637
  }
1668
1638
  };
@@ -1788,7 +1758,6 @@ var processUpdateCollectionConfig = async ({
1788
1758
  );
1789
1759
  }
1790
1760
  const embeddingFunction = currentEmbeddingFunction || await getEmbeddingFunction({
1791
- collectionName,
1792
1761
  client: client2,
1793
1762
  efConfig: currentConfiguration.embeddingFunction ?? void 0
1794
1763
  });
@@ -3886,7 +3855,6 @@ var Schema = class _Schema {
3886
3855
  spann: json.spann ? cloneObject(json.spann) : null
3887
3856
  });
3888
3857
  config.embeddingFunction = await getEmbeddingFunction({
3889
- collectionName: "schema deserialization",
3890
3858
  client: client2,
3891
3859
  efConfig: json.embedding_function
3892
3860
  });
@@ -3901,7 +3869,6 @@ var Schema = class _Schema {
3901
3869
  bm25: typeof json.bm25 === "boolean" ? json.bm25 : null
3902
3870
  });
3903
3871
  const embeddingFunction = await getSparseEmbeddingFunction(
3904
- "schema deserialization",
3905
3872
  client2,
3906
3873
  json.embedding_function
3907
3874
  ) ?? config.embeddingFunction ?? void 0;
@@ -3987,7 +3954,7 @@ var CollectionImpl = class _CollectionImpl {
3987
3954
  const embeddingFunction = this._embeddingFunction ?? this.getSchemaEmbeddingFunction();
3988
3955
  if (!embeddingFunction) {
3989
3956
  throw new ChromaValueError(
3990
- "Embedding function must be defined for operations requiring embeddings."
3957
+ `No embedding function found for collection '${this._name}'. You can either provide embeddings directly, or ensure the appropriate embedding function package (e.g. @chroma-core/default-embed) is installed.`
3991
3958
  );
3992
3959
  }
3993
3960
  if (isQuery && embeddingFunction.generateForQueries) {
@@ -4048,10 +4015,8 @@ var CollectionImpl = class _CollectionImpl {
4048
4015
  }
4049
4016
  if (index < documentsList.length) {
4050
4017
  const doc = documentsList[index];
4051
- if (typeof doc === "string") {
4052
- inputs.push(doc);
4053
- positions.push(index);
4054
- }
4018
+ inputs.push(doc);
4019
+ positions.push(index);
4055
4020
  }
4056
4021
  });
4057
4022
  if (inputs.length === 0) {
@@ -4471,6 +4436,13 @@ var CollectionImpl = class _CollectionImpl {
4471
4436
  configuration: data.configuration_json
4472
4437
  });
4473
4438
  }
4439
+ async forkCount() {
4440
+ const { data } = await CollectionService.forkCount({
4441
+ client: this.apiClient,
4442
+ path: await this.path()
4443
+ });
4444
+ return data.count;
4445
+ }
4474
4446
  async update({
4475
4447
  ids,
4476
4448
  embeddings,
@@ -4557,6 +4529,75 @@ var CollectionImpl = class _CollectionImpl {
4557
4529
  return data;
4558
4530
  }
4559
4531
  };
4532
+ 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.";
4533
+ 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.";
4534
+ var CollectionHandle = class extends CollectionImpl {
4535
+ constructor({ chromaClient, apiClient, id, tenant, database }) {
4536
+ super({
4537
+ chromaClient,
4538
+ apiClient,
4539
+ id,
4540
+ tenant,
4541
+ database,
4542
+ name: "",
4543
+ configuration: {}
4544
+ });
4545
+ }
4546
+ async add(args) {
4547
+ if (!args.embeddings) {
4548
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4549
+ }
4550
+ return super.add(args);
4551
+ }
4552
+ async update(args) {
4553
+ if (!args.embeddings && args.documents) {
4554
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4555
+ }
4556
+ return super.update(args);
4557
+ }
4558
+ async upsert(args) {
4559
+ if (!args.embeddings) {
4560
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4561
+ }
4562
+ return super.upsert(args);
4563
+ }
4564
+ async query(args) {
4565
+ if (!args.queryEmbeddings) {
4566
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4567
+ }
4568
+ return super.query(args);
4569
+ }
4570
+ async search(searches, options) {
4571
+ const items = Array.isArray(searches) ? searches : [searches];
4572
+ for (const search of items) {
4573
+ const payload = toSearch(search).toPayload();
4574
+ if (this.hasStringKnnQuery(payload.rank)) {
4575
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
4576
+ }
4577
+ }
4578
+ return super.search(searches, options);
4579
+ }
4580
+ async modify(_args) {
4581
+ throw new ChromaValueError(`modify() ${HANDLE_NOT_SUPPORTED_ERROR}`);
4582
+ }
4583
+ async fork(_args) {
4584
+ throw new ChromaValueError(`fork() ${HANDLE_NOT_SUPPORTED_ERROR}`);
4585
+ }
4586
+ hasStringKnnQuery(obj) {
4587
+ if (!obj || typeof obj !== "object") return false;
4588
+ if (Array.isArray(obj)) {
4589
+ return obj.some((item) => this.hasStringKnnQuery(item));
4590
+ }
4591
+ const record = obj;
4592
+ if ("$knn" in record && isPlainObject(record.$knn)) {
4593
+ const knn = record.$knn;
4594
+ if (typeof knn.query === "string") return true;
4595
+ }
4596
+ return Object.values(record).some(
4597
+ (value) => this.hasStringKnnQuery(value)
4598
+ );
4599
+ }
4600
+ };
4560
4601
 
4561
4602
  // src/next.ts
4562
4603
  function withChroma(userNextConfig = {}) {
@@ -4918,7 +4959,6 @@ var ChromaClient = class {
4918
4959
  );
4919
4960
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
4920
4961
  const resolvedEmbeddingFunction = await getEmbeddingFunction({
4921
- collectionName: collection.name,
4922
4962
  client: this,
4923
4963
  efConfig: collection.configuration_json.embedding_function ?? void 0
4924
4964
  }) ?? schemaEmbeddingFunction;
@@ -4988,7 +5028,6 @@ var ChromaClient = class {
4988
5028
  );
4989
5029
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
4990
5030
  const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
4991
- collectionName: data.name,
4992
5031
  client: this,
4993
5032
  efConfig: data.configuration_json.embedding_function ?? void 0
4994
5033
  }) ?? schemaEmbeddingFunction;
@@ -5024,7 +5063,6 @@ var ChromaClient = class {
5024
5063
  const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
5025
5064
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
5026
5065
  const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
5027
- collectionName: data.name,
5028
5066
  client: this,
5029
5067
  efConfig: data.configuration_json.embedding_function ?? void 0
5030
5068
  }) ?? schemaEmbeddingFunction;
@@ -5055,7 +5093,6 @@ var ChromaClient = class {
5055
5093
  const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
5056
5094
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
5057
5095
  const resolvedEmbeddingFunction = await getEmbeddingFunction({
5058
- collectionName: data.name,
5059
5096
  efConfig: data.configuration_json.embedding_function ?? void 0,
5060
5097
  client: this
5061
5098
  }) ?? schemaEmbeddingFunction;
@@ -5131,7 +5168,6 @@ var ChromaClient = class {
5131
5168
  );
5132
5169
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
5133
5170
  const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
5134
- collectionName: name,
5135
5171
  efConfig: data.configuration_json.embedding_function ?? void 0,
5136
5172
  client: this
5137
5173
  }) ?? schemaEmbeddingFunction;
@@ -5148,6 +5184,30 @@ var ChromaClient = class {
5148
5184
  schema: serverSchema
5149
5185
  });
5150
5186
  }
5187
+ /**
5188
+ * Returns a lightweight collection handle for the given collection ID.
5189
+ * The handle supports operations that don't require an embedding function
5190
+ * or schema (e.g., add with pre-computed embeddings, get, delete, count, search).
5191
+ * Operations that require an embedding function will throw a clear error
5192
+ * directing you to use {@link getCollection} instead.
5193
+ * @param id - The collection ID
5194
+ * @returns A Collection handle for the given ID
5195
+ * @throws ChromaValueError if tenant or database are not set on the client
5196
+ */
5197
+ collection(id) {
5198
+ if (!this._tenant || !this._database) {
5199
+ throw new ChromaValueError(
5200
+ "tenant and database must be set on the client before calling collection(). Provide them in the ChromaClient constructor or use getCollection() instead."
5201
+ );
5202
+ }
5203
+ return new CollectionHandle({
5204
+ chromaClient: this,
5205
+ apiClient: this.apiClient,
5206
+ id,
5207
+ tenant: this._tenant,
5208
+ database: this._database
5209
+ });
5210
+ }
5151
5211
  /**
5152
5212
  * Deletes a collection and all its data.
5153
5213
  * @param options - Deletion options
@@ -5284,6 +5344,7 @@ export {
5284
5344
  CloudClient,
5285
5345
  Cmek,
5286
5346
  CmekProvider,
5347
+ CollectionHandle,
5287
5348
  DOCUMENT_KEY,
5288
5349
  Div,
5289
5350
  EMBEDDING_KEY,