chromadb 1.4.2 → 1.5.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.
Files changed (69) hide show
  1. package/dist/main/ChromaClient.d.ts +163 -0
  2. package/dist/main/ChromaClient.d.ts.map +1 -0
  3. package/dist/main/ChromaClient.js +204 -0
  4. package/dist/main/ChromaClient.js.map +1 -0
  5. package/dist/main/Collection.d.ts +249 -0
  6. package/dist/main/Collection.d.ts.map +1 -0
  7. package/dist/main/Collection.js +396 -0
  8. package/dist/main/Collection.js.map +1 -0
  9. package/dist/main/embeddings/CohereEmbeddingFunction.d.ts +11 -0
  10. package/dist/main/embeddings/CohereEmbeddingFunction.d.ts.map +1 -0
  11. package/dist/main/embeddings/CohereEmbeddingFunction.js +26 -0
  12. package/dist/main/embeddings/CohereEmbeddingFunction.js.map +1 -0
  13. package/dist/main/embeddings/IEmbeddingFunction.d.ts +4 -0
  14. package/dist/main/embeddings/IEmbeddingFunction.d.ts.map +1 -0
  15. package/dist/main/embeddings/IEmbeddingFunction.js +3 -0
  16. package/dist/main/embeddings/IEmbeddingFunction.js.map +1 -0
  17. package/dist/main/embeddings/OpenAIEmbeddingFunction.d.ts +13 -0
  18. package/dist/main/embeddings/OpenAIEmbeddingFunction.d.ts.map +1 -0
  19. package/dist/main/embeddings/OpenAIEmbeddingFunction.js +37 -0
  20. package/dist/main/embeddings/OpenAIEmbeddingFunction.js.map +1 -0
  21. package/dist/main/index.d.ts +5 -427
  22. package/dist/main/index.d.ts.map +1 -1
  23. package/dist/main/index.js +9 -705
  24. package/dist/main/index.js.map +1 -1
  25. package/dist/main/types.d.ts +10 -5
  26. package/dist/main/types.d.ts.map +1 -1
  27. package/dist/main/utils.d.ts +10 -0
  28. package/dist/main/utils.d.ts.map +1 -0
  29. package/dist/main/utils.js +71 -0
  30. package/dist/main/utils.js.map +1 -0
  31. package/dist/module/ChromaClient.d.ts +163 -0
  32. package/dist/module/ChromaClient.d.ts.map +1 -0
  33. package/dist/module/ChromaClient.js +200 -0
  34. package/dist/module/ChromaClient.js.map +1 -0
  35. package/dist/module/Collection.d.ts +249 -0
  36. package/dist/module/Collection.d.ts.map +1 -0
  37. package/dist/module/Collection.js +392 -0
  38. package/dist/module/Collection.js.map +1 -0
  39. package/dist/module/embeddings/CohereEmbeddingFunction.d.ts +11 -0
  40. package/dist/module/embeddings/CohereEmbeddingFunction.d.ts.map +1 -0
  41. package/dist/module/embeddings/CohereEmbeddingFunction.js +22 -0
  42. package/dist/module/embeddings/CohereEmbeddingFunction.js.map +1 -0
  43. package/dist/module/embeddings/IEmbeddingFunction.d.ts +4 -0
  44. package/dist/module/embeddings/IEmbeddingFunction.d.ts.map +1 -0
  45. package/dist/module/embeddings/IEmbeddingFunction.js +2 -0
  46. package/dist/module/embeddings/IEmbeddingFunction.js.map +1 -0
  47. package/dist/module/embeddings/OpenAIEmbeddingFunction.d.ts +13 -0
  48. package/dist/module/embeddings/OpenAIEmbeddingFunction.d.ts.map +1 -0
  49. package/dist/module/embeddings/OpenAIEmbeddingFunction.js +33 -0
  50. package/dist/module/embeddings/OpenAIEmbeddingFunction.js.map +1 -0
  51. package/dist/module/index.d.ts +5 -427
  52. package/dist/module/index.d.ts.map +1 -1
  53. package/dist/module/index.js +4 -700
  54. package/dist/module/index.js.map +1 -1
  55. package/dist/module/types.d.ts +10 -5
  56. package/dist/module/types.d.ts.map +1 -1
  57. package/dist/module/utils.d.ts +10 -0
  58. package/dist/module/utils.d.ts.map +1 -0
  59. package/dist/module/utils.js +63 -0
  60. package/dist/module/utils.js.map +1 -0
  61. package/package.json +1 -1
  62. package/src/ChromaClient.ts +260 -0
  63. package/src/Collection.ts +573 -0
  64. package/src/embeddings/CohereEmbeddingFunction.ts +29 -0
  65. package/src/embeddings/IEmbeddingFunction.ts +3 -0
  66. package/src/embeddings/OpenAIEmbeddingFunction.ts +48 -0
  67. package/src/index.ts +5 -569
  68. package/src/types.ts +68 -0
  69. package/src/utils.ts +65 -0
