chromadb 3.1.5 → 3.1.6

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.
@@ -579,7 +579,7 @@ interface EmbeddingFunction {
579
579
  /** Returns all supported vector spaces for this embedding function */
580
580
  supportedSpaces?(): EmbeddingFunctionSpace[];
581
581
  /** Creates an instance from configuration object */
582
- buildFromConfig?(config: Record<string, any>): EmbeddingFunction;
582
+ buildFromConfig?(config: Record<string, any>, client?: ChromaClient): EmbeddingFunction;
583
583
  /** Returns the current configuration as an object */
584
584
  getConfig?(): Record<string, any>;
585
585
  /**
@@ -616,7 +616,7 @@ interface SparseEmbeddingFunction {
616
616
  /** Optional name identifier for the embedding function */
617
617
  name?: string;
618
618
  /** Creates an instance from configuration object */
619
- buildFromConfig?(config: Record<string, any>): SparseEmbeddingFunction;
619
+ buildFromConfig?(config: Record<string, any>, client?: ChromaClient): SparseEmbeddingFunction;
620
620
  /** Returns the current configuration as an object */
621
621
  getConfig?(): Record<string, any>;
622
622
  /**
@@ -640,7 +640,7 @@ interface EmbeddingFunctionClass {
640
640
  /** Name identifier for the embedding function */
641
641
  name: string;
642
642
  /** Static method to build instance from configuration */
643
- buildFromConfig(config: Record<string, any>): EmbeddingFunction;
643
+ buildFromConfig(config: Record<string, any>, client?: ChromaClient): EmbeddingFunction;
644
644
  }
645
645
  /**
646
646
  * Interface for sparse embedding function constructor classes.
@@ -652,7 +652,7 @@ interface SparseEmbeddingFunctionClass {
652
652
  /** Name identifier for the embedding function */
653
653
  name: string;
654
654
  /** Static method to build instance from configuration */
655
- buildFromConfig(config: Record<string, any>): SparseEmbeddingFunction;
655
+ buildFromConfig(config: Record<string, any>, client?: ChromaClient): SparseEmbeddingFunction;
656
656
  }
657
657
  /**
658
658
  * Registry of available embedding functions.
@@ -684,18 +684,18 @@ declare const registerEmbeddingFunction: (name: string, fn: EmbeddingFunctionCla
684
684
  declare const registerSparseEmbeddingFunction: (name: string, fn: SparseEmbeddingFunctionClass) => void;
685
685
  /**
686
686
  * Retrieves and instantiates an embedding function from configuration.
687
- * @param collectionName - Name of the collection (for error messages)
688
- * @param efConfig - Configuration for the embedding function
689
687
  * @returns EmbeddingFunction instance or undefined if it cannot be constructed
690
688
  */
691
- declare const getEmbeddingFunction: (collectionName: string, efConfig?: EmbeddingFunctionConfiguration) => Promise<EmbeddingFunction | undefined>;
689
+ declare const getEmbeddingFunction: (args: {
690
+ collectionName: string;
691
+ client: ChromaClient;
692
+ efConfig?: EmbeddingFunctionConfiguration;
693
+ }) => Promise<EmbeddingFunction | undefined>;
692
694
  /**
693
695
  * Retrieves and instantiates a sparse embedding function from configuration.
694
- * @param collectionName - Name of the collection (for error messages)
695
- * @param efConfig - Configuration for the sparse embedding function
696
696
  * @returns SparseEmbeddingFunction instance or undefined if it cannot be constructed
697
697
  */
