chromadb 1.10.3 → 1.10.5

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.
@@ -2,6 +2,7 @@ import * as openai from 'openai';
2
2
  import * as _xenova_transformers from '@xenova/transformers';
3
3
  import * as chromadb_default_embed from 'chromadb-default-embed';
4
4
  import * as _google_generative_ai from '@google/generative-ai';
5
+ import * as ollama from 'ollama';
5
6
 
6
7
  interface IEmbeddingFunction {
7
8
  generate(texts: string[]): Promise<number[][]>;
@@ -1433,7 +1434,7 @@ declare class ChromaClient {
1433
1434
  */
1434
1435
  getOrCreateCollection({ name, metadata, embeddingFunction, }: GetOrCreateCollectionParams): Promise<Collection>;
1435
1436
  /**
1436
- * Lists all collections.
1437
+ * Get all collection names.
1437
1438
  *
1438
1439
  * @returns {Promise<string[]>} A promise that resolves to a list of collection names.
1439
1440
  * @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
@@ -1449,6 +1450,26 @@ declare class ChromaClient {
1449
1450
  * ```
1450
1451
  */
1451
1452
  listCollections({ limit, offset }?: ListCollectionsParams): Promise<string[]>;
1453
+ /**
1454
+ * List collection names, IDs, and metadata.
1455
+ *
1456
+ * @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
1457
+ * @param {PositiveInteger} [params.offset] - Optional offset on the items to get.
1458
+ * @throws {Error} If there is an issue listing the collections.
1459
+ * @returns {Promise<{ name: string, id: string, metadata?: CollectionMetadata }[]>} A promise that resolves to a list of collection names, IDs, and metadata.
1460
+ *
1461
+ * @example
1462
+ * ```typescript
1463
+ * const collections = await client.listCollectionsAndMetadata({
1464
+ * limit: 10,
1465
+ * offset: 0,
1466
+ * });
1467
+ */
1468
+ listCollectionsAndMetadata({ limit, offset, }?: ListCollectionsParams): Promise<{
1469
+ name: string;
1470
+ id: string;
1471
+ metadata?: CollectionMetadata;
1472
+ }[]>;
1452
1473
  /**
1453
1474
  * Counts all collections.
1454
1475
  *
@@ -1498,6 +1519,8 @@ interface Tenant {
1498
1519
  name: string;
1499
1520
  }
1500
1521
  interface Database {
1522
+ id: string;
1523
+ tenant: string;
1501
1524
  name: string;
1502
1525
  }
1503
1526
  declare class AdminClient {
@@ -1628,7 +1651,9 @@ declare class AdminClient {
1628
1651
  createDatabase({ name, tenantName, }: {
1629
1652
  name: string;
1630
1653
  tenantName: string;
1631
- }): Promise<Database>;
1654
+ }): Promise<{
1655
+ name: string;
1656
+ }>;
1632
1657
  /**
1633
1658
  * Gets a database with the specified properties.
1634
1659
  *
@@ -1822,13 +1847,85 @@ declare class GoogleGenerativeAiEmbeddingFunction implements IEmbeddingFunction
1822
1847
  }
1823
1848
 
1824
1849
  declare class OllamaEmbeddingFunction implements IEmbeddingFunction {
1825
- private readonly url;
1850
+ private readonly url?;
1826
1851
  private readonly model;
1827
- constructor({ url, model }: {
1828
- url: string;
1829
- model: string;
1852
+ private ollamaClient;
1853
+ constructor({ url, model, }?: {
1854
+ url?: string;
1855
+ model?: string;
1830
1856
  });
1831
- generate(texts: string[]): Promise<number[][]>;
1857
+ private initClient;
1858
+ /** @ignore */
1859
+ static import(): Promise<{
1860
+ ollama: typeof ollama;
1861
+ }>;
1862
+ generate(texts: string[]): Promise<any>;
1863
+ }
1864
+
1865
+ /**
1866
+ * This is a generic Chroma error.
1867
+ */
1868
+ declare class ChromaError extends Error {
1869
+ readonly cause?: unknown | undefined;
1870
+ constructor(name: string, message: string, cause?: unknown | undefined);
1871
+ }
1872
+ /**
1873
+ * Indicates that there was a problem with the connection to the Chroma server (e.g. the server is down or the client is not connected to the internet)
1874
+ */
1875
+ declare class ChromaConnectionError extends Error {
1876
+ readonly cause?: unknown | undefined;
1877
+ name: string;
1878
+ constructor(message: string, cause?: unknown | undefined);
1879
+ }
1880
+ /** Indicates that the server encountered an error while handling the request. */
1881
+ declare class ChromaServerError extends Error {
1882
+ readonly cause?: unknown | undefined;
1883
+ name: string;
1884
+ constructor(message: string, cause?: unknown | undefined);
1885
+ }
1886
+ /** Indicate that there was an issue with the request that the client made. */
1887
+ declare class ChromaClientError extends Error {
1888
+ readonly cause?: unknown | undefined;
1889
+ name: string;
1890
+ constructor(message: string, cause?: unknown | undefined);
1891
+ }
1892
+ /** The request lacked valid authentication. */
1893
+ declare class ChromaUnauthorizedError extends Error {
1894
+ readonly cause?: unknown | undefined;
1895
+ name: string;
1896
+ constructor(message: string, cause?: unknown | undefined);
1897
+ }
1898
+ /** The user does not have permission to access the requested resource. */
1899
+ declare class ChromaForbiddenError extends Error {
1900
+ readonly cause?: unknown | undefined;
1901
+ name: string;
1902
+ constructor(message: string, cause?: unknown | undefined);
1903
+ }
1904
+ declare class ChromaNotFoundError extends Error {
1905
+ readonly cause?: unknown | undefined;
1906
+ name: string;
1907
+ constructor(message: string, cause?: unknown | undefined);
1908
+ }
1909
+ declare class ChromaValueError extends Error {
1910
+ readonly cause?: unknown | undefined;
1911
+ name: string;
1912
+ constructor(message: string, cause?: unknown | undefined);
1913
+ }
1914
+ declare class InvalidCollectionError extends Error {
1915
+ readonly cause?: unknown | undefined;
1916
+ name: string;
1917
+ constructor(message: string, cause?: unknown | undefined);
1918
+ }
1919
+ declare class InvalidArgumentError extends Error {
1920
+ readonly cause?: unknown | undefined;
1921
+ name: string;
1922
+ constructor(message: string, cause?: unknown | undefined);
1923
+ }
1924
+ declare class ChromaUniqueError extends Error {
1925
+ readonly cause?: unknown | undefined;
1926
+ name: string;
1927
+ constructor(message: string, cause?: unknown | undefined);
1832
1928
  }
1929
+ declare function createErrorByType(type: string, message: string): InvalidCollectionError | InvalidArgumentError | undefined;
1833
1930
 
1834
- export { type AddRecordsParams, AdminClient, ChromaClient, type ChromaClientParams, CloudClient, CohereEmbeddingFunction, Collection, type CollectionMetadata, type CollectionParams, type CreateCollectionParams, DefaultEmbeddingFunction, type DeleteCollectionParams, type DeleteParams, type Document, type Documents, type Embedding, type Embeddings, type GetCollectionParams, type GetOrCreateCollectionParams, type GetParams, type GetResponse, GoogleGenerativeAiEmbeddingFunction, HuggingFaceEmbeddingServerFunction, type ID, type IDs, type IEmbeddingFunction, IncludeEnum, JinaEmbeddingFunction, type ListCollectionsParams, type Metadata, type Metadatas, type ModifyCollectionParams, OllamaEmbeddingFunction, OpenAIEmbeddingFunction, type PeekParams, type QueryRecordsParams, type QueryResponse, TransformersEmbeddingFunction, type UpdateRecordsParams, type UpsertRecordsParams, type Where, type WhereDocument };
1931
+ export { AddRecordsParams, AdminClient, ChromaClient, ChromaClientError, ChromaClientParams, ChromaConnectionError, ChromaError, ChromaForbiddenError, ChromaNotFoundError, ChromaServerError, ChromaUnauthorizedError, ChromaUniqueError, ChromaValueError, CloudClient, CohereEmbeddingFunction, Collection, CollectionMetadata, CollectionParams, CreateCollectionParams, DefaultEmbeddingFunction, DeleteCollectionParams, DeleteParams, Document, Documents, Embedding, Embeddings, GetCollectionParams, GetOrCreateCollectionParams, GetParams, GetResponse, GoogleGenerativeAiEmbeddingFunction, HuggingFaceEmbeddingServerFunction, ID, IDs, IEmbeddingFunction, IncludeEnum, InvalidArgumentError, InvalidCollectionError, JinaEmbeddingFunction, ListCollectionsParams, Metadata, Metadatas, ModifyCollectionParams, OllamaEmbeddingFunction, OpenAIEmbeddingFunction, PeekParams, QueryRecordsParams, QueryResponse, TransformersEmbeddingFunction, UpdateRecordsParams, UpsertRecordsParams, Where, WhereDocument, createErrorByType };
@@ -3386,15 +3386,15 @@ var ApiApi = class extends BaseAPI {
3386
3386
  // src/generated/models.ts
3387
3387
  var Api;
3388
3388
  ((Api2) => {
3389
- let IncludeEnum;
3390
- ((IncludeEnum2) => {
3391
- IncludeEnum2["Documents"] = "documents";
3392
- IncludeEnum2["Embeddings"] = "embeddings";
3393
- IncludeEnum2["Metadatas"] = "metadatas";
3394
- IncludeEnum2["Distances"] = "distances";
3395
- IncludeEnum2["Uris"] = "uris";
3396
- IncludeEnum2["Data"] = "data";
3397
- })(IncludeEnum = Api2.IncludeEnum || (Api2.IncludeEnum = {}));
3389
+ let IncludeEnum2;
3390
+ ((IncludeEnum3) => {
3391
+ IncludeEnum3["Documents"] = "documents";
3392
+ IncludeEnum3["Embeddings"] = "embeddings";
3393
+ IncludeEnum3["Metadatas"] = "metadatas";
3394
+ IncludeEnum3["Distances"] = "distances";
3395
+ IncludeEnum3["Uris"] = "uris";
3396
+ IncludeEnum3["Data"] = "data";
3397
+ })(IncludeEnum2 = Api2.IncludeEnum || (Api2.IncludeEnum = {}));
3398
3398
  })(Api || (Api = {}));
3399
3399
 
3400
3400
  // src/generated/configuration.ts
@@ -4267,12 +4267,12 @@ var AdminClient = class {
4267
4267
  name,
4268
4268
  tenantName
4269
4269
  }) {
4270
- const getDatabase = await this.api.getDatabase(
4270
+ const result = await this.api.getDatabase(
4271
4271
  name,
4272
4272
  tenantName,
4273
4273
  this.api.options
4274
4274
  );
4275
- return { name: getDatabase.name };
4275
+ return result;
4276
4276
  }
4277
4277
  /**
4278
4278
  * Deletes a database.
@@ -4305,13 +4305,12 @@ var AdminClient = class {
4305
4305
  offset,
4306
4306
  tenantName
4307
4307
  }) {
4308
- const listDatabases = await this.api.listDatabases(
4308
+ return await this.api.listDatabases(
4309
4309
  tenantName,
4310
4310
  limit,
4311
4311
  offset,
4312
4312
  this.api.options
4313
4313
  );
4314
- return listDatabases.map((db) => ({ name: db.name }));
4315
4314
  }
4316
4315
  };
4317
4316
 
@@ -4382,9 +4381,8 @@ var DefaultEmbeddingFunction = class _DefaultEmbeddingFunction {
4382
4381
  let importResult;
4383
4382
  if (isBrowser()) {
4384
4383
  importResult = await import(
4385
- // todo: we can't import chromadb-default-embed here yet because the `build` script was not run before publishing our fork to NPM, so the entrypoint in our forked package points to a non-existent file.
4386
4384
  // @ts-expect-error
4387
- "https://unpkg.com/@xenova/transformers@2.13.2"
4385
+ "https://unpkg.com/chromadb-default-embed@2.14.0"
4388
4386
  );
4389
4387
  } else {
4390
4388
  importResult = await import("chromadb-default-embed");
@@ -4616,7 +4614,7 @@ var ChromaClient = class {
4616
4614
  });
4617
4615
  }
4618
4616
  /**
4619
- * Lists all collections.
4617
+ * Get all collection names.
4620
4618
  *
4621
4619
  * @returns {Promise<string[]>} A promise that resolves to a list of collection names.
4622
4620
  * @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
@@ -4642,6 +4640,34 @@ var ChromaClient = class {
4642
4640
  );
4643
4641
  return collections.map((collection) => collection.name);
4644
4642
  }
4643
+ /**
4644
+ * List collection names, IDs, and metadata.
4645
+ *
4646
+ * @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
4647
+ * @param {PositiveInteger} [params.offset] - Optional offset on the items to get.
4648
+ * @throws {Error} If there is an issue listing the collections.
4649
+ * @returns {Promise<{ name: string, id: string, metadata?: CollectionMetadata }[]>} A promise that resolves to a list of collection names, IDs, and metadata.
4650
+ *
4651
+ * @example
4652
+ * ```typescript
4653
+ * const collections = await client.listCollectionsAndMetadata({
4654
+ * limit: 10,
4655
+ * offset: 0,
4656
+ * });
4657
+ */
4658
+ async listCollectionsAndMetadata({
4659
+ limit,
4660
+ offset
4661
+ } = {}) {
4662
+ await this.init();
4663
+ return await this.api.listCollections(
4664
+ this.tenant,
4665
+ this.database,
4666
+ limit,
4667
+ offset,
4668
+ this.api.options
4669
+ );
4670
+ }
4645
4671
  /**
4646
4672
  * Counts all collections.
4647
4673
  *
@@ -5130,44 +5156,93 @@ var GoogleGenerativeAiEmbeddingFunction = class _GoogleGenerativeAiEmbeddingFunc
5130
5156
  };
5131
5157
 
5132
5158
  // src/embeddings/OllamaEmbeddingFunction.ts
5133
- var OllamaEmbeddingFunction = class {
5134
- constructor({ url, model }) {
5135
- this.url = url;
5136
- this.model = model;
5159
+ var DEFAULT_MODEL = "chroma/all-minilm-l6-v2-f32";
5160
+ var DEFAULT_LOCAL_URL = "http://localhost:11434";
5161
+ var OllamaEmbeddingFunction = class _OllamaEmbeddingFunction {
5162
+ constructor({
5163
+ url = DEFAULT_LOCAL_URL,
5164
+ model = DEFAULT_MODEL
5165
+ } = {
5166
+ url: DEFAULT_LOCAL_URL,
5167
+ model: DEFAULT_MODEL
5168
+ }) {
5169
+ if (url && url.endsWith("/api/embeddings")) {
5170
+ this.url = url.slice(0, -"/api/embeddings".length);
5171
+ } else {
5172
+ this.url = url || DEFAULT_LOCAL_URL;
5173
+ }
5174
+ this.model = model || DEFAULT_MODEL;
5137
5175
  }
5138
- async generate(texts) {
5139
- let embeddings = [];
5140
- for (let text of texts) {
5141
- const response = await fetch(this.url, {
5142
- method: "POST",
5143
- headers: {
5144
- "Content-Type": "application/json"
5145
- },
5146
- body: JSON.stringify({ model: this.model, prompt: text })
5147
- });
5148
- if (!response.ok) {
5176
+ async initClient() {
5177
+ if (this.ollamaClient)
5178
+ return;
5179
+ try {
5180
+ const { ollama } = await _OllamaEmbeddingFunction.import();
5181
+ this.ollamaClient = new ollama.Ollama({ host: this.url });
5182
+ } catch (e) {
5183
+ if (e.code === "MODULE_NOT_FOUND") {
5149
5184
  throw new Error(
5150
- `Failed to generate embeddings: ${response.status} (${response.statusText})`
5185
+ "Please install the ollama package to use the OllamaEmbeddingFunction, `npm install -S ollama`"
5151
5186
  );
5152
5187
  }
5153
- let finalResponse = await response.json();
5154
- embeddings.push(finalResponse["embedding"]);
5188
+ throw e;
5155
5189
  }
5156
- return embeddings;
5190
+ }
5191
+ /** @ignore */
5192
+ static async import() {
5193
+ try {
5194
+ const { ollama } = await import("ollama").then((m) => ({ ollama: m }));
5195
+ return { ollama };
5196
+ } catch (e) {
5197
+ throw new Error(
5198
+ "Please install Ollama as a dependency with, e.g. `npm install ollama`"
5199
+ );
5200
+ }
5201
+ }
5202
+ async generate(texts) {
5203
+ await this.initClient();
5204
+ return await this.ollamaClient.embed({
5205
+ model: this.model,
5206
+ input: texts
5207
+ }).then((response) => {
5208
+ return response.embeddings;
5209
+ });
5157
5210
  }
5158
5211
  };
5212
+
5213
+ // src/types.ts
5214
+ var IncludeEnum = /* @__PURE__ */ ((IncludeEnum2) => {
5215
+ IncludeEnum2["Documents"] = "documents";
5216
+ IncludeEnum2["Embeddings"] = "embeddings";
5217
+ IncludeEnum2["Metadatas"] = "metadatas";
5218
+ IncludeEnum2["Distances"] = "distances";
5219
+ return IncludeEnum2;
5220
+ })(IncludeEnum || {});
5159
5221
  export {
5160
5222
  AdminClient,
5161
5223
  ChromaClient,
5224
+ ChromaClientError,
5225
+ ChromaConnectionError,
5226
+ ChromaError,
5227
+ ChromaForbiddenError,
5228
+ ChromaNotFoundError,
5229
+ ChromaServerError,
5230
+ ChromaUnauthorizedError,
5231
+ ChromaUniqueError,
5232
+ ChromaValueError,
5162
5233
  CloudClient,
5163
5234
  CohereEmbeddingFunction,
5164
5235
  Collection,
5165
5236
  DefaultEmbeddingFunction,
5166
5237
  GoogleGenerativeAiEmbeddingFunction,
5167
5238
  HuggingFaceEmbeddingServerFunction,
5239
+ IncludeEnum,
5240
+ InvalidArgumentError,
5241
+ InvalidCollectionError,
5168
5242
  JinaEmbeddingFunction,
5169
5243
  OllamaEmbeddingFunction,
5170
5244
  OpenAIEmbeddingFunction,
5171
- TransformersEmbeddingFunction
5245
+ TransformersEmbeddingFunction,
5246
+ createErrorByType
5172
5247
  };
5173
5248
  //# sourceMappingURL=chromadb.mjs.map
package/dist/chromadb.mjs CHANGED
@@ -3386,15 +3386,15 @@ var ApiApi = class extends BaseAPI {
3386
3386
  // src/generated/models.ts
3387
3387
  var Api;
3388
3388
  ((Api2) => {
3389
- let IncludeEnum;
3390
- ((IncludeEnum2) => {
3391
- IncludeEnum2["Documents"] = "documents";
3392
- IncludeEnum2["Embeddings"] = "embeddings";
3393
- IncludeEnum2["Metadatas"] = "metadatas";
3394
- IncludeEnum2["Distances"] = "distances";
3395
- IncludeEnum2["Uris"] = "uris";
3396
- IncludeEnum2["Data"] = "data";
3397
- })(IncludeEnum = Api2.IncludeEnum || (Api2.IncludeEnum = {}));
3389
+ let IncludeEnum2;
3390
+ ((IncludeEnum3) => {
3391
+ IncludeEnum3["Documents"] = "documents";
3392
+ IncludeEnum3["Embeddings"] = "embeddings";
3393
+ IncludeEnum3["Metadatas"] = "metadatas";
3394
+ IncludeEnum3["Distances"] = "distances";
3395
+ IncludeEnum3["Uris"] = "uris";
3396
+ IncludeEnum3["Data"] = "data";
3397
+ })(IncludeEnum2 = Api2.IncludeEnum || (Api2.IncludeEnum = {}));
3398
3398
  })(Api || (Api = {}));
3399
3399
 
3400
3400
  // src/generated/configuration.ts
@@ -4267,12 +4267,12 @@ var AdminClient = class {
4267
4267
  name,
4268
4268
  tenantName
4269
4269
  }) {
4270
- const getDatabase = await this.api.getDatabase(
4270
+ const result = await this.api.getDatabase(
4271
4271
  name,
4272
4272
  tenantName,
4273
4273
  this.api.options
4274
4274
  );
4275
- return { name: getDatabase.name };
4275
+ return result;
4276
4276
  }
4277
4277
  /**
4278
4278
  * Deletes a database.
@@ -4305,13 +4305,12 @@ var AdminClient = class {
4305
4305
  offset,
4306
4306
  tenantName
4307
4307
  }) {
4308
- const listDatabases = await this.api.listDatabases(
4308
+ return await this.api.listDatabases(
4309
4309
  tenantName,
4310
4310
  limit,
4311
4311
  offset,
4312
4312
  this.api.options
4313
4313
  );
4314
- return listDatabases.map((db) => ({ name: db.name }));
4315
4314
  }
4316
4315
  };
4317
4316
 
@@ -4382,9 +4381,8 @@ var DefaultEmbeddingFunction = class _DefaultEmbeddingFunction {
4382
4381
  let importResult;
4383
4382
  if (isBrowser()) {
4384
4383
  importResult = await import(
4385
- // todo: we can't import chromadb-default-embed here yet because the `build` script was not run before publishing our fork to NPM, so the entrypoint in our forked package points to a non-existent file.
4386
4384
  // @ts-expect-error
4387
- "https://unpkg.com/@xenova/transformers@2.13.2"
4385
+ "https://unpkg.com/chromadb-default-embed@2.14.0"
4388
4386
  );
4389
4387
  } else {
4390
4388
  importResult = await import("chromadb-default-embed");
@@ -4616,7 +4614,7 @@ var ChromaClient = class {
4616
4614
  });
4617
4615
  }
4618
4616
  /**
4619
- * Lists all collections.
4617
+ * Get all collection names.
4620
4618
  *
4621
4619
  * @returns {Promise<string[]>} A promise that resolves to a list of collection names.
4622
4620
  * @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
@@ -4642,6 +4640,34 @@ var ChromaClient = class {
4642
4640
  );
4643
4641
  return collections.map((collection) => collection.name);
4644
4642
  }
4643
+ /**
4644
+ * List collection names, IDs, and metadata.
4645
+ *
4646
+ * @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
4647
+ * @param {PositiveInteger} [params.offset] - Optional offset on the items to get.
4648
+ * @throws {Error} If there is an issue listing the collections.
4649
+ * @returns {Promise<{ name: string, id: string, metadata?: CollectionMetadata }[]>} A promise that resolves to a list of collection names, IDs, and metadata.
4650
+ *
4651
+ * @example
4652
+ * ```typescript
4653
+ * const collections = await client.listCollectionsAndMetadata({
4654
+ * limit: 10,
4655
+ * offset: 0,
4656
+ * });
4657
+ */
4658
+ async listCollectionsAndMetadata({
4659
+ limit,
4660
+ offset
4661
+ } = {}) {
4662
+ await this.init();
4663
+ return await this.api.listCollections(
4664
+ this.tenant,
4665
+ this.database,
4666
+ limit,
4667
+ offset,
4668
+ this.api.options
4669
+ );
4670
+ }
4645
4671
  /**
4646
4672
  * Counts all collections.
4647
4673
  *
@@ -5130,44 +5156,93 @@ var GoogleGenerativeAiEmbeddingFunction = class _GoogleGenerativeAiEmbeddingFunc
5130
5156
  };
5131
5157
 
5132
5158
  // src/embeddings/OllamaEmbeddingFunction.ts
5133
- var OllamaEmbeddingFunction = class {
5134
- constructor({ url, model }) {
5135
- this.url = url;
5136
- this.model = model;
5159
+ var DEFAULT_MODEL = "chroma/all-minilm-l6-v2-f32";
5160
+ var DEFAULT_LOCAL_URL = "http://localhost:11434";
5161
+ var OllamaEmbeddingFunction = class _OllamaEmbeddingFunction {
5162
+ constructor({
5163
+ url = DEFAULT_LOCAL_URL,
5164
+ model = DEFAULT_MODEL
5165
+ } = {
5166
+ url: DEFAULT_LOCAL_URL,
5167
+ model: DEFAULT_MODEL
5168
+ }) {
5169
+ if (url && url.endsWith("/api/embeddings")) {
5170
+ this.url = url.slice(0, -"/api/embeddings".length);
5171
+ } else {
5172
+ this.url = url || DEFAULT_LOCAL_URL;
5173
+ }
5174
+ this.model = model || DEFAULT_MODEL;
5137
5175
  }
5138
- async generate(texts) {
5139
- let embeddings = [];
5140
- for (let text of texts) {
5141
- const response = await fetch(this.url, {
5142
- method: "POST",
5143
- headers: {
5144
- "Content-Type": "application/json"
5145
- },
5146
- body: JSON.stringify({ model: this.model, prompt: text })
5147
- });
5148
- if (!response.ok) {
5176
+ async initClient() {
5177
+ if (this.ollamaClient)
5178
+ return;
5179
+ try {
5180
+ const { ollama } = await _OllamaEmbeddingFunction.import();
5181
+ this.ollamaClient = new ollama.Ollama({ host: this.url });
5182
+ } catch (e) {
5183
+ if (e.code === "MODULE_NOT_FOUND") {
5149
5184
  throw new Error(
5150
- `Failed to generate embeddings: ${response.status} (${response.statusText})`
5185
+ "Please install the ollama package to use the OllamaEmbeddingFunction, `npm install -S ollama`"
5151
5186
  );
5152
5187
  }
5153
- let finalResponse = await response.json();
5154
- embeddings.push(finalResponse["embedding"]);
5188
+ throw e;
5155
5189
  }
5156
- return embeddings;
5190
+ }
5191
+ /** @ignore */
5192
+ static async import() {
5193
+ try {
5194
+ const { ollama } = await import("ollama").then((m) => ({ ollama: m }));
5195
+ return { ollama };
5196
+ } catch (e) {
5197
+ throw new Error(
5198
+ "Please install Ollama as a dependency with, e.g. `npm install ollama`"
5199
+ );
5200
+ }
5201
+ }
5202
+ async generate(texts) {
5203
+ await this.initClient();
5204
+ return await this.ollamaClient.embed({
5205
+ model: this.model,
5206
+ input: texts
5207
+ }).then((response) => {
5208
+ return response.embeddings;
5209
+ });
5157
5210
  }
5158
5211
  };
5212
+
5213
+ // src/types.ts
5214
+ var IncludeEnum = /* @__PURE__ */ ((IncludeEnum2) => {
5215
+ IncludeEnum2["Documents"] = "documents";
5216
+ IncludeEnum2["Embeddings"] = "embeddings";
5217
+ IncludeEnum2["Metadatas"] = "metadatas";
5218
+ IncludeEnum2["Distances"] = "distances";
5219
+ return IncludeEnum2;
5220
+ })(IncludeEnum || {});
5159
5221
  export {
5160
5222
  AdminClient,
5161
5223
  ChromaClient,
5224
+ ChromaClientError,
5225
+ ChromaConnectionError,
5226
+ ChromaError,
5227
+ ChromaForbiddenError,
5228
+ ChromaNotFoundError,
5229
+ ChromaServerError,
5230
+ ChromaUnauthorizedError,
5231
+ ChromaUniqueError,
5232
+ ChromaValueError,
5162
5233
  CloudClient,
5163
5234
  CohereEmbeddingFunction,
5164
5235
  Collection,
5165
5236
  DefaultEmbeddingFunction,
5166
5237
  GoogleGenerativeAiEmbeddingFunction,
5167
5238
  HuggingFaceEmbeddingServerFunction,
5239
+ IncludeEnum,
5240
+ InvalidArgumentError,
5241
+ InvalidCollectionError,
5168
5242
  JinaEmbeddingFunction,
5169
5243
  OllamaEmbeddingFunction,
5170
5244
  OpenAIEmbeddingFunction,
5171
- TransformersEmbeddingFunction
5245
+ TransformersEmbeddingFunction,
5246
+ createErrorByType
5172
5247
  };
5173
5248
  //# sourceMappingURL=chromadb.mjs.map