chromadb 1.7.1-beta2 → 1.7.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.
@@ -1,5 +1,6 @@
1
1
  import * as openai from 'openai';
2
2
  import * as cohere_ai from 'cohere-ai';
3
+ import * as _google_generative_ai from '@google/generative-ai';
3
4
 
4
5
  /**
5
6
  * FastAPI
@@ -1211,6 +1212,16 @@ declare class AdminClient {
1211
1212
  }): Promise<Database>;
1212
1213
  }
1213
1214
 
1215
+ interface CloudClientParams {
1216
+ apiKey?: string;
1217
+ database?: string;
1218
+ cloudHost?: string;
1219
+ cloudPort?: string;
1220
+ }
1221
+ declare class CloudClient extends ChromaClient {
1222
+ constructor({ apiKey, database, cloudHost, cloudPort }: CloudClientParams);
1223
+ }
1224
+
1214
1225
  declare class OpenAIEmbeddingFunction implements IEmbeddingFunction {
1215
1226
  private api_key;
1216
1227
  private org_id;
@@ -1246,6 +1257,24 @@ declare class CohereEmbeddingFunction implements IEmbeddingFunction {
1246
1257
  }>;
1247
1258
  }
1248
1259
 
1260
+ declare class GoogleGenerativeAiEmbeddingFunction implements IEmbeddingFunction {
1261
+ private api_key;
1262
+ private model;
1263
+ private googleGenAiApi?;
1264
+ private taskType;
1265
+ constructor({ googleApiKey, model, taskType }: {
1266
+ googleApiKey: string;
1267
+ model?: string;
1268
+ taskType?: string;
1269
+ });
1270
+ private loadClient;
1271
+ generate(texts: string[]): Promise<any>;
1272
+ /** @ignore */
1273
+ static import(): Promise<{
1274
+ googleGenAi: typeof _google_generative_ai;
1275
+ }>;
1276
+ }
1277
+
1249
1278
  declare class HuggingFaceEmbeddingServerFunction implements IEmbeddingFunction {
1250
1279
  private url;
1251
1280
  constructor({ url }: {
@@ -1254,4 +1283,15 @@ declare class HuggingFaceEmbeddingServerFunction implements IEmbeddingFunction {
1254
1283
  generate(texts: string[]): Promise<any>;
1255
1284
  }
1256
1285
 
1257
- export { type AddParams, AdminClient, ChromaClient, type ChromaClientParams, CohereEmbeddingFunction, Collection, type CollectionMetadata, type CollectionType, type CreateCollectionParams, type DeleteCollectionParams, type DeleteParams, type Document, type Documents, type Embedding, type Embeddings, type GetCollectionParams, type GetOrCreateCollectionParams, type GetParams, type GetResponse, HuggingFaceEmbeddingServerFunction, type ID, type IDs, type IEmbeddingFunction, IncludeEnum, type ListCollectionsParams, type Metadata, type Metadatas, type ModifyCollectionParams, OpenAIEmbeddingFunction, type PeekParams, type QueryParams, type QueryResponse, type UpdateParams, type UpsertParams, type Where, type WhereDocument };
1286
+ declare class JinaEmbeddingFunction implements IEmbeddingFunction {
1287
+ private model_name;
1288
+ private api_url;
1289
+ private headers;
1290
+ constructor({ jinaai_api_key, model_name }: {
1291
+ jinaai_api_key: string;
1292
+ model_name?: string;
1293
+ });
1294
+ generate(texts: string[]): Promise<any[]>;
1295
+ }
1296
+
1297
+ export { AddParams, AdminClient, ChromaClient, ChromaClientParams, CloudClient, CohereEmbeddingFunction, Collection, CollectionMetadata, CollectionType, CreateCollectionParams, DeleteCollectionParams, DeleteParams, Document, Documents, Embedding, Embeddings, GetCollectionParams, GetOrCreateCollectionParams, GetParams, GetResponse, GoogleGenerativeAiEmbeddingFunction, HuggingFaceEmbeddingServerFunction, ID, IDs, IEmbeddingFunction, IncludeEnum, JinaEmbeddingFunction, ListCollectionsParams, Metadata, Metadatas, ModifyCollectionParams, OpenAIEmbeddingFunction, PeekParams, QueryParams, QueryResponse, UpdateParams, UpsertParams, Where, WhereDocument };
@@ -2825,6 +2825,32 @@ var ChromaClient = class {
2825
2825
  }
2826
2826
  };
2827
2827
 
2828
+ // src/CloudClient.ts
2829
+ var CloudClient = class extends ChromaClient {
2830
+ constructor({ apiKey, database, cloudHost, cloudPort }) {
2831
+ if (!apiKey) {
2832
+ apiKey = process.env.CHROMA_API_KEY;
2833
+ }
2834
+ if (!apiKey) {
2835
+ throw new Error("No API key provided");
2836
+ }
2837
+ cloudHost = cloudHost || "https://api.trychroma.com";
2838
+ cloudPort = cloudPort || "8000";
2839
+ const path = `${cloudHost}:${cloudPort}`;
2840
+ const auth = {
2841
+ provider: "token",
2842
+ credentials: apiKey,
2843
+ providerOptions: { headerType: "X_CHROMA_TOKEN" }
2844
+ };
2845
+ return new ChromaClient({
2846
+ path,
2847
+ auth,
2848
+ database
2849
+ });
2850
+ super();
2851
+ }
2852
+ };
2853
+
2828
2854
  // src/embeddings/OpenAIEmbeddingFunction.ts
2829
2855
  var OpenAIApi;
2830
2856
  var openAiVersion = null;
@@ -2965,6 +2991,55 @@ var CohereEmbeddingFunction = class _CohereEmbeddingFunction {
2965
2991
  }
2966
2992
  };
2967
2993
 
2994
+ // src/embeddings/GoogleGeminiEmbeddingFunction.ts
2995
+ var googleGenAiApi;
2996
+ var GoogleGenerativeAiEmbeddingFunction = class _GoogleGenerativeAiEmbeddingFunction {
2997
+ constructor({ googleApiKey, model, taskType }) {
2998
+ this.api_key = googleApiKey;
2999
+ this.model = model || "embedding-001";
3000
+ this.taskType = taskType || "RETRIEVAL_DOCUMENT";
3001
+ }
3002
+ async loadClient() {
3003
+ if (this.googleGenAiApi)
3004
+ return;
3005
+ try {
3006
+ const { googleGenAi } = await _GoogleGenerativeAiEmbeddingFunction.import();
3007
+ googleGenAiApi = googleGenAi;
3008
+ googleGenAiApi = new googleGenAiApi(this.api_key);
3009
+ } catch (_a) {
3010
+ if (_a.code === "MODULE_NOT_FOUND") {
3011
+ throw new Error("Please install the @google/generative-ai package to use the GoogleGenerativeAiEmbeddingFunction, `npm install -S @google/generative-ai`");
3012
+ }
3013
+ throw _a;
3014
+ }
3015
+ this.googleGenAiApi = googleGenAiApi;
3016
+ }
3017
+ async generate(texts) {
3018
+ await this.loadClient();
3019
+ const model = this.googleGenAiApi.getGenerativeModel({ model: this.model });
3020
+ const response = await model.batchEmbedContents({
3021
+ requests: texts.map((t) => ({
3022
+ content: { parts: [{ text: t }] },
3023
+ taskType: this.taskType
3024
+ }))
3025
+ });
3026
+ const embeddings = response.embeddings.map((e) => e.values);
3027
+ return embeddings;
3028
+ }
3029
+ /** @ignore */
3030
+ static async import() {
3031
+ try {
3032
+ const { GoogleGenerativeAI } = await import("@google/generative-ai");
3033
+ const googleGenAi = GoogleGenerativeAI;
3034
+ return { googleGenAi };
3035
+ } catch (e) {
3036
+ throw new Error(
3037
+ "Please install @google/generative-ai as a dependency with, e.g. `yarn add @google/generative-ai`"
3038
+ );
3039
+ }
3040
+ }
3041
+ };
3042
+
2968
3043
  // src/types.ts
2969
3044
  var IncludeEnum = /* @__PURE__ */ ((IncludeEnum2) => {
2970
3045
  IncludeEnum2["Documents"] = "documents";
@@ -2994,13 +3069,54 @@ var HuggingFaceEmbeddingServerFunction = class {
2994
3069
  return data;
2995
3070
  }
2996
3071
  };
3072
+
3073
+ // src/embeddings/JinaEmbeddingFunction.ts
3074
+ var JinaEmbeddingFunction = class {
3075
+ constructor({ jinaai_api_key, model_name }) {
3076
+ this.model_name = model_name || "jina-embeddings-v2-base-en";
3077
+ this.api_url = "https://api.jina.ai/v1/embeddings";
3078
+ this.headers = {
3079
+ Authorization: `Bearer ${jinaai_api_key}`,
3080
+ "Accept-Encoding": "identity",
3081
+ "Content-Type": "application/json"
3082
+ };
3083
+ }
3084
+ async generate(texts) {
3085
+ try {
3086
+ const response = await fetch(this.api_url, {
3087
+ method: "POST",
3088
+ headers: this.headers,
3089
+ body: JSON.stringify({
3090
+ input: texts,
3091
+ model: this.model_name
3092
+ })
3093
+ });
3094
+ const data = await response.json();
3095
+ if (!data || !data.data) {
3096
+ throw new Error(data.detail);
3097
+ }
3098
+ const embeddings = data.data;
3099
+ const sortedEmbeddings = embeddings.sort((a, b) => a.index - b.index);
3100
+ return sortedEmbeddings.map((result) => result.embedding);
3101
+ } catch (error) {
3102
+ if (error instanceof Error) {
3103
+ throw new Error(`Error calling Jina AI API: ${error.message}`);
3104
+ } else {
3105
+ throw new Error(`Error calling Jina AI API: ${error}`);
3106
+ }
3107
+ }
3108
+ }
3109
+ };
2997
3110
  export {
2998
3111
  AdminClient,
2999
3112
  ChromaClient,
3113
+ CloudClient,
3000
3114
  CohereEmbeddingFunction,
3001
3115
  Collection,
3116
+ GoogleGenerativeAiEmbeddingFunction,
3002
3117
  HuggingFaceEmbeddingServerFunction,
3003
3118
  IncludeEnum,
3119
+ JinaEmbeddingFunction,
3004
3120
  OpenAIEmbeddingFunction
3005
3121
  };
3006
3122
  //# sourceMappingURL=chromadb.mjs.map
package/dist/chromadb.mjs CHANGED
@@ -2825,6 +2825,32 @@ var ChromaClient = class {
2825
2825
  }
2826
2826
  };
2827
2827
 
2828
+ // src/CloudClient.ts
2829
+ var CloudClient = class extends ChromaClient {
2830
+ constructor({ apiKey, database, cloudHost, cloudPort }) {
2831
+ if (!apiKey) {
2832
+ apiKey = process.env.CHROMA_API_KEY;
2833
+ }
2834
+ if (!apiKey) {
2835
+ throw new Error("No API key provided");
2836
+ }
2837
+ cloudHost = cloudHost || "https://api.trychroma.com";
2838
+ cloudPort = cloudPort || "8000";
2839
+ const path = `${cloudHost}:${cloudPort}`;
2840
+ const auth = {
2841
+ provider: "token",
2842
+ credentials: apiKey,
2843
+ providerOptions: { headerType: "X_CHROMA_TOKEN" }
2844
+ };
2845
+ return new ChromaClient({
2846
+ path,
2847
+ auth,
2848
+ database
2849
+ });
2850
+ super();
2851
+ }
2852
+ };
2853
+
2828
2854
  // src/embeddings/OpenAIEmbeddingFunction.ts
2829
2855
  var OpenAIApi;
2830
2856
  var openAiVersion = null;
@@ -2965,6 +2991,55 @@ var CohereEmbeddingFunction = class _CohereEmbeddingFunction {
2965
2991
  }
2966
2992
  };
