chromadb 3.3.1 → 3.3.3

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
@@ -1515,7 +1515,10 @@ var pythonEmbeddingFunctions = {
1515
1515
  onnx_mini_lm_l6_v2: "default-embed",
1516
1516
  default: "default-embed",
1517
1517
  together_ai: "together-ai",
1518
- sentence_transformer: "sentence-transformer"
1518
+ sentence_transformer: "sentence-transformer",
1519
+ google_gemini: "google-gemini",
1520
+ google_genai: "google-gemini"
1521
+ // Backward compatibility alias
1519
1522
  };
1520
1523
  var unsupportedEmbeddingFunctions = /* @__PURE__ */ new Set([
1521
1524
  "amazon_bedrock",
@@ -1554,32 +1557,11 @@ var registerSparseEmbeddingFunction = (name, fn) => {
1554
1557
  knownSparseEmbeddingFunctions.set(name, fn);
1555
1558
  };
1556
1559
  var getEmbeddingFunction = async (args) => {
1557
- const { collectionName, client: client2, efConfig } = args;
1558
- if (!efConfig) {
1559
- console.warn(
1560
- `No embedding function configuration found for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
1561
- );
1562
- return void 0;
1563
- }
1564
- if (efConfig.type === "legacy") {
1565
- console.warn(
1566
- `No embedding function configuration found for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
1567
- );
1568
- return void 0;
1569
- }
1570
- if (efConfig.type === "unknown") {
1571
- console.warn(
1572
- `Unknown embedding function configuration for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
1573
- );
1574
- return void 0;
1575
- }
1576
- if (efConfig.type !== "known") {
1560
+ const { client: client2, efConfig } = args;
1561
+ if (efConfig?.type !== "known") {
1577
1562
  return void 0;
1578
1563
  }
1579
1564
  if (unsupportedEmbeddingFunctions.has(efConfig.name)) {
1580
- console.warn(
1581
- `Embedding function ${efConfig.name} is not supported in the JS/TS SDK. 'add' and 'query' will fail unless you provide them embeddings directly.`
1582
- );
1583
1565
  return void 0;
1584
1566
  }
1585
1567
  const packageName = pythonEmbeddingFunctions[efConfig.name] || efConfig.name;
@@ -1595,42 +1577,24 @@ var getEmbeddingFunction = async (args) => {
1595
1577
  } catch (error) {
1596
1578
  }
1597
1579
  if (!embeddingFunction) {
1598
- console.warn(
1599
- `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.`
1600
- );
1601
1580
  return void 0;
1602
1581
  }
1603
1582
  }
1604
- let constructorConfig = efConfig.type === "known" ? efConfig.config : {};
1583
+ const constructorConfig = efConfig.config ?? {};
1605
1584
  try {
1606
1585
  if (embeddingFunction.buildFromConfig) {
1607
1586
  return embeddingFunction.buildFromConfig(constructorConfig, client2);
1608
1587
  }
1609
- console.warn(
1610
- `Embedding function ${packageName} does not define a 'buildFromConfig' function. 'add' and 'query' will fail unless you provide them embeddings directly.`
1611
- );
1612
1588
  return void 0;
1613
1589
  } catch (e) {
1614
- console.warn(
1615
- `Embedding function ${packageName} failed to build with config: ${constructorConfig}. 'add' and 'query' will fail unless you provide them embeddings directly. Error: ${e}`
1616
- );
1617
1590
  return void 0;
1618
1591
  }
1619
1592
  };
1620
- var getSparseEmbeddingFunction = async (collectionName, client2, efConfig) => {
1621
- if (!efConfig) {
1622
- return void 0;
1623
- }
1624
- if (efConfig.type === "legacy") {
1625
- return void 0;
1626
- }
1627
- if (efConfig.type !== "known") {
1593
+ var getSparseEmbeddingFunction = async (client2, efConfig) => {
1594
+ if (efConfig?.type !== "known") {
1628
1595
  return void 0;
1629
1596
  }
1630
1597
  if (unsupportedSparseEmbeddingFunctions.has(efConfig.name)) {
1631
- console.warn(
1632
- "Embedding function ${efConfig.name} is not supported in the JS/TS SDK. 'add' and 'query' will fail unless you provide them embeddings directly."
1633
- );
1634
1598
  return void 0;
1635
1599
  }
1636
1600
  const packageName = pythonSparseEmbeddingFunctions[efConfig.name] || efConfig.name;
@@ -1643,25 +1607,16 @@ var getSparseEmbeddingFunction = async (collectionName, client2, efConfig) => {
1643
1607
  } catch (error) {
1644
1608
  }
1645
1609
  if (!sparseEmbeddingFunction) {
1646
- console.warn(
1647
- `Collection ${collectionName} was created with the ${packageName} sparse embedding function. However, the @chroma-core/${packageName} package is not installed.`
1648
- );
1649
1610
  return void 0;
1650
1611
  }
1651
1612
  }
1652
- let constructorConfig = efConfig.type === "known" ? efConfig.config : {};
1613
+ const constructorConfig = efConfig.config ?? {};
1653
1614
  try {
1654
1615
  if (sparseEmbeddingFunction.buildFromConfig) {
1655
1616
  return sparseEmbeddingFunction.buildFromConfig(constructorConfig, client2);
1656
1617
  }
1657
- console.warn(
1658
- `Sparse embedding function ${packageName} does not define a 'buildFromConfig' function.`
1659
- );
1660
1618
  return void 0;
1661
1619
  } catch (e) {
1662
- console.warn(
1663
- `Sparse embedding function ${packageName} failed to build with config: ${constructorConfig}. Error: ${e}`
1664
- );
1665
1620
  return void 0;
1666
1621
  }
1667
1622
  };
@@ -1787,7 +1742,6 @@ var processUpdateCollectionConfig = async ({
1787
1742
  );
1788
1743
  }
1789
1744
  const embeddingFunction = currentEmbeddingFunction || await getEmbeddingFunction({
1790
- collectionName,
1791
1745
  client: client2,
1792
1746
  efConfig: currentConfiguration.embeddingFunction ?? void 0
1793
1747
  });
@@ -3276,9 +3230,19 @@ var Schema = class _Schema {
3276
3230
  "Cannot enable all index types globally. Must specify either config or key."
3277
3231
  );
3278
3232
  }
3279
- if (keyProvided && key && (key === EMBEDDING_KEY || key === DOCUMENT_KEY)) {
3233
+ if (keyProvided && key && key === EMBEDDING_KEY) {
3280
3234
  throw new Error(
3281
- `Cannot create index on special key '${key}'. These keys are managed automatically by the system.`
3235
+ `Cannot create index on special key '${key}'. This key is managed automatically by the system. Invoke createIndex(new VectorIndexConfig(...)) without specifying a key to configure the vector index globally.`
3236
+ );
3237
+ }
3238
+ if (keyProvided && key === DOCUMENT_KEY && !(config instanceof FtsIndexConfig)) {
3239
+ throw new Error(
3240
+ `Cannot create index on special key '${key}' with this config. Only FtsIndexConfig is allowed for #document.`
3241
+ );
3242
+ }
3243
+ if (keyProvided && key && key.startsWith("#") && key !== DOCUMENT_KEY) {
3244
+ throw new Error(
3245
+ "key cannot begin with '#'. Keys starting with '#' are reserved for system use."
3282
3246
  );
3283
3247
  }
3284
3248
  if (config instanceof VectorIndexConfig) {
@@ -3287,21 +3251,17 @@ var Schema = class _Schema {
3287
3251
  return this;
3288
3252
  }
3289
3253
  throw new Error(
3290
- "Vector index cannot be enabled on specific keys. Use createIndex(config=VectorIndexConfig(...)) without specifying a key to configure the vector index globally."
3254
+ "Vector index cannot be enabled on specific keys. Use createIndex(new VectorIndexConfig(...)) without specifying a key to configure the vector index globally."
3291
3255
  );
3292
3256
  }
3293
- if (config instanceof FtsIndexConfig) {
3294
- if (!keyProvided) {
3295
- this.setFtsIndexConfig(config);
3296
- return this;
3297
- }
3257
+ if (config instanceof FtsIndexConfig && (!keyProvided || key !== DOCUMENT_KEY)) {
3298
3258
  throw new Error(
3299
- "FTS index cannot be enabled on specific keys. Use createIndex(config=FtsIndexConfig(...)) without specifying a key to configure the FTS index globally."
3259
+ "FTS index can only be enabled on #document key. Use createIndex(new FtsIndexConfig(), '#document')"
3300
3260
  );
3301
3261
  }
3302
3262
  if (config instanceof SparseVectorIndexConfig && !keyProvided) {
3303
3263
  throw new Error(
3304
- "Sparse vector index must be created on a specific key. Please specify a key using: createIndex(config=SparseVectorIndexConfig(...), key='your_key')"
3264
+ "Sparse vector index must be created on a specific key. Please specify a key using: createIndex(new SparseVectorIndexConfig(...), 'your_key')"
3305
3265
  );
3306
3266
  }
3307
3267
  if (!configProvided && keyProvided && key) {
@@ -3324,22 +3284,32 @@ var Schema = class _Schema {
3324
3284
  "Cannot disable all indexes. Must specify either config or key."
3325
3285
  );
3326
3286
  }
3327
- if (keyProvided && key && (key === EMBEDDING_KEY || key === DOCUMENT_KEY)) {
3287
+ if (keyProvided && key && key === EMBEDDING_KEY) {
3288
+ throw new Error(
3289
+ "Cannot modify #embedding. Currently not supported"
3290
+ );
3291
+ }
3292
+ if (keyProvided && key === DOCUMENT_KEY && !(config instanceof FtsIndexConfig)) {
3293
+ throw new Error(
3294
+ `Cannot delete index on special key '${key}' with this config. Only FtsIndexConfig is allowed for #document.`
3295
+ );
3296
+ }
3297
+ if (keyProvided && key && key.startsWith("#") && key !== DOCUMENT_KEY) {
3328
3298
  throw new Error(
3329
- `Cannot delete index on special key '${key}'. These keys are managed automatically by the system.`
3299
+ "key cannot begin with '#'. Keys starting with '#' are reserved for system use."
3330
3300
  );
3331
3301
  }
3332
3302
  if (config instanceof VectorIndexConfig) {
3333
3303
  throw new Error("Deleting vector index is not currently supported.");
3334
3304
  }
3335
- if (config instanceof FtsIndexConfig) {
3336
- throw new Error("Deleting FTS index is not currently supported.");
3337
- }
3338
3305
  if (config instanceof SparseVectorIndexConfig) {
3339
3306
  throw new Error(
3340
3307
  "Deleting sparse vector index is not currently supported."
3341
3308
  );
3342
3309
  }
3310
+ if (config instanceof FtsIndexConfig && (!keyProvided || key !== DOCUMENT_KEY)) {
3311
+ throw new Error("Deleting FTS index is only supported on #document key.");
3312
+ }
3343
3313
  if (keyProvided && !configProvided && key) {
3344
3314
  throw new Error(
3345
3315
  `Cannot disable all index types for key '${key}'. Please specify a specific index configuration.`
@@ -3423,22 +3393,6 @@ var Schema = class _Schema {
3423
3393
  })
3424
3394
  );
3425
3395
  }
3426
- setFtsIndexConfig(config) {
3427
- const defaultsString = ensureStringValueType(this.defaults);
3428
- const currentDefaultsFts = defaultsString.ftsIndex ?? new FtsIndexType(false, new FtsIndexConfig());
3429
- defaultsString.ftsIndex = new FtsIndexType(
3430
- currentDefaultsFts.enabled,
3431
- config
3432
- );
3433
- const documentValueTypes = ensureValueTypes(this.keys[DOCUMENT_KEY]);
3434
- this.keys[DOCUMENT_KEY] = documentValueTypes;
3435
- const overrideString = ensureStringValueType(documentValueTypes);
3436
- const currentOverrideFts = overrideString.ftsIndex ?? new FtsIndexType(true, new FtsIndexConfig());
3437
- overrideString.ftsIndex = new FtsIndexType(
3438
- currentOverrideFts.enabled,
3439
- config
3440
- );
3441
- }
3442
3396
  setIndexInDefaults(config, enabled) {
3443
3397
  if (config instanceof FtsIndexConfig) {
3444
3398
  const valueType = ensureStringValueType(this.defaults);
@@ -3885,7 +3839,6 @@ var Schema = class _Schema {
3885
3839
  spann: json.spann ? cloneObject(json.spann) : null
3886
3840
  });
3887
3841
  config.embeddingFunction = await getEmbeddingFunction({
3888
- collectionName: "schema deserialization",
3889
3842
  client: client2,
3890
3843
  efConfig: json.embedding_function
3891
3844
  });
@@ -3900,7 +3853,6 @@ var Schema = class _Schema {
3900
3853
  bm25: typeof json.bm25 === "boolean" ? json.bm25 : null
3901
3854
  });
3902
3855
  const embeddingFunction = await getSparseEmbeddingFunction(
3903
- "schema deserialization",
3904
3856
  client2,
3905
3857
  json.embedding_function
3906
3858
  ) ?? config.embeddingFunction ?? void 0;
@@ -3986,7 +3938,7 @@ var CollectionImpl = class _CollectionImpl {
3986
3938
  const embeddingFunction = this._embeddingFunction ?? this.getSchemaEmbeddingFunction();
3987
3939
  if (!embeddingFunction) {
3988
3940
  throw new ChromaValueError(
3989
- "Embedding function must be defined for operations requiring embeddings."
3941
+ `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.`
3990
3942
  );
3991
3943
  }
3992
3944
  if (isQuery && embeddingFunction.generateForQueries) {
@@ -4047,10 +3999,8 @@ var CollectionImpl = class _CollectionImpl {
4047
3999
  }
4048
4000
  if (index < documentsList.length) {
4049
4001
  const doc = documentsList[index];
4050
- if (typeof doc === "string") {
4051
- inputs.push(doc);
4052
- positions.push(index);
4053
- }
4002
+ inputs.push(doc);
4003
+ positions.push(index);
4054
4004
  }
4055
4005
  });
4056
4006
  if (inputs.length === 0) {
@@ -4263,15 +4213,24 @@ var CollectionImpl = class _CollectionImpl {
4263
4213
  embeddings
4264
4214
  };
4265
4215
  }
4266
- validateDelete(ids, where, whereDocument) {
4216
+ validateDelete(ids, where, whereDocument, limit) {
4267
4217
  if (ids) validateIDs(ids);
4268
4218
  if (where) validateWhere(where);
4269
4219
  if (whereDocument) validateWhereDocument(whereDocument);
4220
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit < 0)) {
4221
+ throw new Error("limit must be a non-negative integer");
4222
+ }
4223
+ if (limit !== void 0 && !where && !whereDocument) {
4224
+ throw new Error(
4225
+ "limit can only be specified when a where or whereDocument clause is provided"
4226
+ );
4227
+ }
4270
4228
  }
4271
- async count() {
4229
+ async count(options) {
4272
4230
  const { data } = await RecordService.collectionCount({
4273
4231
  client: this.apiClient,
4274
- path: await this.path()
4232
+ path: await this.path(),
4233
+ query: options?.readLevel ? { read_level: options.readLevel } : void 0
4275
4234
  });
4276
4235
  return data;
4277
4236
  }
@@ -4523,18 +4482,21 @@ var CollectionImpl = class _CollectionImpl {
4523
4482
  async delete({
4524
4483
  ids,
4525
4484
  where,
4526
- whereDocument
4485
+ whereDocument,
4486
+ limit
4527
4487
  }) {
4528
- this.validateDelete(ids, where, whereDocument);
4529
- await RecordService.collectionDelete({
4488
+ this.validateDelete(ids, where, whereDocument, limit);
4489
+ const { data } = await RecordService.collectionDelete({
4530
4490
  client: this.apiClient,
4531
4491
  path: await this.path(),
4532
4492
  body: {
4533
4493
  ids,
4534
4494
  where,
4535
- where_document: whereDocument
4495
+ where_document: whereDocument,
4496
+ limit
4536
4497
  }
4537
4498
  });
4499
+ return { deleted: data?.deleted ?? 0 };
4538
4500
  }
4539
4501
  async getIndexingStatus() {
4540
4502
  const { data } = await RecordService.indexingStatus({
@@ -4905,7 +4867,6 @@ var ChromaClient = class {
4905
4867
  );
4906
4868
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
4907
4869
  const resolvedEmbeddingFunction = await getEmbeddingFunction({
4908
- collectionName: collection.name,
4909
4870
  client: this,
4910
4871
  efConfig: collection.configuration_json.embedding_function ?? void 0
4911
4872
  }) ?? schemaEmbeddingFunction;
@@ -4975,7 +4936,6 @@ var ChromaClient = class {
4975
4936
  );
4976
4937
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
4977
4938
  const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
4978
- collectionName: data.name,
4979
4939
  client: this,
4980
4940
  efConfig: data.configuration_json.embedding_function ?? void 0
4981
4941
  }) ?? schemaEmbeddingFunction;
@@ -5011,7 +4971,6 @@ var ChromaClient = class {
5011
4971
  const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
5012
4972
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
5013
4973
  const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
5014
- collectionName: data.name,
5015
4974
  client: this,
5016
4975
  efConfig: data.configuration_json.embedding_function ?? void 0
5017
4976
  }) ?? schemaEmbeddingFunction;
@@ -5042,7 +5001,6 @@ var ChromaClient = class {
5042
5001
  const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
5043
5002
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
5044
5003
  const resolvedEmbeddingFunction = await getEmbeddingFunction({
5045
- collectionName: data.name,
5046
5004
  efConfig: data.configuration_json.embedding_function ?? void 0,
5047
5005
  client: this
5048
5006
  }) ?? schemaEmbeddingFunction;
@@ -5118,7 +5076,6 @@ var ChromaClient = class {
5118
5076
  );
5119
5077
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
5120
5078
  const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
5121
- collectionName: name,
5122
5079
  efConfig: data.configuration_json.embedding_function ?? void 0,
5123
5080
  client: this
5124
5081
  }) ?? schemaEmbeddingFunction;