698
- declare const getSparseEmbeddingFunction: (collectionName: string, efConfig?: EmbeddingFunctionConfiguration) => Promise<SparseEmbeddingFunction | undefined>;
698
+ declare const getSparseEmbeddingFunction: (collectionName: string, client: ChromaClient, efConfig?: EmbeddingFunctionConfiguration) => Promise<SparseEmbeddingFunction | undefined>;
699
699
  /**
700
700
  * Serializes an embedding function to configuration format.
701
701
  * @param embeddingFunction - User provided embedding function
@@ -1001,7 +1001,7 @@ declare class Schema {
1001
1001
  createIndex(config?: IndexConfig, key?: string): this;
1002
1002
  deleteIndex(config?: IndexConfig, key?: string): this;
1003
1003
  serializeToJSON(): Schema$1;
1004
- static deserializeFromJSON(json?: Schema$1 | JsonDict | null): Promise<Schema | undefined>;
1004
+ static deserializeFromJSON(json: Schema$1 | JsonDict | null, client: ChromaClient): Promise<Schema | undefined>;
1005
1005
  private setVectorIndexConfig;
1006
1006
  private setFtsIndexConfig;
1007
1007
  private setIndexInDefaults;
@@ -1075,11 +1075,12 @@ declare const processCreateCollectionConfig: ({ configuration, embeddingFunction
1075
1075
  /**
1076
1076
  *
1077
1077
  */
