@sprucelabs/chroma-data-store 0.3.47 → 1.0.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.
- package/README.md +1 -1
- package/build/ChromaDatabase.d.ts +1 -1
- package/build/ChromaDatabase.js +8 -6
- package/build/chroma.types.d.ts +21 -174
- package/build/esm/ChromaDatabase.d.ts +1 -1
- package/build/esm/ChromaDatabase.js +8 -6
- package/build/esm/chroma.types.d.ts +21 -174
- package/package.json +17 -16
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ By default, the ChromaDabatase class will use llama3.2 hosted through Ollama to
|
|
|
22
22
|
Llama 3.2 is the newest version of Llama (as of this writing) that supports embeddings.
|
|
23
23
|
|
|
24
24
|
1. Inside of terminal, run `ollama run llama3.2`
|
|
25
|
-
2. You should be able to visit http://localhost:11434/api/embeddings and get a
|
|
25
|
+
2. You should be able to visit http://localhost:11434/api/embeddings and get a 405 response (this is because the route only accepts POST requests)
|
|
26
26
|
|
|
27
27
|
### Improving embeddings with `nomic-embed-text`
|
|
28
28
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateOptions, Database, DatabaseInternalOptions, Index, IndexWithFilter, QueryOptions } from '@sprucelabs/data-stores';
|
|
2
|
-
import { OllamaEmbeddingFunction } from '
|
|
2
|
+
import { OllamaEmbeddingFunction } from '@chroma-core/ollama';
|
|
3
3
|
export default class ChromaDatabase implements Database {
|
|
4
4
|
static Class?: new (connectionString: string) => Database;
|
|
5
5
|
static EmbeddingFunction: typeof OllamaEmbeddingFunction;
|
package/build/ChromaDatabase.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const data_stores_1 = require("@sprucelabs/data-stores");
|
|
7
7
|
const schema_1 = require("@sprucelabs/schema");
|
|
8
8
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
9
|
+
const ollama_1 = require("@chroma-core/ollama");
|
|
9
10
|
const chromadb_1 = require("chromadb");
|
|
10
11
|
const SpruceError_1 = __importDefault(require("./errors/SpruceError"));
|
|
11
12
|
class ChromaDatabase {
|
|
@@ -15,7 +16,7 @@ class ChromaDatabase {
|
|
|
15
16
|
(0, schema_1.assertOptions)({ connectionString }, ['connectionString']);
|
|
16
17
|
this.embeddings = new ChromaDatabase.EmbeddingFunction({
|
|
17
18
|
model: process.env.CHROMA_EMBEDDING_MODEL ?? 'llama3.2',
|
|
18
|
-
url: 'http://localhost:11434
|
|
19
|
+
url: 'http://localhost:11434',
|
|
19
20
|
});
|
|
20
21
|
if (!connectionString.startsWith('chroma://')) {
|
|
21
22
|
throw new data_stores_1.DataStoresError({
|
|
@@ -180,7 +181,7 @@ class ChromaDatabase {
|
|
|
180
181
|
}
|
|
181
182
|
async dropDatabase() {
|
|
182
183
|
const collections = await this.client.listCollections();
|
|
183
|
-
await Promise.all(collections.map((col) => this.dropCollection(col)));
|
|
184
|
+
await Promise.all(collections.map((col) => this.dropCollection(col.name)));
|
|
184
185
|
}
|
|
185
186
|
async findOne(collection, query, options, dbOptions) {
|
|
186
187
|
const matches = await this.find(collection, query, { ...options, limit: 1 }, dbOptions);
|
|
@@ -199,7 +200,9 @@ class ChromaDatabase {
|
|
|
199
200
|
const queryResults = await col.query({
|
|
200
201
|
queryTexts: [$prompt],
|
|
201
202
|
nResults: limit,
|
|
202
|
-
where: Object.keys(rest).length > 0
|
|
203
|
+
where: (Object.keys(rest).length > 0
|
|
204
|
+
? rest
|
|
205
|
+
: undefined),
|
|
203
206
|
});
|
|
204
207
|
matches = {
|
|
205
208
|
ids: queryResults.ids[0],
|
|
@@ -210,7 +213,7 @@ class ChromaDatabase {
|
|
|
210
213
|
matches = await col.get({
|
|
211
214
|
ids,
|
|
212
215
|
include: ['metadatas'],
|
|
213
|
-
where,
|
|
216
|
+
where: where,
|
|
214
217
|
limit: limit == 0 ? 1 : limit,
|
|
215
218
|
});
|
|
216
219
|
}
|
|
@@ -264,7 +267,6 @@ class ChromaDatabase {
|
|
|
264
267
|
where = rest;
|
|
265
268
|
}
|
|
266
269
|
if (where?.$or && where.$or.length === 1) {
|
|
267
|
-
//@ts-ignore
|
|
268
270
|
where = where.$or[0];
|
|
269
271
|
}
|
|
270
272
|
if (where) {
|
|
@@ -394,5 +396,5 @@ class ChromaDatabase {
|
|
|
394
396
|
});
|
|
395
397
|
}
|
|
396
398
|
}
|
|
397
|
-
ChromaDatabase.EmbeddingFunction =
|
|
399
|
+
ChromaDatabase.EmbeddingFunction = ollama_1.OllamaEmbeddingFunction;
|
|
398
400
|
exports.default = ChromaDatabase;
|
package/build/chroma.types.d.ts
CHANGED
|
@@ -1,177 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @returns {Promise<void>}
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const response = await collection.upsert({
|
|
16
|
-
* ids: ["id1", "id2"],
|
|
17
|
-
* embeddings: [[1, 2, 3], [4, 5, 6]],
|
|
18
|
-
* metadatas: [{ "key": "value" }, { "key": "value" }],
|
|
19
|
-
* documents: ["document1", "document2"],
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
upsert(params: UpsertRecordsParams): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* Count the number of items in the collection
|
|
26
|
-
* @returns {Promise<number>} - The number of items in the collection.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* const count = await collection.count();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
count(): Promise<number>;
|
|
34
|
-
/**
|
|
35
|
-
* Get items from the collection
|
|
36
|
-
* @param {Object} params - The parameters for the query.
|
|
37
|
-
* @param {ID | IDs} [params.ids] - Optional IDs of the items to get.
|
|
38
|
-
* @param {Where} [params.where] - Optional where clause to filter items by.
|
|
39
|
-
* @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
|
|
40
|
-
* @param {PositiveInteger} [params.offset] - Optional offset on the items to get.
|
|
41
|
-
* @param {IncludeEnum[]} [params.include] - Optional list of items to include in the response.
|
|
42
|
-
* @param {WhereDocument} [params.whereDocument] - Optional where clause to filter items by.
|
|
43
|
-
* @returns {Promise<GetResponse>} - The response from the server.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* const response = await collection.get({
|
|
48
|
-
* ids: ["id1", "id2"],
|
|
49
|
-
* where: { "key": "value" },
|
|
50
|
-
* limit: 10,
|
|
51
|
-
* offset: 0,
|
|
52
|
-
* include: ["embeddings", "metadatas", "documents"],
|
|
53
|
-
* whereDocument: { $contains: "value" },
|
|
54
|
-
* });
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
get(options?: BaseGetParams): Promise<GetResponse>;
|
|
58
|
-
/**
|
|
59
|
-
* Update items in the collection
|
|
60
|
-
* @param {Object} params - The parameters for the query.
|
|
61
|
-
* @param {ID | IDs} [params.ids] - IDs of the items to add.
|
|
62
|
-
* @param {Embedding | Embeddings} [params.embeddings] - Optional embeddings of the items to add.
|
|
63
|
-
* @param {Metadata | Metadatas} [params.metadatas] - Optional metadata of the items to add.
|
|
64
|
-
* @param {Document | Documents} [params.documents] - Optional documents of the items to add.
|
|
65
|
-
* @returns {Promise<void>}
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const response = await collection.update({
|
|
70
|
-
* ids: ["id1", "id2"],
|
|
71
|
-
* embeddings: [[1, 2, 3], [4, 5, 6]],
|
|
72
|
-
* metadatas: [{ "key": "value" }, { "key": "value" }],
|
|
73
|
-
* documents: ["document1", "document2"],
|
|
74
|
-
* });
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
update(params: UpdateRecordsParams): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* Performs a query on the collection using the specified parameters.
|
|
80
|
-
*
|
|
81
|
-
* @param {Object} params - The parameters for the query.
|
|
82
|
-
* @param {Embedding | Embeddings} [params.queryEmbeddings] - Optional query embeddings to use for the search.
|
|
83
|
-
* @param {PositiveInteger} [params.nResults] - Optional number of results to return (default is 10).
|
|
84
|
-
* @param {Where} [params.where] - Optional query condition to filter results based on metadata values.
|
|
85
|
-
* @param {string | string[]} [params.queryTexts] - Optional query text(s) to search for in the collection.
|
|
86
|
-
* @param {WhereDocument} [params.whereDocument] - Optional query condition to filter results based on document content.
|
|
87
|
-
* @param {IncludeEnum[]} [params.include] - Optional array of fields to include in the result, such as "metadata" and "document".
|
|
88
|
-
*
|
|
89
|
-
* @returns {Promise<QueryResponse>} A promise that resolves to the query results.
|
|
90
|
-
* @throws {Error} If there is an issue executing the query.
|
|
91
|
-
* @example
|
|
92
|
-
* // Query the collection using embeddings
|
|
93
|
-
* const results = await collection.query({
|
|
94
|
-
* queryEmbeddings: [[0.1, 0.2, ...], ...],
|
|
95
|
-
* nResults: 10,
|
|
96
|
-
* where: {"name": {"$eq": "John Doe"}},
|
|
97
|
-
* include: ["metadata", "document"]
|
|
98
|
-
* });
|
|
99
|
-
* @example
|
|
100
|
-
* ```js
|
|
101
|
-
* // Query the collection using query text
|
|
102
|
-
* const results = await collection.query({
|
|
103
|
-
* queryTexts: "some text",
|
|
104
|
-
* nResults: 10,
|
|
105
|
-
* where: {"name": {"$eq": "John Doe"}},
|
|
106
|
-
* include: ["metadata", "document"]
|
|
107
|
-
* });
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
|
-
query({ nResults, where, whereDocument, include, queryTexts, queryEmbeddings, }: QueryRecordsParams): Promise<QueryResponse>;
|
|
112
|
-
/**
|
|
113
|
-
* Modify the collection name or metadata
|
|
114
|
-
* @param {Object} params - The parameters for the query.
|
|
115
|
-
* @param {string} [params.name] - Optional new name for the collection.
|
|
116
|
-
* @param {CollectionMetadata} [params.metadata] - Optional new metadata for the collection.
|
|
117
|
-
* @returns {Promise<void>} - The response from the API.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* const response = await client.updateCollection({
|
|
122
|
-
* name: "new name",
|
|
123
|
-
* metadata: { "key": "value" },
|
|
124
|
-
* });
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
modify({ name, metadata, }: {
|
|
128
|
-
name?: string;
|
|
129
|
-
metadata?: CollectionMetadata;
|
|
130
|
-
}): Promise<CollectionParams>;
|
|
131
|
-
/**
|
|
132
|
-
* Peek inside the collection
|
|
133
|
-
* @param {Object} params - The parameters for the query.
|
|
134
|
-
* @param {PositiveInteger} [params.limit] - Optional number of results to return (default is 10).
|
|
135
|
-
* @returns {Promise<GetResponse>} A promise that resolves to the query results.
|
|
136
|
-
* @throws {Error} If there is an issue executing the query.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* const results = await collection.peek({
|
|
141
|
-
* limit: 10
|
|
142
|
-
* });
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
peek(options?: PeekParams): Promise<GetResponse>;
|
|
146
|
-
/**
|
|
147
|
-
* Deletes items from the collection.
|
|
148
|
-
* @param {Object} params - The parameters for deleting items from the collection.
|
|
149
|
-
* @param {ID | IDs} [params.ids] - Optional ID or array of IDs of items to delete.
|
|
150
|
-
* @param {Where} [params.where] - Optional query condition to filter items to delete based on metadata values.
|
|
151
|
-
* @param {WhereDocument} [params.whereDocument] - Optional query condition to filter items to delete based on document content.
|
|
152
|
-
* @returns {Promise<string[]>} A promise that resolves to the IDs of the deleted items.
|
|
153
|
-
* @throws {Error} If there is an issue deleting items from the collection.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```typescript
|
|
157
|
-
* const results = await collection.delete({
|
|
158
|
-
* ids: "some_id",
|
|
159
|
-
* where: {"name": {"$eq": "John Doe"}},
|
|
160
|
-
* whereDocument: {"$contains":"search_string"}
|
|
161
|
-
* });
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
delete(options?: DeleteParams): Promise<void>;
|
|
1
|
+
import { IncludeEnum, Metadata } from 'chromadb';
|
|
2
|
+
export type ID = string;
|
|
3
|
+
export type Embedding = number[];
|
|
4
|
+
export type Embeddings = Embedding[];
|
|
5
|
+
export interface GetResponse {
|
|
6
|
+
ids: ID[];
|
|
7
|
+
embeddings: Embeddings | null;
|
|
8
|
+
documents: (Document | null)[];
|
|
9
|
+
metadatas: (Metadata | null)[];
|
|
10
|
+
included: IncludeEnum[];
|
|
165
11
|
}
|
|
166
|
-
|
|
167
|
-
ids?: ID | IDs;
|
|
168
|
-
where?: Where;
|
|
169
|
-
limit?: number;
|
|
170
|
-
offset?: number;
|
|
171
|
-
include?: IncludeEnum[];
|
|
172
|
-
whereDocument?: WhereDocument;
|
|
173
|
-
}
|
|
174
|
-
export type WhereWithPrompt = Where & {
|
|
12
|
+
export type WhereWithPrompt = WhereDocument & {
|
|
175
13
|
$prompt?: string;
|
|
176
14
|
};
|
|
177
|
-
export {
|
|
15
|
+
export interface WhereDocument {
|
|
16
|
+
$contains?: string;
|
|
17
|
+
$not_contains?: string;
|
|
18
|
+
$matches?: string;
|
|
19
|
+
$not_matches?: string;
|
|
20
|
+
$regex?: string;
|
|
21
|
+
$not_regex?: string;
|
|
22
|
+
$and?: WhereDocument[];
|
|
23
|
+
$or?: WhereDocument[];
|
|
24
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateOptions, Database, DatabaseInternalOptions, Index, IndexWithFilter, QueryOptions } from '@sprucelabs/data-stores';
|
|
2
|
-
import { OllamaEmbeddingFunction } from '
|
|
2
|
+
import { OllamaEmbeddingFunction } from '@chroma-core/ollama';
|
|
3
3
|
export default class ChromaDatabase implements Database {
|
|
4
4
|
static Class?: new (connectionString: string) => Database;
|
|
5
5
|
static EmbeddingFunction: typeof OllamaEmbeddingFunction;
|
|
@@ -21,7 +21,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
import { DataStoresError, generateId, } from '@sprucelabs/data-stores';
|
|
22
22
|
import { assertOptions, flattenValues, expandValues } from '@sprucelabs/schema';
|
|
23
23
|
import { NULL_PLACEHOLDER } from '@sprucelabs/test-utils';
|
|
24
|
-
import {
|
|
24
|
+
import { OllamaEmbeddingFunction } from '@chroma-core/ollama';
|
|
25
|
+
import { ChromaClient, } from 'chromadb';
|
|
25
26
|
import SpruceError from './errors/SpruceError.js';
|
|
26
27
|
class ChromaDatabase {
|
|
27
28
|
constructor(connectionString) {
|
|
@@ -31,7 +32,7 @@ class ChromaDatabase {
|
|
|
31
32
|
assertOptions({ connectionString }, ['connectionString']);
|
|
32
33
|
this.embeddings = new ChromaDatabase.EmbeddingFunction({
|
|
33
34
|
model: (_a = process.env.CHROMA_EMBEDDING_MODEL) !== null && _a !== void 0 ? _a : 'llama3.2',
|
|
34
|
-
url: 'http://localhost:11434
|
|
35
|
+
url: 'http://localhost:11434',
|
|
35
36
|
});
|
|
36
37
|
if (!connectionString.startsWith('chroma://')) {
|
|
37
38
|
throw new DataStoresError({
|
|
@@ -221,7 +222,7 @@ class ChromaDatabase {
|
|
|
221
222
|
dropDatabase() {
|
|
222
223
|
return __awaiter(this, void 0, void 0, function* () {
|
|
223
224
|
const collections = yield this.client.listCollections();
|
|
224
|
-
yield Promise.all(collections.map((col) => this.dropCollection(col)));
|
|
225
|
+
yield Promise.all(collections.map((col) => this.dropCollection(col.name)));
|
|
225
226
|
});
|
|
226
227
|
}
|
|
227
228
|
findOne(collection, query, options, dbOptions) {
|
|
@@ -245,7 +246,9 @@ class ChromaDatabase {
|
|
|
245
246
|
const queryResults = yield col.query({
|
|
246
247
|
queryTexts: [$prompt],
|
|
247
248
|
nResults: limit,
|
|
248
|
-
where: Object.keys(rest).length > 0
|
|
249
|
+
where: (Object.keys(rest).length > 0
|
|
250
|
+
? rest
|
|
251
|
+
: undefined),
|
|
249
252
|
});
|
|
250
253
|
matches = {
|
|
251
254
|
ids: queryResults.ids[0],
|
|
@@ -256,7 +259,7 @@ class ChromaDatabase {
|
|
|
256
259
|
matches = yield col.get({
|
|
257
260
|
ids,
|
|
258
261
|
include: ['metadatas'],
|
|
259
|
-
where,
|
|
262
|
+
where: where,
|
|
260
263
|
limit: limit == 0 ? 1 : limit,
|
|
261
264
|
});
|
|
262
265
|
}
|
|
@@ -309,7 +312,6 @@ class ChromaDatabase {
|
|
|
309
312
|
where = rest;
|
|
310
313
|
}
|
|
311
314
|
if ((where === null || where === void 0 ? void 0 : where.$or) && where.$or.length === 1) {
|
|
312
|
-
//@ts-ignore
|
|
313
315
|
where = where.$or[0];
|
|
314
316
|
}
|
|
315
317
|
if (where) {
|
|
@@ -1,177 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @returns {Promise<void>}
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const response = await collection.upsert({
|
|
16
|
-
* ids: ["id1", "id2"],
|
|
17
|
-
* embeddings: [[1, 2, 3], [4, 5, 6]],
|
|
18
|
-
* metadatas: [{ "key": "value" }, { "key": "value" }],
|
|
19
|
-
* documents: ["document1", "document2"],
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
upsert(params: UpsertRecordsParams): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* Count the number of items in the collection
|
|
26
|
-
* @returns {Promise<number>} - The number of items in the collection.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* const count = await collection.count();
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
count(): Promise<number>;
|
|
34
|
-
/**
|
|
35
|
-
* Get items from the collection
|
|
36
|
-
* @param {Object} params - The parameters for the query.
|
|
37
|
-
* @param {ID | IDs} [params.ids] - Optional IDs of the items to get.
|
|
38
|
-
* @param {Where} [params.where] - Optional where clause to filter items by.
|
|
39
|
-
* @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
|
|
40
|
-
* @param {PositiveInteger} [params.offset] - Optional offset on the items to get.
|
|
41
|
-
* @param {IncludeEnum[]} [params.include] - Optional list of items to include in the response.
|
|
42
|
-
* @param {WhereDocument} [params.whereDocument] - Optional where clause to filter items by.
|
|
43
|
-
* @returns {Promise<GetResponse>} - The response from the server.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* const response = await collection.get({
|
|
48
|
-
* ids: ["id1", "id2"],
|
|
49
|
-
* where: { "key": "value" },
|
|
50
|
-
* limit: 10,
|
|
51
|
-
* offset: 0,
|
|
52
|
-
* include: ["embeddings", "metadatas", "documents"],
|
|
53
|
-
* whereDocument: { $contains: "value" },
|
|
54
|
-
* });
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
get(options?: BaseGetParams): Promise<GetResponse>;
|
|
58
|
-
/**
|
|
59
|
-
* Update items in the collection
|
|
60
|
-
* @param {Object} params - The parameters for the query.
|
|
61
|
-
* @param {ID | IDs} [params.ids] - IDs of the items to add.
|
|
62
|
-
* @param {Embedding | Embeddings} [params.embeddings] - Optional embeddings of the items to add.
|
|
63
|
-
* @param {Metadata | Metadatas} [params.metadatas] - Optional metadata of the items to add.
|
|
64
|
-
* @param {Document | Documents} [params.documents] - Optional documents of the items to add.
|
|
65
|
-
* @returns {Promise<void>}
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const response = await collection.update({
|
|
70
|
-
* ids: ["id1", "id2"],
|
|
71
|
-
* embeddings: [[1, 2, 3], [4, 5, 6]],
|
|
72
|
-
* metadatas: [{ "key": "value" }, { "key": "value" }],
|
|
73
|
-
* documents: ["document1", "document2"],
|
|
74
|
-
* });
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
update(params: UpdateRecordsParams): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* Performs a query on the collection using the specified parameters.
|
|
80
|
-
*
|
|
81
|
-
* @param {Object} params - The parameters for the query.
|
|
82
|
-
* @param {Embedding | Embeddings} [params.queryEmbeddings] - Optional query embeddings to use for the search.
|
|
83
|
-
* @param {PositiveInteger} [params.nResults] - Optional number of results to return (default is 10).
|
|
84
|
-
* @param {Where} [params.where] - Optional query condition to filter results based on metadata values.
|
|
85
|
-
* @param {string | string[]} [params.queryTexts] - Optional query text(s) to search for in the collection.
|
|
86
|
-
* @param {WhereDocument} [params.whereDocument] - Optional query condition to filter results based on document content.
|
|
87
|
-
* @param {IncludeEnum[]} [params.include] - Optional array of fields to include in the result, such as "metadata" and "document".
|
|
88
|
-
*
|
|
89
|
-
* @returns {Promise<QueryResponse>} A promise that resolves to the query results.
|
|
90
|
-
* @throws {Error} If there is an issue executing the query.
|
|
91
|
-
* @example
|
|
92
|
-
* // Query the collection using embeddings
|
|
93
|
-
* const results = await collection.query({
|
|
94
|
-
* queryEmbeddings: [[0.1, 0.2, ...], ...],
|
|
95
|
-
* nResults: 10,
|
|
96
|
-
* where: {"name": {"$eq": "John Doe"}},
|
|
97
|
-
* include: ["metadata", "document"]
|
|
98
|
-
* });
|
|
99
|
-
* @example
|
|
100
|
-
* ```js
|
|
101
|
-
* // Query the collection using query text
|
|
102
|
-
* const results = await collection.query({
|
|
103
|
-
* queryTexts: "some text",
|
|
104
|
-
* nResults: 10,
|
|
105
|
-
* where: {"name": {"$eq": "John Doe"}},
|
|
106
|
-
* include: ["metadata", "document"]
|
|
107
|
-
* });
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
|
-
query({ nResults, where, whereDocument, include, queryTexts, queryEmbeddings, }: QueryRecordsParams): Promise<QueryResponse>;
|
|
112
|
-
/**
|
|
113
|
-
* Modify the collection name or metadata
|
|
114
|
-
* @param {Object} params - The parameters for the query.
|
|
115
|
-
* @param {string} [params.name] - Optional new name for the collection.
|
|
116
|
-
* @param {CollectionMetadata} [params.metadata] - Optional new metadata for the collection.
|
|
117
|
-
* @returns {Promise<void>} - The response from the API.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* const response = await client.updateCollection({
|
|
122
|
-
* name: "new name",
|
|
123
|
-
* metadata: { "key": "value" },
|
|
124
|
-
* });
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
modify({ name, metadata, }: {
|
|
128
|
-
name?: string;
|
|
129
|
-
metadata?: CollectionMetadata;
|
|
130
|
-
}): Promise<CollectionParams>;
|
|
131
|
-
/**
|
|
132
|
-
* Peek inside the collection
|
|
133
|
-
* @param {Object} params - The parameters for the query.
|
|
134
|
-
* @param {PositiveInteger} [params.limit] - Optional number of results to return (default is 10).
|
|
135
|
-
* @returns {Promise<GetResponse>} A promise that resolves to the query results.
|
|
136
|
-
* @throws {Error} If there is an issue executing the query.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* const results = await collection.peek({
|
|
141
|
-
* limit: 10
|
|
142
|
-
* });
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
peek(options?: PeekParams): Promise<GetResponse>;
|
|
146
|
-
/**
|
|
147
|
-
* Deletes items from the collection.
|
|
148
|
-
* @param {Object} params - The parameters for deleting items from the collection.
|
|
149
|
-
* @param {ID | IDs} [params.ids] - Optional ID or array of IDs of items to delete.
|
|
150
|
-
* @param {Where} [params.where] - Optional query condition to filter items to delete based on metadata values.
|
|
151
|
-
* @param {WhereDocument} [params.whereDocument] - Optional query condition to filter items to delete based on document content.
|
|
152
|
-
* @returns {Promise<string[]>} A promise that resolves to the IDs of the deleted items.
|
|
153
|
-
* @throws {Error} If there is an issue deleting items from the collection.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```typescript
|
|
157
|
-
* const results = await collection.delete({
|
|
158
|
-
* ids: "some_id",
|
|
159
|
-
* where: {"name": {"$eq": "John Doe"}},
|
|
160
|
-
* whereDocument: {"$contains":"search_string"}
|
|
161
|
-
* });
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
delete(options?: DeleteParams): Promise<void>;
|
|
1
|
+
import { IncludeEnum, Metadata } from 'chromadb';
|
|
2
|
+
export type ID = string;
|
|
3
|
+
export type Embedding = number[];
|
|
4
|
+
export type Embeddings = Embedding[];
|
|
5
|
+
export interface GetResponse {
|
|
6
|
+
ids: ID[];
|
|
7
|
+
embeddings: Embeddings | null;
|
|
8
|
+
documents: (Document | null)[];
|
|
9
|
+
metadatas: (Metadata | null)[];
|
|
10
|
+
included: IncludeEnum[];
|
|
165
11
|
}
|
|
166
|
-
|
|
167
|
-
ids?: ID | IDs;
|
|
168
|
-
where?: Where;
|
|
169
|
-
limit?: number;
|
|
170
|
-
offset?: number;
|
|
171
|
-
include?: IncludeEnum[];
|
|
172
|
-
whereDocument?: WhereDocument;
|
|
173
|
-
}
|
|
174
|
-
export type WhereWithPrompt = Where & {
|
|
12
|
+
export type WhereWithPrompt = WhereDocument & {
|
|
175
13
|
$prompt?: string;
|
|
176
14
|
};
|
|
177
|
-
export {
|
|
15
|
+
export interface WhereDocument {
|
|
16
|
+
$contains?: string;
|
|
17
|
+
$not_contains?: string;
|
|
18
|
+
$matches?: string;
|
|
19
|
+
$not_matches?: string;
|
|
20
|
+
$regex?: string;
|
|
21
|
+
$not_regex?: string;
|
|
22
|
+
$and?: WhereDocument[];
|
|
23
|
+
$or?: WhereDocument[];
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"sprucebot",
|
|
14
14
|
"sprucelabs"
|
|
15
15
|
],
|
|
16
|
-
"version": "0.
|
|
16
|
+
"version": "1.0.1",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build.ci": "yarn run build.tsc && yarn run build.resolve-paths && yarn run lint",
|
|
19
19
|
"build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",
|
|
@@ -43,18 +43,18 @@
|
|
|
43
43
|
"generate.embeddings": "./support/generate_embeddings.sh"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@sprucelabs/esm-postbuild": "^
|
|
47
|
-
"@sprucelabs/jest-json-reporter": "^
|
|
48
|
-
"@sprucelabs/resolve-path-aliases": "^
|
|
46
|
+
"@sprucelabs/esm-postbuild": "^7.0.3",
|
|
47
|
+
"@sprucelabs/jest-json-reporter": "^9.0.5",
|
|
48
|
+
"@sprucelabs/resolve-path-aliases": "^3.0.3",
|
|
49
49
|
"@sprucelabs/semantic-release": "^5.0.2",
|
|
50
|
-
"@sprucelabs/test": "^
|
|
51
|
-
"@sprucelabs/test-utils": "^
|
|
52
|
-
"@types/node": "^
|
|
50
|
+
"@sprucelabs/test": "^10.0.1",
|
|
51
|
+
"@sprucelabs/test-utils": "^6.0.7",
|
|
52
|
+
"@types/node": "^24.0.1",
|
|
53
53
|
"chokidar-cli": "^3.0.0",
|
|
54
|
-
"eslint": "^9.
|
|
54
|
+
"eslint": "^9.29.0",
|
|
55
55
|
"eslint-config-spruce": "^11.2.26",
|
|
56
|
-
"jest": "^
|
|
57
|
-
"jest-circus": "^30.0.0
|
|
56
|
+
"jest": "^30.0.0",
|
|
57
|
+
"jest-circus": "^30.0.0",
|
|
58
58
|
"prettier": "^3.5.3",
|
|
59
59
|
"ts-node": "^10.9.2",
|
|
60
60
|
"tsc-watch": "^7.1.1",
|
|
@@ -83,12 +83,13 @@
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@
|
|
87
|
-
"@sprucelabs/
|
|
88
|
-
"@sprucelabs/
|
|
89
|
-
"@sprucelabs/
|
|
90
|
-
"@sprucelabs/spruce-
|
|
91
|
-
"
|
|
86
|
+
"@chroma-core/ollama": "^0.1.7",
|
|
87
|
+
"@sprucelabs/data-stores": "^29.0.9",
|
|
88
|
+
"@sprucelabs/error": "^7.0.4",
|
|
89
|
+
"@sprucelabs/schema": "^32.0.8",
|
|
90
|
+
"@sprucelabs/spruce-core-schemas": "^41.0.8",
|
|
91
|
+
"@sprucelabs/spruce-skill-utils": "^32.0.8",
|
|
92
|
+
"chromadb": "^3.0.3",
|
|
92
93
|
"chromadb-default-embed": "^2.14.0",
|
|
93
94
|
"ollama": "^0.5.16"
|
|
94
95
|
}
|