2967
2993
 
2994
+ // src/embeddings/GoogleGeminiEmbeddingFunction.ts
2995
+ var googleGenAiApi;
2996
+ var GoogleGenerativeAiEmbeddingFunction = class _GoogleGenerativeAiEmbeddingFunction {
2997
+ constructor({ googleApiKey, model, taskType }) {
2998
+ this.api_key = googleApiKey;
2999
+ this.model = model || "embedding-001";
3000
+ this.taskType = taskType || "RETRIEVAL_DOCUMENT";
3001
+ }
3002
+ async loadClient() {
3003
+ if (this.googleGenAiApi)
3004
+ return;
3005
+ try {
3006
+ const { googleGenAi } = await _GoogleGenerativeAiEmbeddingFunction.import();
3007
+ googleGenAiApi = googleGenAi;
3008
+ googleGenAiApi = new googleGenAiApi(this.api_key);
3009
+ } catch (_a) {
3010
+ if (_a.code === "MODULE_NOT_FOUND") {
3011
+ throw new Error("Please install the @google/generative-ai package to use the GoogleGenerativeAiEmbeddingFunction, `npm install -S @google/generative-ai`");
3012
+ }
3013
+ throw _a;
3014
+ }
3015
+ this.googleGenAiApi = googleGenAiApi;
3016
+ }
3017
+ async generate(texts) {
3018
+ await this.loadClient();
3019
+ const model = this.googleGenAiApi.getGenerativeModel({ model: this.model });
3020
+ const response = await model.batchEmbedContents({
3021
+ requests: texts.map((t) => ({
3022
+ content: { parts: [{ text: t }] },
3023
+ taskType: this.taskType
3024
+ }))
3025
+ });
3026
+ const embeddings = response.embeddings.map((e) => e.values);
3027
+ return embeddings;
3028
+ }
3029
+ /** @ignore */
3030
+ static async import() {
3031
+ try {
3032
+ const { GoogleGenerativeAI } = await import("@google/generative-ai");
3033
+ const googleGenAi = GoogleGenerativeAI;
3034
+ return { googleGenAi };
3035
+ } catch (e) {
3036
+ throw new Error(
3037
+ "Please install @google/generative-ai as a dependency with, e.g. `yarn add @google/generative-ai`"
3038
+ );
3039
+ }
3040
+ }
3041
+ };
3042
+
2968
3043
  // src/types.ts