@@ -0,0 +1,163 @@
1
+ import { IEmbeddingFunction } from './embeddings/IEmbeddingFunction';
2
+ import { Api } from "./generated";
3
+ import { Collection } from './Collection';
4
+ import { CollectionMetadata, CollectionType } from './types';
5
+ export declare class ChromaClient {
6
+ /**
7
+ * @ignore
8
+ */
9
+ private api;
10
+ /**
11
+ * Creates a new ChromaClient instance.
12
+ * @param {Object} params - The parameters for creating a new client
13
+ * @param {string} [params.path] - The base path for the Chroma API.
14
+ * @returns {ChromaClient} A new ChromaClient instance.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const client = new ChromaClient({
19
+ * path: "http://localhost:8000"
20
+ * });
21
+ * ```
22
+ */
23
+ constructor({ path }?: {
24
+ path?: string;
25
+ });
26
+ /**
27
+ * Resets the state of the object by making an API call to the reset endpoint.
28
+ *
29
+ * @returns {Promise<Api.Reset200Response>} A promise that resolves when the reset operation is complete.
30
+ * @throws {Error} If there is an issue resetting the state.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * await client.reset();
35
+ * ```
36
+ */
37
+ reset(): Promise<Api.Reset200Response>;
38
+ /**
39
+ * Returns the version of the Chroma API.
40
+ * @returns {Promise<string>} A promise that resolves to the version of the Chroma API.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const version = await client.version();
45
+ * ```
46
+ */
47
+ version(): Promise<string>;
48
+ /**
49
+ * Returns a heartbeat from the Chroma API.
50
+ * @returns {Promise<number>} A promise that resolves to the heartbeat from the Chroma API.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const heartbeat = await client.heartbeat();
55
+ * ```
56
+ */
57
+ heartbeat(): Promise<number>;
58
+ /**
59
+ * @ignore
60
+ */
61
+ persist(): Promise<never>;
62
+ /**
63
+ * Creates a new collection with the specified properties.
64
+ *
65
+ * @param {Object} params - The parameters for creating a new collection.
66
+ * @param {string} params.name - The name of the collection.
67
+ * @param {CollectionMetadata} [params.metadata] - Optional metadata associated with the collection.
68
+ * @param {IEmbeddingFunction} [params.embeddingFunction] - Optional custom embedding function for the collection.
69
+ *
70
+ * @returns {Promise<Collection>} A promise that resolves to the created collection.
71
+ * @throws {Error} If there is an issue creating the collection.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const collection = await client.createCollection({
76
+ * name: "my_collection",
77
+ * metadata: {
78
+ * "description": "My first collection"
79
+ * }
80
+ * });
81
+ * ```
82
+ */
83
+ createCollection({ name, metadata, embeddingFunction }: {
84
+ name: string;
85
+ metadata?: CollectionMetadata;
86
+ embeddingFunction?: IEmbeddingFunction;
87
+ }): Promise<Collection>;
88
+ /**
89
+ * Gets or creates a collection with the specified properties.
90
+ *
91
+ * @param {Object} params - The parameters for creating a new collection.
92
+ * @param {string} params.name - The name of the collection.
93
+ * @param {CollectionMetadata} [params.metadata] - Optional metadata associated with the collection.
94
+ * @param {IEmbeddingFunction} [params.embeddingFunction] - Optional custom embedding function for the collection.
95
+ *
96
+ * @returns {Promise<Collection>} A promise that resolves to the got or created collection.
97
+ * @throws {Error} If there is an issue getting or creating the collection.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const collection = await client.getOrCreateCollection({
102
+ * name: "my_collection",
103
+ * metadata: {
104
+ * "description": "My first collection"
105
+ * }
106
+ * });
107
+ * ```
108
+ */
109
+ getOrCreateCollection({ name, metadata, embeddingFunction }: {
110
+ name: string;
111
+ metadata?: CollectionMetadata;
112
+ embeddingFunction?: IEmbeddingFunction;
113
+ }): Promise<Collection>;
114
+ /**
115
+ * Lists all collections.
116
+ *
117
+ * @returns {Promise<CollectionType[]>} A promise that resolves to a list of collection names.
118
+ * @throws {Error} If there is an issue listing the collections.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const collections = await client.listCollections();
123
+ * ```
124
+ */
125
+ listCollections(): Promise<CollectionType[]>;
126
+ /**
127
+ * Gets a collection with the specified name.
128
+ * @param {Object} params - The parameters for getting a collection.
129
+ * @param {string} params.name - The name of the collection.
130
+ * @param {IEmbeddingFunction} [params.embeddingFunction] - Optional custom embedding function for the collection.
131
+ * @returns {Promise<Collection>} A promise that resolves to the collection.
132
+ * @throws {Error} If there is an issue getting the collection.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const collection = await client.getCollection({
137
+ * name: "my_collection"
138
+ * });
139
+ * ```
140
+ */
141
+ getCollection({ name, embeddingFunction }: {
142
+ name: string;
143
+ embeddingFunction?: IEmbeddingFunction;
144
+ }): Promise<Collection>;
145
+ /**
146
+ * Deletes a collection with the specified name.
147
+ * @param {Object} params - The parameters for deleting a collection.
148
+ * @param {string} params.name - The name of the collection.
149
+ * @returns {Promise<void>} A promise that resolves when the collection is deleted.
150
+ * @throws {Error} If there is an issue deleting the collection.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * await client.deleteCollection({
155
+ * name: "my_collection"
156
+ * });
157
+ * ```
158
+ */
159
+ deleteCollection({ name }: {
160
+ name: string;
161
+ }): Promise<void>;
162
+ }
163
+ //# sourceMappingURL=ChromaClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChromaClient.d.ts","sourceRoot":"","sources":["../../src/ChromaClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAuC,GAAG,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG7D,qBAAa,YAAY;IACrB;;OAEG;IACH,OAAO,CAAC,GAAG,CAAa;IAExB;;;;;;;;;;;;OAYG;gBACS,EAAE,IAAI,EAAE,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO;IAQ5C;;;;;;;;;;OAUG;IACU,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAInD;;;;;;;;OAQG;IACU,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAKvC;;;;;;;;OAQG;IACU,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAMzC;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC;IAItC;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,gBAAgB,CAAC,EAC1B,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACpB,EAAE;QACC,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,kBAAkB,CAAC;QAC9B,iBAAiB,CAAC,EAAE,kBAAkB,CAAA;KACzC,GAAG,OAAO,CAAC,UAAU,CAAC;IAgBvB;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,qBAAqB,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACpB,EAAE;QACC,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,kBAAkB,CAAC;QAC9B,iBAAiB,CAAC,EAAE,kBAAkB,CAAA;KACzC,GAAG,OAAO,CAAC,UAAU,CAAC;IAuBvB;;;;;;;;;;OAUG;IACU,eAAe,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAKzD;;;;;;;;;;;;;;OAcG;IACU,aAAa,CAAC,EACvB,IAAI,EACJ,iBAAiB,EACpB,EAAE;QACC,IAAI,EAAE,MAAM,CAAC;QACb,iBAAiB,CAAC,EAAE,kBAAkB,CAAA;KACzC,GAAG,OAAO,CAAC,UAAU,CAAC;IAevB;;;;;;;;;;;;;OAaG;IACU,gBAAgB,CAAC,EAC1B,IAAI,EACP,EAAE;QACC,IAAI,EAAE,MAAM,CAAA;KACf,GAAG,OAAO,CAAC,IAAI,CAAC;CAOpB"}
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChromaClient = void 0;
4
+ const generated_1 = require("./generated");
5
+ const utils_1 = require("./utils");
6
+ const Collection_1 = require("./Collection");
7
+ class ChromaClient {
8
+ /**
9
+ * Creates a new ChromaClient instance.
10
+ * @param {Object} params - The parameters for creating a new client
11
+ * @param {string} [params.path] - The base path for the Chroma API.
12
+ * @returns {ChromaClient} A new ChromaClient instance.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const client = new ChromaClient({
17
+ * path: "http://localhost:8000"
18
+ * });
19
+ * ```
20
+ */
21
+ constructor({ path } = {}) {
22
+ if (path === undefined)
23
+ path = "http://localhost:8000";
24
+ const apiConfig = new generated_1.Configuration({
25
+ basePath: path,
26
+ });
27
+ this.api = new generated_1.ApiApi(apiConfig);
28
+ }
29
+ /**
30
+ * Resets the state of the object by making an API call to the reset endpoint.
31
+ *
32
+ * @returns {Promise<Api.Reset200Response>} A promise that resolves when the reset operation is complete.
33
+ * @throws {Error} If there is an issue resetting the state.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * await client.reset();
38
+ * ```
39
+ */
40
+ async reset() {
41
+ return await this.api.reset();
42
+ }
43
+ /**
44
+ * Returns the version of the Chroma API.
45
+ * @returns {Promise<string>} A promise that resolves to the version of the Chroma API.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const version = await client.version();
50
+ * ```
51
+ */
52
+ async version() {
53
+ const response = await this.api.version();
54
+ return await (0, utils_1.handleSuccess)(response);
55
+ }
56
+ /**
57
+ * Returns a heartbeat from the Chroma API.
58
+ * @returns {Promise<number>} A promise that resolves to the heartbeat from the Chroma API.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const heartbeat = await client.heartbeat();
63
+ * ```
64
+ */
65
+ async heartbeat() {
66
+ const response = await this.api.heartbeat();
67
+ let ret = await (0, utils_1.handleSuccess)(response);
68
+ return ret["nanosecond heartbeat"];
69
+ }
70
+ /**
71
+ * @ignore
72
+ */
73
+ async persist() {
74
+ throw new Error("Not implemented in JS client");
75
+ }
76
+ /**
77
+ * Creates a new collection with the specified properties.
78
+ *
79
+ * @param {Object} params - The parameters for creating a new collection.
80
+ * @param {string} params.name - The name of the collection.
81
+ * @param {CollectionMetadata} [params.metadata] - Optional metadata associated with the collection.
82
+ * @param {IEmbeddingFunction} [params.embeddingFunction] - Optional custom embedding function for the collection.
83
+ *
84
+ * @returns {Promise<Collection>} A promise that resolves to the created collection.
85
+ * @throws {Error} If there is an issue creating the collection.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const collection = await client.createCollection({
90
+ * name: "my_collection",
91
+ * metadata: {
92
+ * "description": "My first collection"
93
+ * }
94
+ * });
95
+ * ```
96
+ */
97
+ async createCollection({ name, metadata, embeddingFunction }) {
98
+ const newCollection = await this.api
99
+ .createCollection({
100
+ name,
101
+ metadata,
102
+ })
103
+ .then(utils_1.handleSuccess)
104
+ .catch(utils_1.handleError);
105
+ if (newCollection.error) {
106
+ throw new Error(newCollection.error);
107
+ }
108
+ return new Collection_1.Collection(name, newCollection.id, this.api, metadata, embeddingFunction);
109
+ }
110
+ /**
111
+ * Gets or creates a collection with the specified properties.
112
+ *
113
+ * @param {Object} params - The parameters for creating a new collection.
114
+ * @param {string} params.name - The name of the collection.
115
+ * @param {CollectionMetadata} [params.metadata] - Optional metadata associated with the collection.
116
+ * @param {IEmbeddingFunction} [params.embeddingFunction] - Optional custom embedding function for the collection.
117
+ *
118
+ * @returns {Promise<Collection>} A promise that resolves to the got or created collection.
119
+ * @throws {Error} If there is an issue getting or creating the collection.
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const collection = await client.getOrCreateCollection({
124
+ * name: "my_collection",
125
+ * metadata: {
126
+ * "description": "My first collection"
127
+ * }
128
+ * });
129
+ * ```
130
+ */
131
+ async getOrCreateCollection({ name, metadata, embeddingFunction }) {
132
+ const newCollection = await this.api
133
+ .createCollection({
134
+ name,
135
+ metadata,
136
+ 'get_or_create': true
137
+ })
138
+ .then(utils_1.handleSuccess)
139
+ .catch(utils_1.handleError);
140
+ if (newCollection.error) {
141
+ throw new Error(newCollection.error);
142
+ }
143
+ return new Collection_1.Collection(name, newCollection.id, this.api, newCollection.metadata, embeddingFunction);
144
+ }
145
+ /**
146
+ * Lists all collections.
147
+ *
148
+ * @returns {Promise<CollectionType[]>} A promise that resolves to a list of collection names.
149
+ * @throws {Error} If there is an issue listing the collections.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const collections = await client.listCollections();
154
+ * ```
155
+ */
156
+ async listCollections() {
157
+ const response = await this.api.listCollections();
158
+ return (0, utils_1.handleSuccess)(response);
159
+ }
160
+ /**
161
+ * Gets a collection with the specified name.
162
+ * @param {Object} params - The parameters for getting a collection.
163
+ * @param {string} params.name - The name of the collection.
164
+ * @param {IEmbeddingFunction} [params.embeddingFunction] - Optional custom embedding function for the collection.
165
+ * @returns {Promise<Collection>} A promise that resolves to the collection.
166
+ * @throws {Error} If there is an issue getting the collection.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * const collection = await client.getCollection({
171
+ * name: "my_collection"
172
+ * });
173
+ * ```
174
+ */
175
+ async getCollection({ name, embeddingFunction }) {
176
+ const response = await this.api
177
+ .getCollection(name)
178
+ .then(utils_1.handleSuccess)
179
+ .catch(utils_1.handleError);
180
+ return new Collection_1.Collection(response.name, response.id, this.api, response.metadata, embeddingFunction);
181
+ }
182
+ /**
183
+ * Deletes a collection with the specified name.
184
+ * @param {Object} params - The parameters for deleting a collection.
185
+ * @param {string} params.name - The name of the collection.
186
+ * @returns {Promise<void>} A promise that resolves when the collection is deleted.
187
+ * @throws {Error} If there is an issue deleting the collection.
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * await client.deleteCollection({
192
+ * name: "my_collection"
193
+ * });
194
+ * ```
195
+ */
196
+ async deleteCollection({ name }) {
197
+ return await this.api
198
+ .deleteCollection(name)
199
+ .then(utils_1.handleSuccess)
200
+ .catch(utils_1.handleError);
201
+ }
202
+ }
203
+ exports.ChromaClient = ChromaClient;
204
+ //# sourceMappingURL=ChromaClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChromaClient.js","sourceRoot":"","sources":["../../src/ChromaClient.ts"],"names":[],"mappings":";;;AACA,2CAAuE;AACvE,mCAAqD;AACrD,6CAA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AAI,uBAAU,CACjB,QAAQ,CAAC,IAAI,EACb,QAAQ,CAAC,EAAE,EACX,IAAI,CAAC,GAAG,EACR,QAAQ,CAAC,QAAQ,EACjB,iBAAiB,CACpB,CAAC;IACN,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,KAAK,CAAC,gBAAgB,CAAC,EAC1B,IAAI,EAGP;QACG,OAAO,MAAM,IAAI,CAAC,GAAG;aAChB,gBAAgB,CAAC,IAAI,CAAC;aACtB,IAAI,CAAC,qBAAa,CAAC;aACnB,KAAK,CAAC,mBAAW,CAAC,CAAC;IAC5B,CAAC;CAEJ;AA5PD,oCA4PC"}
@@ -0,0 +1,249 @@
1
+ import { IncludeEnum, Metadata, Metadatas, Embedding, Embeddings, Document, Documents, Where, WhereDocument, ID, IDs, PositiveInteger, GetResponse, QueryResponse, AddResponse, CollectionMetadata } from "./types";
2
+ import { IEmbeddingFunction } from './embeddings/IEmbeddingFunction';
3
+ import { ApiApi as DefaultApi } from "./generated";
4
+ export declare class Collection {
5
+ name: string;
6
+ id: string;
7
+ metadata: CollectionMetadata | undefined;
8
+ /**
9
+ * @ignore
10
+ */
11
+ private api;
12
+ /**
13
+ * @ignore
14
+ */
15
+ embeddingFunction: IEmbeddingFunction | undefined;
16
+ /**
17
+ * @ignore
18
+ */
19
+ constructor(name: string, id: string, api: DefaultApi, metadata?: CollectionMetadata, embeddingFunction?: IEmbeddingFunction);
20
+ /**
21
+ * @ignore
22
+ */
23
+ private setName;
24
+ /**
25
+ * @ignore
26
+ */
27
+ private setMetadata;
28
+ /**
29
+ * @ignore
30
+ */
31
+ private validate;
32
+ /**
33
+ * Add items to the collection
34
+ * @param {Object} params - The parameters for the query.
35
+ * @param {ID | IDs} [params.ids] - IDs of the items to add.
36
+ * @param {Embedding | Embeddings} [params.embeddings] - Optional embeddings of the items to add.
37
+ * @param {Metadata | Metadatas} [params.metadatas] - Optional metadata of the items to add.
38
+ * @param {Document | Documents} [params.documents] - Optional documents of the items to add.
39
+ * @returns {Promise<AddResponse>} - The response from the API. True if successful.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const response = await collection.add({
44
+ * ids: ["id1", "id2"],
45
+ * embeddings: [[1, 2, 3], [4, 5, 6]],
46
+ * metadatas: [{ "key": "value" }, { "key": "value" }],
47
+ * documents: ["document1", "document2"]
48
+ * });
49
+ * ```
50
+ */
51
+ add({ ids, embeddings, metadatas, documents, }: {
52
+ ids: ID | IDs;
53
+ embeddings?: Embedding | Embeddings;
54
+ metadatas?: Metadata | Metadatas;
55
+ documents?: Document | Documents;
56
+ }): Promise<AddResponse>;
57
+ /**
58
+ * Upsert items to the collection
59
+ * @param {Object} params - The parameters for the query.
60
+ * @param {ID | IDs} [params.ids] - IDs of the items to add.
61
+ * @param {Embedding | Embeddings} [params.embeddings] - Optional embeddings of the items to add.
62
+ * @param {Metadata | Metadatas} [params.metadatas] - Optional metadata of the items to add.
63
+ * @param {Document | Documents} [params.documents] - Optional documents of the items to add.
64
+ * @returns {Promise<boolean>} - The response from the API. True if successful.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const response = await collection.upsert({
69
+ * ids: ["id1", "id2"],
70
+ * embeddings: [[1, 2, 3], [4, 5, 6]],
71
+ * metadatas: [{ "key": "value" }, { "key": "value" }],
72
+ * documents: ["document1", "document2"],
73
+ * });
74
+ * ```
75
+ */
76
+ upsert({ ids, embeddings, metadatas, documents, }: {
77
+ ids: ID | IDs;
78
+ embeddings?: Embedding | Embeddings;
79
+ metadatas?: Metadata | Metadatas;
80
+ documents?: Document | Documents;
81
+ }): Promise<boolean>;
82
+ /**
83
+ * Count the number of items in the collection
84
+ * @returns {Promise<number>} - The response from the API.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const response = await collection.count();
89
+ * ```
90
+ */
91
+ count(): Promise<number>;
92
+ /**
93
+ * Modify the collection name or metadata
94
+ * @param {Object} params - The parameters for the query.
95
+ * @param {string} [params.name] - Optional new name for the collection.
96
+ * @param {CollectionMetadata} [params.metadata] - Optional new metadata for the collection.
97
+ * @returns {Promise<void>} - The response from the API.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const response = await collection.modify({
102
+ * name: "new name",
103
+ * metadata: { "key": "value" },
104
+ * });
105
+ * ```
106
+ */
107
+ modify({ name, metadata }?: {
108
+ name?: string;
109
+ metadata?: CollectionMetadata;
110
+ }): Promise<void>;
111
+ /**
112
+ * Get items from the collection
113
+ * @param {Object} params - The parameters for the query.
114
+ * @param {ID | IDs} [params.ids] - Optional IDs of the items to get.
115
+ * @param {Where} [params.where] - Optional where clause to filter items by.
116
+ * @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
117
+ * @param {PositiveInteger} [params.offset] - Optional offset on the items to get.
118
+ * @param {IncludeEnum[]} [params.include] - Optional list of items to include in the response.
119
+ * @param {WhereDocument} [params.whereDocument] - Optional where clause to filter items by.
120
+ * @returns {Promise<GetResponse>} - The response from the server.
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const response = await collection.get({
125
+ * ids: ["id1", "id2"],
126
+ * where: { "key": "value" },
127
+ * limit: 10,
128
+ * offset: 0,
129
+ * include: ["embeddings", "metadatas", "documents"],
130
+ * whereDocument: { $contains: "value" },
131
+ * });
132
+ * ```
133
+ */
134
+ get({ ids, where, limit, offset, include, whereDocument, }?: {
135
+ ids?: ID | IDs;
136
+ where?: Where;
137
+ limit?: PositiveInteger;
138
+ offset?: PositiveInteger;
139
+ include?: IncludeEnum[];
140
+ whereDocument?: WhereDocument;
141
+ }): Promise<GetResponse>;
142
+ /**
143
+ * Update the embeddings, documents, and/or metadatas of existing items
144
+ * @param {Object} params - The parameters for the query.
145
+ * @param {ID | IDs} [params.ids] - The IDs of the items to update.
146
+ * @param {Embedding | Embeddings} [params.embeddings] - Optional embeddings to update.
147
+ * @param {Metadata | Metadatas} [params.metadatas] - Optional metadatas to update.
148
+ * @param {Document | Documents} [params.documents] - Optional documents to update.
149
+ * @returns {Promise<boolean>} - The API Response. True if successful. Else, error.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const response = await collection.update({
154
+ * ids: ["id1", "id2"],
155
+ * embeddings: [[1, 2, 3], [4, 5, 6]],
156
+ * metadatas: [{ "key": "value" }, { "key": "value" }],
157
+ * documents: ["new document 1", "new document 2"],
158
+ * });
159
+ * ```
160
+ */
161
+ update({ ids, embeddings, metadatas, documents, }: {
162
+ ids: ID | IDs;
163
+ embeddings?: Embedding | Embeddings;
164
+ metadatas?: Metadata | Metadatas;
165
+ documents?: Document | Documents;
166
+ }): Promise<boolean>;
167
+ /**
168
+ * Performs a query on the collection using the specified parameters.
169
+ *
170
+ * @param {Object} params - The parameters for the query.
171
+ * @param {Embedding | Embeddings} [params.queryEmbeddings] - Optional query embeddings to use for the search.
172
+ * @param {PositiveInteger} [params.nResults] - Optional number of results to return (default is 10).
173
+ * @param {Where} [params.where] - Optional query condition to filter results based on metadata values.
174
+ * @param {string | string[]} [params.queryTexts] - Optional query text(s) to search for in the collection.
175
+ * @param {WhereDocument} [params.whereDocument] - Optional query condition to filter results based on document content.
176
+ * @param {IncludeEnum[]} [params.include] - Optional array of fields to include in the result, such as "metadata" and "document".
177
+ *
178
+ * @returns {Promise<QueryResponse>} A promise that resolves to the query results.
179
+ * @throws {Error} If there is an issue executing the query.
180
+ * @example
181
+ * // Query the collection using embeddings
182
+ * const results = await collection.query({
183
+ * queryEmbeddings: [[0.1, 0.2, ...], ...],
184
+ * nResults: 10,
185
+ * where: {"name": {"$eq": "John Doe"}},
186
+ * include: ["metadata", "document"]
187
+ * });
188
+ * @example
189
+ * ```js
190
+ * // Query the collection using query text
191
+ * const results = await collection.query({
192
+ * queryTexts: "some text",
193
+ * nResults: 10,
194
+ * where: {"name": {"$eq": "John Doe"}},
195
+ * include: ["metadata", "document"]
196
+ * });
197
+ * ```
198
+ *
199
+ */
200
+ query({ queryEmbeddings, nResults, where, queryTexts, whereDocument, include, }: {
201
+ queryEmbeddings?: Embedding | Embeddings;
202
+ nResults?: PositiveInteger;
203
+ where?: Where;
204
+ queryTexts?: string | string[];
205
+ whereDocument?: WhereDocument;
206
+ include?: IncludeEnum[];
207
+ }): Promise<QueryResponse>;
208
+ /**
209
+ * Peek inside the collection
210
+ * @param {Object} params - The parameters for the query.
211
+ * @param {PositiveInteger} [params.limit] - Optional number of results to return (default is 10).
212
+ * @returns {Promise<GetResponse>} A promise that resolves to the query results.
213
+ * @throws {Error} If there is an issue executing the query.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * const results = await collection.peek({
218
+ * limit: 10
219
+ * });
220
+ * ```
221
+ */
222
+ peek({ limit }?: {
223
+ limit?: PositiveInteger;
224
+ }): Promise<GetResponse>;
225
+ /**
226
+ * Deletes items from the collection.
227
+ * @param {Object} params - The parameters for deleting items from the collection.
228
+ * @param {ID | IDs} [params.ids] - Optional ID or array of IDs of items to delete.
229
+ * @param {Where} [params.where] - Optional query condition to filter items to delete based on metadata values.
230
+ * @param {WhereDocument} [params.whereDocument] - Optional query condition to filter items to delete based on document content.
231
+ * @returns {Promise<string[]>} A promise that resolves to the IDs of the deleted items.
232
+ * @throws {Error} If there is an issue deleting items from the collection.
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const results = await collection.delete({
237
+ * ids: "some_id",
238
+ * where: {"name": {"$eq": "John Doe"}},
239
+ * whereDocument: {"$contains":"search_string"}
240
+ * });
241
+ * ```
242
+ */
243
+ delete({ ids, where, whereDocument }?: {
244
+ ids?: ID | IDs;
245
+ where?: Where;
246
+ whereDocument?: WhereDocument;
247
+ }): Promise<string[]>;
248
+ }
249
+ //# sourceMappingURL=Collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../src/Collection.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,QAAQ,EACR,SAAS,EACT,KAAK,EACL,aAAa,EACb,EAAE,EACF,GAAG,EACH,eAAe,EACf,W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