1078
- declare const processUpdateCollectionConfig: ({ collectionName, currentConfiguration, currentEmbeddingFunction, newConfiguration, }: {
1078
+ declare const processUpdateCollectionConfig: ({ collectionName, currentConfiguration, currentEmbeddingFunction, newConfiguration, client, }: {
1079
1079
  collectionName: string;
1080
1080
  currentConfiguration: CollectionConfiguration;
1081
1081
  currentEmbeddingFunction?: EmbeddingFunction;
1082
1082
  newConfiguration: UpdateCollectionConfiguration;
1083
+ client: ChromaClient;
1083
1084
  }) => Promise<{
1084
1085
  updateConfiguration?: UpdateCollectionConfiguration$1;
1085
1086
  updateEmbeddingFunction?: EmbeddingFunction;
@@ -1116,6 +1117,7 @@ declare class ChromaClient {
1116
1117
  private _tenant;
1117
1118
  private _database;
1118
1119
  private _preflightChecks;
1120
+ private _headers;
1119
1121
  private readonly apiClient;
1120
1122
  /**
1121
1123
  * Creates a new ChromaClient instance.
@@ -1140,6 +1142,7 @@ declare class ChromaClient {
1140
1142
  */
1141
1143
  get preflightChecks(): ChecklistResponse | undefined;
1142
1144
  protected set preflightChecks(preflightChecks: ChecklistResponse | undefined);
1145
+ get headers(): Record<string, string> | undefined;
1143
1146
  /** @ignore */
1144
1147
  _path(): Promise<{
1145
1148
  tenant: string;
@@ -1200,6 +1203,13 @@ declare class ChromaClient {
1200
1203
  name: string;
1201
1204
  embeddingFunction?: EmbeddingFunction;
1202
1205
  }): Promise<Collection>;
1206
+ /**
1207
+ * Retrieves an existing collection by its Chroma Resource Name (CRN).
1208
+ * @param crn - The Chroma Resource Name of the collection to retrieve
1209
+ * @returns Promise resolving to the Collection instance
1210
+ * @throws Error if the collection does not exist
1211
+ */
1212
+ getCollectionByCrn(crn: string): Promise<Collection>;
1203
1213
  /**
1204
1214
  * Retrieves multiple collections by name.
1205
1215
  * @param items - Array of collection names or objects with name and optional embedding function (should match the ones used to create the collections)
@@ -1266,6 +1276,10 @@ declare class ChromaClient {
1266
1276
  * Provides methods for adding, querying, updating, and deleting records.
1267
1277
  */
1268
1278
  interface Collection {
1279
+ /** Tenant name */
1280
+ tenant: string;
1281
+ /** Database name */
1282
+ database: string;
1269
1283
  /** Unique identifier for the collection */
1270
1284
  id: string;
1271
1285
  /** Name of the collection */
@@ -1325,7 +1325,8 @@ var registerSparseEmbeddingFunction = (name, fn) => {
1325
1325
  }
1326
1326
  knownSparseEmbeddingFunctions.set(name, fn);
1327
1327
  };
1328
- var getEmbeddingFunction = async (collectionName, efConfig) => {
1328
+ var getEmbeddingFunction = async (args) => {
1329
+ const { collectionName, client: client2, efConfig } = args;
1329
1330
  if (!efConfig) {
1330
1331
  console.warn(
1331
1332
  `No embedding function configuration found for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
@@ -1375,7 +1376,7 @@ var getEmbeddingFunction = async (collectionName, efConfig) => {
1375
1376
  let constructorConfig = efConfig.type === "known" ? efConfig.config : {};
1376
1377
  try {
1377
1378
  if (embeddingFunction.buildFromConfig) {
1378
- return embeddingFunction.buildFromConfig(constructorConfig);
1379
+ return embeddingFunction.buildFromConfig(constructorConfig, client2);
1379
1380
  }
1380
1381
  console.warn(
1381
1382
  `Embedding function ${packageName} does not define a 'buildFromConfig' function. 'add' and 'query' will fail unless you provide them embeddings directly.`
@@ -1388,7 +1389,7 @@ var getEmbeddingFunction = async (collectionName, efConfig) => {
1388
1389
  return void 0;
1389
1390
  }
1390
1391
  };
1391
- var getSparseEmbeddingFunction = async (collectionName, efConfig) => {
1392
+ var getSparseEmbeddingFunction = async (collectionName, client2, efConfig) => {
1392
1393
  if (!efConfig) {
1393
1394
  return void 0;
1394
1395
  }
@@ -1423,7 +1424,7 @@ var getSparseEmbeddingFunction = async (collectionName, efConfig) => {
1423
1424
  let constructorConfig = efConfig.type === "known" ? efConfig.config : {};
1424
1425
  try {
1425
1426
  if (sparseEmbeddingFunction.buildFromConfig) {
1426
- return sparseEmbeddingFunction.buildFromConfig(constructorConfig);
1427
+ return sparseEmbeddingFunction.buildFromConfig(constructorConfig, client2);
1427
1428
  }
1428
1429
  console.warn(
1429
1430
  `Sparse embedding function ${packageName} does not define a 'buildFromConfig' function.`
@@ -1544,7 +1545,8 @@ var processUpdateCollectionConfig = async ({
1544
1545
  collectionName,
1545
1546
  currentConfiguration,
1546
1547
  currentEmbeddingFunction,
1547
- newConfiguration
1548
+ newConfiguration,
1549
+ client: client2
1548
1550
  }) => {
1549
1551
  if (newConfiguration.hnsw && typeof newConfiguration.hnsw !== "object") {
1550
1552
  throw new ChromaValueError(
@@ -1556,10 +1558,11 @@ var processUpdateCollectionConfig = async ({
1556
1558
  "Invalid SPANN config provided in UpdateCollectionConfiguration"
1557
1559
  );
1558
1560
  }
1559
- const embeddingFunction = currentEmbeddingFunction || await getEmbeddingFunction(
1561
+ const embeddingFunction = currentEmbeddingFunction || await getEmbeddingFunction({
1560
1562
  collectionName,
1561
- currentConfiguration.embeddingFunction ?? void 0
1562
- );
1563
+ client: client2,
1564
+ efConfig: currentConfiguration.embeddingFunction ?? void 0
1565
+ });
1563
1566
  const newEmbeddingFunction = newConfiguration.embeddingFunction;
1564
1567
  if (embeddingFunction && embeddingFunction.validateConfigUpdate && newEmbeddingFunction && newEmbeddingFunction.getConfig) {
1565
1568
  embeddingFunction.validateConfigUpdate(newEmbeddingFunction.getConfig());
@@ -2812,19 +2815,23 @@ var Schema = class _Schema {
2812
2815
  keys
2813
2816
  };
2814
2817
  }
2815
- static async deserializeFromJSON(json) {
2818
+ static async deserializeFromJSON(json, client2) {
2816
2819
  if (json == null) {
2817
2820
  return void 0;
2818
2821
  }
2819
2822
  const data = json;
2820
2823
  const instance = Object.create(_Schema.prototype);
2821
2824
  instance.defaults = await _Schema.deserializeValueTypes(
2822
- data.defaults ?? {}
2825
+ data.defaults ?? {},
2826
+ client2
2823
2827
  );
2824
2828
  instance.keys = {};
2825
2829
  const keys = data.keys ?? {};
2826
2830
  for (const [keyName, value] of Object.entries(keys)) {
2827
- instance.keys[keyName] = await _Schema.deserializeValueTypes(value);
2831
+ instance.keys[keyName] = await _Schema.deserializeValueTypes(
2832
+ value,
2833
+ client2
2834
+ );
2828
2835
  }
2829
2836
  return instance;
2830
2837
  }
@@ -3205,7 +3212,7 @@ var Schema = class _Schema {
3205
3212
  }
3206
3213
  return serialized;
3207
3214
  }
3208
- static async deserializeValueTypes(json) {
3215
+ static async deserializeValueTypes(json, client2) {
3209
3216
  const result = new ValueTypes();
3210
3217
  if (json[STRING_VALUE_NAME]) {
3211
3218
  result.string = _Schema.deserializeStringValueType(
@@ -3214,12 +3221,14 @@ var Schema = class _Schema {
3214
3221
  }
3215
3222
  if (json[FLOAT_LIST_VALUE_NAME]) {
3216
3223
  result.floatList = await _Schema.deserializeFloatListValueType(
3217
- json[FLOAT_LIST_VALUE_NAME]
3224
+ json[FLOAT_LIST_VALUE_NAME],
3225
+ client2
3218
3226
  );
3219
3227
  }
3220
3228
  if (json[SPARSE_VECTOR_VALUE_NAME]) {
3221
3229
  result.sparseVector = await _Schema.deserializeSparseVectorValueType(
3222
- json[SPARSE_VECTOR_VALUE_NAME]
3230
+ json[SPARSE_VECTOR_VALUE_NAME],
3231
+ client2
3223
3232
  );
3224
3233
  }
3225
3234
  if (json[INT_VALUE_NAME]) {
@@ -3251,23 +3260,27 @@ var Schema = class _Schema {
3251
3260
  }
3252
3261
  return new StringValueType(ftsIndex, stringIndex);
3253
3262
  }
3254
- static async deserializeFloatListValueType(json) {
3263
+ static async deserializeFloatListValueType(json, client2) {
3255
3264
  let vectorIndex = null;
3256
3265
  if (json[VECTOR_INDEX_NAME]) {
3257
3266
  const data = json[VECTOR_INDEX_NAME];
3258
3267
  const enabled = Boolean(data.enabled);
3259
- const config = await _Schema.deserializeVectorConfig(data.config ?? {});
3268
+ const config = await _Schema.deserializeVectorConfig(
3269
+ data.config ?? {},
3270
+ client2
3271
+ );
3260
3272
  vectorIndex = new VectorIndexType(enabled, config);
3261
3273
  }
3262
3274
  return new FloatListValueType(vectorIndex);
3263
3275
  }
3264
- static async deserializeSparseVectorValueType(json) {
3276
+ static async deserializeSparseVectorValueType(json, client2) {
3265
3277
  let sparseIndex = null;
3266
3278
  if (json[SPARSE_VECTOR_INDEX_NAME]) {
3267
3279
  const data = json[SPARSE_VECTOR_INDEX_NAME];
3268
3280
  const enabled = Boolean(data.enabled);
3269
3281
  const config = await _Schema.deserializeSparseVectorConfig(
3270
- data.config ?? {}
3282
+ data.config ?? {},
3283
+ client2
3271
3284
  );
3272
3285
  sparseIndex = new SparseVectorIndexType(enabled, config);
3273
3286
  }
@@ -3306,29 +3319,31 @@ var Schema = class _Schema {
3306
3319
  }
3307
3320
  return new BoolValueType(index);
3308
3321
  }
3309
- static async deserializeVectorConfig(json) {
3322
+ static async deserializeVectorConfig(json, client2) {
3310
3323
  const config = new VectorIndexConfig({
3311
3324
  space: json.space ?? null,
3312
3325
  sourceKey: json.source_key ?? null,
3313
3326
  hnsw: json.hnsw ? cloneObject(json.hnsw) : null,
3314
3327
  spann: json.spann ? cloneObject(json.spann) : null
3315
3328
  });
3316
- config.embeddingFunction = await getEmbeddingFunction(
3317
- "schema deserialization",
3318
- json.embedding_function
3319
- );
3329
+ config.embeddingFunction = await getEmbeddingFunction({
3330
+ collectionName: "schema deserialization",
3331
+ client: client2,
3332
+ efConfig: json.embedding_function
3333
+ });
3320
3334
  if (!config.space && config.embeddingFunction?.defaultSpace) {
3321
3335
  config.space = config.embeddingFunction.defaultSpace();
3322
3336
  }
3323
3337
  return config;
3324
3338
  }
3325
- static async deserializeSparseVectorConfig(json) {
3339
+ static async deserializeSparseVectorConfig(json, client2) {
3326
3340
  const config = new SparseVectorIndexConfig({
3327
3341
  sourceKey: json.source_key ?? null,
3328
3342
  bm25: typeof json.bm25 === "boolean" ? json.bm25 : null
3329
3343
  });
3330
3344
  const embeddingFunction = await getSparseEmbeddingFunction(
3331
3345
  "schema deserialization",
3346
+ client2,
3332
3347
  json.embedding_function
3333
3348
  ) ?? config.embeddingFunction ?? void 0;
3334
3349
  config.embeddingFunction = embeddingFunction ?? null;
@@ -3353,6 +3368,8 @@ var CollectionImpl = class _CollectionImpl {
3353
3368
  chromaClient,
3354
3369
  apiClient,
3355
3370
  id,
3371
+ tenant,
3372
+ database,
3356
3373
  name,
3357
3374
  metadata,
3358
3375
  configuration,
@@ -3362,6 +3379,8 @@ var CollectionImpl = class _CollectionImpl {
3362
3379
  this.chromaClient = chromaClient;
3363
3380
  this.apiClient = apiClient;
3364
3381
  this.id = id;
3382
+ this.tenant = tenant;
3383
+ this.database = database;
3365
3384
  this._name = name;
3366
3385
  this._metadata = metadata;
3367
3386
  this._configuration = configuration;
@@ -3399,9 +3418,9 @@ var CollectionImpl = class _CollectionImpl {
3399
3418
  this._schema = schema;
3400
3419
  }
3401
3420
  async path() {
3402
- const clientPath = await this.chromaClient._path();
3403
3421
  return {
3404
- ...clientPath,
3422
+ tenant: this.tenant,
3423
+ database: this.database,
3405
3424
  collection_id: this.id
3406
3425
  };
3407
3426
  }
@@ -3479,7 +3498,11 @@ var CollectionImpl = class _CollectionImpl {
3479
3498
  if (inputs.length === 0) {
3480
3499
  continue;
3481
3500
  }
3482
- const sparseEmbeddings2 = await this.sparseEmbed(embeddingFunction, inputs, false);
3501
+ const sparseEmbeddings2 = await this.sparseEmbed(
3502
+ embeddingFunction,
3503
+ inputs,
3504
+ false
3505
+ );
3483
3506
  if (sparseEmbeddings2.length !== positions.length) {
3484
3507
  throw new ChromaValueError(
3485
3508
  "Sparse embedding function returned unexpected number of embeddings."
@@ -3504,7 +3527,11 @@ var CollectionImpl = class _CollectionImpl {
3504
3527
  if (inputs.length === 0) {
3505
3528
  continue;
3506
3529
  }
3507
- const sparseEmbeddings = await this.sparseEmbed(embeddingFunction, inputs, false);
3530
+ const sparseEmbeddings = await this.sparseEmbed(
3531
+ embeddingFunction,
3532
+ inputs,
3533
+ false
3534
+ );
3508
3535
  if (sparseEmbeddings.length !== positions.length) {
3509
3536
  throw new ChromaValueError(
3510
3537
  "Sparse embedding function returned unexpected number of embeddings."
@@ -3801,7 +3828,9 @@ var CollectionImpl = class _CollectionImpl {
3801
3828
  async search(searches) {
3802
3829
  const items = Array.isArray(searches) ? searches : [searches];
3803
3830
  if (items.length === 0) {
3804
- throw new ChromaValueError("At least one search payload must be provided.");
3831
+ throw new ChromaValueError(
3832
+ "At least one search payload must be provided."
3833
+ );
3805
3834
  }
3806
3835
  const payloads = await Promise.all(
3807
3836
  items.map(async (search) => {
@@ -3830,7 +3859,8 @@ var CollectionImpl = class _CollectionImpl {
3830
3859
  collectionName: this.name,
3831
3860
  currentConfiguration: this.configuration,
3832
3861
  newConfiguration: configuration,
3833
- currentEmbeddingFunction: this.embeddingFunction
3862
+ currentEmbeddingFunction: this.embeddingFunction,
3863
+ client: this.chromaClient
3834
3864
  }) : {};
3835
3865
  if (updateEmbeddingFunction) {
3836
3866
  this.embeddingFunction = updateEmbeddingFunction;
@@ -3862,6 +3892,8 @@ var CollectionImpl = class _CollectionImpl {
3862
3892
  chromaClient: this.chromaClient,
3863
3893
  apiClient: this.apiClient,
3864
3894
  name: data.name,
3895
+ tenant: this.tenant,
3896
+ database: this.database,
3865
3897
  id: data.id,
3866
3898
  embeddingFunction: this._embeddingFunction,
3867
3899
  metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
@@ -3975,6 +4007,14 @@ var offlineError = (error) => {
3975
4007
  (error?.name === "TypeError" || error?.name === "FetchError") && (error.message?.includes("fetch failed") || error.message?.includes("Failed to fetch") || error.message?.includes("ENOTFOUND"))
3976
4008
  );
3977
4009
  };
4010
+ var getErrorMessage = async (response) => {
4011
+ try {
4012
+ const body = await response.clone().json();
4013
+ return body.message || body.error || `${response.status}: ${response.statusText}`;
4014
+ } catch {
4015
+ return `${response.status}: ${response.statusText}`;
4016
+ }
4017
+ };
3978
4018
  var chromaFetch = async (input, init) => {
3979
4019
  let response;
3980
4020
  try {
@@ -4014,15 +4054,23 @@ var chromaFetch = async (input, init) => {
4014
4054
  case 409:
4015
4055
  throw new ChromaUniqueError("The resource already exists");
4016
4056
  case 422:
4017
- const body = await response.json();
4018
- if (body && body.message && (body.message.startsWith("Quota exceeded") || body.message.startsWith("Billing limit exceeded"))) {
4019
- throw new ChromaQuotaExceededError(body?.message);
4057
+ try {
4058
+ const body = await response.json();
4059
+ if (body && body.message && (body.message.startsWith("Quota exceeded") || body.message.startsWith("Billing limit exceeded"))) {
4060
+ throw new ChromaQuotaExceededError(body?.message);
4061
+ }
4062
+ throw new ChromaClientError(body?.message || "Unprocessable Entity");
4063
+ } catch (error) {
4064
+ if (error instanceof ChromaQuotaExceededError || error instanceof ChromaClientError) {
4065
+ throw error;
4066
+ }
4067
+ throw new ChromaClientError(`Unprocessable Entity: ${response.statusText}`);
4020
4068
  }
4021
- break;
4022
4069
  case 429:
4023
4070
  throw new ChromaRateLimitError("Rate limit exceeded");
4024
4071
  }
4025
- throw new ChromaServerError(`${response.status}: ${response.statusText}`);
4072
+ const errorMessage = await getErrorMessage(response);
4073
+ throw new ChromaServerError(errorMessage);
4026
4074
  };
4027
4075
 
4028
4076
  // src/admin-client.ts
@@ -4182,6 +4230,7 @@ var ChromaClient = class {
4182
4230
  const baseUrl = `${ssl ? "https" : "http"}://${host}:${port}`;
4183
4231
  this._tenant = tenant || process.env.CHROMA_TENANT;
4184
4232
  this._database = database || process.env.CHROMA_DATABASE;
4233
+ this._headers = headers;
4185
4234
  const configOptions = {
4186
4235
  ...fetchOptions,
4187
4236
  method: normalizeMethod(fetchOptions?.method),
@@ -4221,6 +4270,9 @@ var ChromaClient = class {
4221
4270
  set preflightChecks(preflightChecks) {
4222
4271
  this._preflightChecks = preflightChecks;
4223
4272
  }
4273
+ get headers() {
4274
+ return this._headers;
4275
+ }
4224
4276
  /** @ignore */
4225
4277
  async _path() {
4226
4278
  if (!this._tenant || !this._database) {
@@ -4278,16 +4330,20 @@ var ChromaClient = class {
4278
4330
  return Promise.all(
4279
4331
  data.map(async (collection) => {
4280
4332
  const schema = await Schema.deserializeFromJSON(
4281
- collection.schema ?? void 0
4333
+ collection.schema ?? null,
4334
+ this
4282
4335
  );
4283
4336
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
4284
- const resolvedEmbeddingFunction = await getEmbeddingFunction(
4285
- collection.name,
4286
- collection.configuration_json.embedding_function ?? void 0
4287
- ) ?? schemaEmbeddingFunction;
4337
+ const resolvedEmbeddingFunction = await getEmbeddingFunction({
4338
+ collectionName: collection.name,
4339
+ client: this,
4340
+ efConfig: collection.configuration_json.embedding_function ?? void 0
4341
+ }) ?? schemaEmbeddingFunction;
4288
4342
  return new CollectionImpl({
4289
4343
  chromaClient: this,
4290
4344
  apiClient: this.apiClient,
4345
+ tenant: collection.tenant,
4346
+ database: collection.database,
4291
4347
  name: collection.name,
4292
4348
  id: collection.id,
4293
4349
  embeddingFunction: resolvedEmbeddingFunction,
@@ -4344,17 +4400,21 @@ var ChromaClient = class {
4344
4400
  }
4345
4401
  });
4346
4402
  const serverSchema = await Schema.deserializeFromJSON(
4347
- data.schema ?? void 0
4403
+ data.schema ?? null,
4404
+ this
4348
4405
  );
4349
4406
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
4350
- const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction(
4351
- data.name,
4352
- data.configuration_json.embedding_function ?? void 0
4353
- ) ?? schemaEmbeddingFunction;
4407
+ const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
4408
+ collectionName: data.name,
4409
+ client: this,
4410
+ efConfig: data.configuration_json.embedding_function ?? void 0
4411
+ }) ?? schemaEmbeddingFunction;
4354
4412
  return new CollectionImpl({
4355
4413
  chromaClient: this,
4356
4414
  apiClient: this.apiClient,
4357
4415
  name,
4416
+ tenant: data.tenant,
4417
+ database: data.database,
4358
4418
  configuration: data.configuration_json,
4359
4419
  metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
4360
4420
  embeddingFunction: resolvedEmbeddingFunction,
@@ -4378,16 +4438,50 @@ var ChromaClient = class {
4378
4438
  client: this.apiClient,
4379
4439
  path: { ...await this._path(), collection_id: name }
4380
4440
  });
4381
- const schema = await Schema.deserializeFromJSON(data.schema ?? void 0);
4441
+ const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
4382
4442
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
4383
- const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction(
4384
- data.name,
4385
- data.configuration_json.embedding_function ?? void 0
4386
- ) ?? schemaEmbeddingFunction;
4443
+ const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
4444
+ collectionName: data.name,
4445
+ client: this,
4446
+ efConfig: data.configuration_json.embedding_function ?? void 0
4447
+ }) ?? schemaEmbeddingFunction;
4387
4448
  return new CollectionImpl({
4388
4449
  chromaClient: this,
4389
4450
  apiClient: this.apiClient,
4390
4451
  name,
4452
+ tenant: data.tenant,
4453
+ database: data.database,
4454
+ configuration: data.configuration_json,
4455
+ metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
4456
+ embeddingFunction: resolvedEmbeddingFunction,
4457
+ id: data.id,
4458
+ schema
4459
+ });
4460
+ }
4461
+ /**
4462
+ * Retrieves an existing collection by its Chroma Resource Name (CRN).
4463
+ * @param crn - The Chroma Resource Name of the collection to retrieve
4464
+ * @returns Promise resolving to the Collection instance
4465
+ * @throws Error if the collection does not exist
4466
+ */
4467
+ async getCollectionByCrn(crn) {
4468
+ const { data } = await DefaultService.getCollectionByCrn({
4469
+ client: this.apiClient,
4470
+ path: { crn }
4471
+ });
4472
+ const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
4473
+ const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
4474
+ const resolvedEmbeddingFunction = await getEmbeddingFunction({
4475
+ collectionName: data.name,
4476
+ efConfig: data.configuration_json.embedding_function ?? void 0,
4477
+ client: this
4478
+ }) ?? schemaEmbeddingFunction;
4479
+ return new CollectionImpl({
4480
+ chromaClient: this,
4481
+ apiClient: this.apiClient,
4482
+ name: data.name,
4483
+ tenant: data.tenant,
4484
+ database: data.database,
4391
4485
  configuration: data.configuration_json,
4392
4486
  metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
4393
4487
  embeddingFunction: resolvedEmbeddingFunction,
@@ -4434,7 +4528,8 @@ var ChromaClient = class {
4434
4528
  const collectionConfig = await processCreateCollectionConfig({
4435
4529
  configuration,
4436
4530
  embeddingFunction,
4437
- metadata
4531
+ metadata,
4532
+ schema
4438
4533
  });
4439
4534
  const { data } = await DefaultService.createCollection({
4440
4535
  client: this.apiClient,
@@ -4448,17 +4543,21 @@ var ChromaClient = class {
4448
4543
  }
4449
4544
  });
4450
4545
  const serverSchema = await Schema.deserializeFromJSON(
4451
- data.schema ?? void 0
4546
+ data.schema ?? null,
4547
+ this
4452
4548
  );
4453
4549
  const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
4454
- const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction(
4455
- name,
4456
- data.configuration_json.embedding_function ?? void 0
4457
- ) ?? schemaEmbeddingFunction;
4550
+ const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
4551
+ collectionName: name,
4552
+ efConfig: data.configuration_json.embedding_function ?? void 0,
4553
+ client: this
4554
+ }) ?? schemaEmbeddingFunction;
4458
4555
  return new CollectionImpl({
4459
4556
  chromaClient: this,
4460
4557
  apiClient: this.apiClient,
4461
4558
  name,
4559
+ tenant: data.tenant,
4560
+ database: data.database,
4462
4561
  configuration: data.configuration_json,
4463
4562
  metadata: deserializeMetadata(data.metadata ?? void 0) ?? void 0,
4464
4563
  embeddingFunction: resolvedEmbeddingFunction,