2969
3044
  var IncludeEnum = /* @__PURE__ */ ((IncludeEnum2) => {
2970
3045
  IncludeEnum2["Documents"] = "documents";
@@ -2994,13 +3069,54 @@ var HuggingFaceEmbeddingServerFunction = class {
2994
3069
  return data;
2995
3070
  }
2996
3071
  };
3072
+
3073
+ // src/embeddings/JinaEmbeddingFunction.ts
3074
+ var JinaEmbeddingFunction = class {
3075
+ constructor({ jinaai_api_key, model_name }) {
3076
+ this.model_name = model_name || "jina-embeddings-v2-base-en";
3077
+ this.api_url = "https://api.jina.ai/v1/embeddings";
3078
+ this.headers = {
3079
+ Authorization: `Bearer ${jinaai_api_key}`,
3080
+ "Accept-Encoding": "identity",
3081
+ "Content-Type": "application/json"
3082
+ };
3083
+ }
3084
+ async generate(texts) {
3085
+ try {
3086
+ const response = await fetch(this.api_url, {
3087
+ method: "POST",
3088
+ headers: this.headers,
3089
+ body: JSON.stringify({
3090
+ input: texts,
3091
+ model: this.model_name
3092
+ })
3093
+ });
3094
+ const data = await response.json();
3095
+ if (!data || !data.data) {
3096
+ throw new Error(data.detail);
3097
+ }
3098
+ const embeddings = data.data;
3099
+ const sortedEmbeddings = embeddings.sort((a, b) => a.index - b.index);
3100
+ return sortedEmbeddings.map((result) => result.embedding);
3101
+ } catch (error) {
3102
+ if (error instanceof Error) {
3103
+ throw new Error(`Error calling Jina AI API: ${error.message}`);
3104
+ } else {
3105
+ throw new Error(`Error calling Jina AI API: ${error}`);
3106
+ }
3107
+ }
3108
+ }
3109
+ };
2997
3110
  export {
2998
3111
  AdminClient,
2999
3112
  ChromaClient,
3113
+ CloudClient,
3000
3114
  CohereEmbeddingFunction,
3001
3115
  Collection,
3116
+ GoogleGenerativeAiEmbeddingFunction,
3002
3117
  HuggingFaceEmbeddingServerFunction,
3003
3118
  IncludeEnum,
3119
+ JinaEmbeddingFunction,
3004
3120
  OpenAIEmbeddingFunction
3005
3121
  };
3006
3122
  //# sourceMappingURL=chromadb.mjs.map