@sprucelabs/chroma-data-store 0.0.3
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/build/.spruce/errors/chromaDataStore/featureNotSupported.schema.d.ts +3 -0
- package/build/.spruce/errors/chromaDataStore/featureNotSupported.schema.js +19 -0
- package/build/.spruce/errors/chromaDataStore/featureNotSupported.schema.js.map +1 -0
- package/build/.spruce/errors/errors.types.d.ts +21 -0
- package/build/.spruce/errors/errors.types.js +3 -0
- package/build/.spruce/errors/errors.types.js.map +1 -0
- package/build/.spruce/errors/options.types.d.ts +7 -0
- package/build/.spruce/errors/options.types.js +3 -0
- package/build/.spruce/errors/options.types.js.map +1 -0
- package/build/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
- package/build/.spruce/schemas/fields/fieldClassMap.js +5 -0
- package/build/.spruce/schemas/fields/fieldClassMap.js.map +1 -0
- package/build/.spruce/schemas/fields/fields.types.d.ts +1 -0
- package/build/.spruce/schemas/fields/fields.types.js +3 -0
- package/build/.spruce/schemas/fields/fields.types.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/choice.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/choice.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/choice.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/link.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/link.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/link.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/location.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/location.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/location.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/message.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/message.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/message.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/organization.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/organization.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/organization.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/person.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/person.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/person.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/role.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/role.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/role.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/skill.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/skill.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/skill.schema.js.map +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.d.ts +1 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.js +6 -0
- package/build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.js.map +1 -0
- package/build/.spruce/settings.json +13 -0
- package/build/ChromaDatabase.d.ts +46 -0
- package/build/ChromaDatabase.js +386 -0
- package/build/ChromaDatabase.js.map +1 -0
- package/build/__tests__/behavioral/ChromaDatabase.test.d.ts +39 -0
- package/build/__tests__/behavioral/ChromaDatabase.test.js +351 -0
- package/build/__tests__/behavioral/ChromaDatabase.test.js.map +1 -0
- package/build/chroma.types.d.ts +177 -0
- package/build/chroma.types.js +3 -0
- package/build/chroma.types.js.map +1 -0
- package/build/errors/SpruceError.d.ts +6 -0
- package/build/errors/SpruceError.js +26 -0
- package/build/errors/SpruceError.js.map +1 -0
- package/build/errors/featureNotSupported.builder.d.ts +11 -0
- package/build/errors/featureNotSupported.builder.js +14 -0
- package/build/errors/featureNotSupported.builder.js.map +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +27 -0
- package/build/index.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
const data_stores_1 = require("@sprucelabs/data-stores");
|
|
46
|
+
const test_utils_1 = __importStar(require("@sprucelabs/test-utils"));
|
|
47
|
+
const chromadb_1 = require("chromadb");
|
|
48
|
+
const ChromaDatabase_1 = __importDefault(require("../../ChromaDatabase"));
|
|
49
|
+
class ChromaDatabaseTest extends test_utils_1.default {
|
|
50
|
+
static async beforeEach() {
|
|
51
|
+
await super.beforeEach();
|
|
52
|
+
ChromaDatabase_1.default.clearEmbeddingsFields();
|
|
53
|
+
this.chroma = new chromadb_1.ChromaClient({ path: 'http://localhost:8000' });
|
|
54
|
+
this.embedding = new chromadb_1.OllamaEmbeddingFunction({
|
|
55
|
+
model: 'llama3.2',
|
|
56
|
+
url: 'http://localhost:11434/api/embeddings',
|
|
57
|
+
});
|
|
58
|
+
const { db } = await chromaConnect();
|
|
59
|
+
this.db = db;
|
|
60
|
+
this.collectionName = (0, test_utils_1.generateId)();
|
|
61
|
+
this.collection = await this.getOrCreateCollection();
|
|
62
|
+
}
|
|
63
|
+
static async afterEach() {
|
|
64
|
+
await super.afterEach();
|
|
65
|
+
try {
|
|
66
|
+
await this.db.dropCollection(this.collectionName);
|
|
67
|
+
}
|
|
68
|
+
catch { }
|
|
69
|
+
}
|
|
70
|
+
static async throwsWithMissing() {
|
|
71
|
+
//@ts-ignore
|
|
72
|
+
const err = test_utils_1.assert.doesThrow(() => new ChromaDatabase_1.default());
|
|
73
|
+
test_utils_1.errorAssert.assertError(err, 'MISSING_PARAMETERS', {
|
|
74
|
+
parameters: ['connectionString'],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
static async defaultsToOllamaEmbedding() {
|
|
78
|
+
await this.createOneAndAssertExpectedEmbeddings('name: Hello', {
|
|
79
|
+
name: 'Hello',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
static async embedsTheWholeDocumentByDefault() {
|
|
83
|
+
await this.createOneAndAssertExpectedEmbeddings('test: true', {
|
|
84
|
+
test: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
static async canGenerateEmbedsForNestedValues() {
|
|
88
|
+
await this.createOneAndAssertExpectedEmbeddings(`nested:\n\ttest: true`, {
|
|
89
|
+
nested: { test: true },
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
static async canDoMultipleKeyValuePairsForEmbeddings() {
|
|
93
|
+
await this.createOneAndAssertExpectedEmbeddings(`name: Hello\ntest: true`, {
|
|
94
|
+
name: 'Hello',
|
|
95
|
+
test: true,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
static async canDoMultipleNestedKeyValuePairsForEmbeddings() {
|
|
99
|
+
await this.createOneAndAssertExpectedEmbeddings(`nested:\n\ttest: true\nname: Hello`, {
|
|
100
|
+
nested: { test: true },
|
|
101
|
+
name: 'Hello',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
static async throwsExpectedErrorForUnsupportedFeatures() {
|
|
105
|
+
await this.assertOperationThrowsNotSupported(() => this.db.syncIndexes((0, test_utils_1.generateId)(), []), 'syncIndexes');
|
|
106
|
+
await this.assertOperationThrowsNotSupported(() => this.db.dropIndex((0, test_utils_1.generateId)(), []), 'dropIndex');
|
|
107
|
+
await this.assertOperationThrowsNotSupported(() => this.db.getUniqueIndexes((0, test_utils_1.generateId)()), 'getUniqueIndexes');
|
|
108
|
+
await this.assertOperationThrowsNotSupported(() => this.db.getIndexes((0, test_utils_1.generateId)()), 'getIndexes');
|
|
109
|
+
await this.assertOperationThrowsNotSupported(() => this.db.query(''), 'query');
|
|
110
|
+
await this.assertOperationThrowsNotSupported(() => this.db.createUniqueIndex('', []), 'createUniqueIndex');
|
|
111
|
+
await this.assertOperationThrowsNotSupported(() => this.db.createIndex('', []), 'createIndex');
|
|
112
|
+
await this.assertOperationThrowsNotSupported(() => this.db.syncUniqueIndexes('', []), 'syncUniqueIndexes');
|
|
113
|
+
}
|
|
114
|
+
static async runsSuiteOfDatabaseTests() {
|
|
115
|
+
await data_stores_1.databaseAssert.runSuite(chromaConnect, [
|
|
116
|
+
'!assertThrowsWithBadDatabaseName',
|
|
117
|
+
'!assertCanSortDesc',
|
|
118
|
+
'!assertCanSortAsc',
|
|
119
|
+
'!assertCanSortById',
|
|
120
|
+
'!assertCanPushOntoArrayValue',
|
|
121
|
+
'!assertCanPushToArrayOnUpsert',
|
|
122
|
+
'!assertCanSyncUniqueIndexesWithFilterExpression',
|
|
123
|
+
'!assertCanSearchByRegex',
|
|
124
|
+
'!assertHasNoUniqueIndexToStart',
|
|
125
|
+
'!assertCanCreateUniqueIndex',
|
|
126
|
+
'!assertCanCreateMultiFieldUniqueIndex',
|
|
127
|
+
'!assertCantCreateUniqueIndexTwice',
|
|
128
|
+
'!assertCanDropUniqueIndex',
|
|
129
|
+
'!assertCanDropCompoundUniqueIndex',
|
|
130
|
+
'!assertCantDropUniqueIndexThatDoesntExist',
|
|
131
|
+
'!assertCantDropIndexWhenNoIndexExists',
|
|
132
|
+
'!assertCantDropCompoundUniqueIndexThatDoesntExist',
|
|
133
|
+
'!assertSyncingUniqueIndexesAddsMissingIndexes',
|
|
134
|
+
'!assertSyncingUniqueIndexesSkipsExistingIndexes',
|
|
135
|
+
'!assertSyncingUniqueIndexesRemovesExtraIndexes',
|
|
136
|
+
'!assertUniqueIndexBlocksDuplicates',
|
|
137
|
+
'!assertDuplicateKeyThrowsOnInsert',
|
|
138
|
+
'!assertSettingUniqueIndexViolationThrowsSpruceError',
|
|
139
|
+
'!assertCanCreateUniqueIndexOnNestedField',
|
|
140
|
+
'!assertHasNoIndexToStart',
|
|
141
|
+
'!assertCanCreateIndex',
|
|
142
|
+
'!assertCantCreateSameIndexTwice',
|
|
143
|
+
'!assertCanCreateMultiFieldIndex',
|
|
144
|
+
'!assertCanDropIndex',
|
|
145
|
+
'!assertCanDropCompoundIndex',
|
|
146
|
+
'!assertCantDropCompoundIndexThatDoesNotExist',
|
|
147
|
+
'!assertSyncIndexesSkipsExisting',
|
|
148
|
+
'!assertSyncIndexesRemovesExtraIndexes',
|
|
149
|
+
'!assertSyncIndexesHandlesRaceConditions',
|
|
150
|
+
'!assertSyncIndexesDoesNotRemoveExisting',
|
|
151
|
+
'!assertDuplicateFieldsWithMultipleUniqueIndexesWorkAsExpected',
|
|
152
|
+
'!assertCanSyncIndexesWithoutPartialThenAgainWithProperlyUpdates',
|
|
153
|
+
'!assertSyncingIndexesDoesNotAddAndRemove',
|
|
154
|
+
'!assertNestedFieldIndexUpdates',
|
|
155
|
+
'!assertSyncingUniqueIndexesIsRaceProof',
|
|
156
|
+
'!assertUpsertWithUniqueIndex',
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
static async canSetSingleEmbeddingField() {
|
|
160
|
+
await this.setEmbedFieldsAndAssertEmbeddingsEqual(['name'], 'Hello', {
|
|
161
|
+
name: 'Hello',
|
|
162
|
+
test: true,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
static async canSetDifferentSingleEmbeddingField() {
|
|
166
|
+
await this.setEmbedFieldsAndAssertEmbeddingsEqual(['firstName'], 'Cheese', {
|
|
167
|
+
firstName: 'Cheese',
|
|
168
|
+
name: 'Hello',
|
|
169
|
+
test: false,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
static async canSetMultipleFieldsOnEmbedding() {
|
|
173
|
+
await this.setEmbedFieldsAndAssertEmbeddingsEqual(['firstName', 'lastName'], 'firstName: tay\nlastName: ro', {
|
|
174
|
+
firstName: 'tay',
|
|
175
|
+
lastName: 'ro',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
static async embeddingFieldsHonorsCollection() {
|
|
179
|
+
this.setEmbeddingFields(['lastName']);
|
|
180
|
+
this.setEmbeddingFields(['name'], (0, test_utils_1.generateId)());
|
|
181
|
+
await this.assertEmbeddingsEqual({
|
|
182
|
+
lastName: 'test',
|
|
183
|
+
}, 'test');
|
|
184
|
+
}
|
|
185
|
+
static async dropDatabaseDeletesAllCollections() {
|
|
186
|
+
await this.getOrCreateCollection((0, test_utils_1.generateId)());
|
|
187
|
+
await this.getOrCreateCollection((0, test_utils_1.generateId)());
|
|
188
|
+
await this.getOrCreateCollection((0, test_utils_1.generateId)());
|
|
189
|
+
await this.db.dropDatabase();
|
|
190
|
+
const client = new chromadb_1.ChromaClient({ path: 'http://localhost:8000' });
|
|
191
|
+
const collections = await client.listCollections();
|
|
192
|
+
test_utils_1.assert.isLength(collections, 0, 'Collections were not deleted');
|
|
193
|
+
}
|
|
194
|
+
static async doesTextSearchWith$promptKey() {
|
|
195
|
+
const created = await this.createSearchableDocuments();
|
|
196
|
+
const results = await this.findByPrompt('down');
|
|
197
|
+
test_utils_1.assert.isEqualDeep(results[0], created[1], 'Searching based on $prompt did not return the expected match');
|
|
198
|
+
}
|
|
199
|
+
static async canFindUsingDifferent$promptKey() {
|
|
200
|
+
const created = await this.createSearchableDocuments();
|
|
201
|
+
const results = await this.findByPrompt('pepper');
|
|
202
|
+
test_utils_1.assert.isEqualDeep(results[0], created[0], 'Searching based on $prompt did not return the expected match');
|
|
203
|
+
}
|
|
204
|
+
static async canFindUsingDifferentLimit() {
|
|
205
|
+
await this.createSearchableDocuments();
|
|
206
|
+
const results = await this.findByPrompt('pepper', 2);
|
|
207
|
+
test_utils_1.assert.isLength(results, 2, 'Expected to find two results');
|
|
208
|
+
}
|
|
209
|
+
static async canSearchByPromptAndDocumentFields() {
|
|
210
|
+
const created = await this.createSearchableDocuments();
|
|
211
|
+
const results = await this.findByPrompt('cheese', 1, { hello: 'world' });
|
|
212
|
+
const expected = created[3];
|
|
213
|
+
test_utils_1.assert.isEqualDeep(results[0], expected, 'Searching based on $prompt and document fields did not return the expected match');
|
|
214
|
+
}
|
|
215
|
+
static async canSearchSamePromptAndDifferentDocumentFields() {
|
|
216
|
+
const created = await this.createSearchableDocuments();
|
|
217
|
+
const results = await this.findByPrompt('cheese', 1, { world: 'hello' });
|
|
218
|
+
const expected = created[4];
|
|
219
|
+
test_utils_1.assert.isEqualDeep(results[0], expected, 'Searching based on $prompt and document fields did not return the expected match');
|
|
220
|
+
}
|
|
221
|
+
static async findByPrompt(prompt, limit, query) {
|
|
222
|
+
const results = await this.db.find(this.collectionName, {
|
|
223
|
+
$prompt: prompt,
|
|
224
|
+
...query,
|
|
225
|
+
}, {
|
|
226
|
+
limit: limit ?? 1,
|
|
227
|
+
});
|
|
228
|
+
test_utils_1.assert.isLength(results, limit ?? 1, 'Expected to find one result from $prompt');
|
|
229
|
+
return results;
|
|
230
|
+
}
|
|
231
|
+
static async createSearchableDocuments() {
|
|
232
|
+
return await this.db.create(this.collectionName, [
|
|
233
|
+
{ name: 'peter piper picked a pepper' },
|
|
234
|
+
{ name: 'this is down' },
|
|
235
|
+
{ cheesey: 'this is a burrito' },
|
|
236
|
+
{ stinky: 'cheese', hello: 'world' },
|
|
237
|
+
{ stinky: 'cheese', world: 'hello' },
|
|
238
|
+
]);
|
|
239
|
+
}
|
|
240
|
+
static async getOrCreateCollection(collectionName) {
|
|
241
|
+
return await this.chroma.getOrCreateCollection({
|
|
242
|
+
name: collectionName ?? this.collectionName,
|
|
243
|
+
embeddingFunction: this.embedding,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
static async setEmbedFieldsAndAssertEmbeddingsEqual(embeddingFields, embeddingPrompt, values) {
|
|
247
|
+
this.setEmbeddingFields(embeddingFields);
|
|
248
|
+
await this.assertEmbeddingsEqual(values, embeddingPrompt);
|
|
249
|
+
}
|
|
250
|
+
static async assertEmbeddingsEqual(values, embeddingPrompt) {
|
|
251
|
+
const record = await this.createOne(values);
|
|
252
|
+
const match = await this.getById(record.id);
|
|
253
|
+
const embeddings = await this.generateEmbeddings([embeddingPrompt]);
|
|
254
|
+
test_utils_1.assert.isEqualDeep(match.embeddings?.[0], embeddings[0], `The embeddings for ${JSON.stringify(record)} did not match based on the prompt 'Hello'.`);
|
|
255
|
+
}
|
|
256
|
+
static setEmbeddingFields(fields, collectionName) {
|
|
257
|
+
ChromaDatabase_1.default.setEmbeddingsFields(collectionName ?? this.collectionName, fields);
|
|
258
|
+
}
|
|
259
|
+
static async assertOperationThrowsNotSupported(cb, operation) {
|
|
260
|
+
const err = await test_utils_1.assert.doesThrowAsync(cb, undefined, `Expected ${operation} to throw`);
|
|
261
|
+
test_utils_1.errorAssert.assertError(err, 'FEATURE_NOT_SUPPORTED', {
|
|
262
|
+
operation,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
static async createOneAndAssertExpectedEmbeddings(prompt, values) {
|
|
266
|
+
const expected = await this.generateEmbeddings([prompt]);
|
|
267
|
+
const created = await this.createOne(values);
|
|
268
|
+
const match = await this.getById(created.id);
|
|
269
|
+
test_utils_1.assert.isEqual(match.documents?.[0], prompt, `The generate prompt did not match!`);
|
|
270
|
+
test_utils_1.assert.isEqualDeep(match.embeddings?.[0], expected[0], `The embeddings for ${JSON.stringify(values)} did not match based on the prompt '${prompt}'.`);
|
|
271
|
+
}
|
|
272
|
+
static async getById(id) {
|
|
273
|
+
return await this.collection.get({
|
|
274
|
+
ids: [id],
|
|
275
|
+
include: ['embeddings', 'documents'],
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
static async generateEmbeddings(prompts) {
|
|
279
|
+
return await this.embedding.generate(prompts);
|
|
280
|
+
}
|
|
281
|
+
static async createOne(values) {
|
|
282
|
+
return await this.db.createOne(this.collectionName, values);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exports.default = ChromaDatabaseTest;
|
|
286
|
+
__decorate([
|
|
287
|
+
(0, test_utils_1.test)()
|
|
288
|
+
], ChromaDatabaseTest, "throwsWithMissing", null);
|
|
289
|
+
__decorate([
|
|
290
|
+
(0, test_utils_1.test)()
|
|
291
|
+
], ChromaDatabaseTest, "defaultsToOllamaEmbedding", null);
|
|
292
|
+
__decorate([
|
|
293
|
+
(0, test_utils_1.test)()
|
|
294
|
+
], ChromaDatabaseTest, "embedsTheWholeDocumentByDefault", null);
|
|
295
|
+
__decorate([
|
|
296
|
+
(0, test_utils_1.test)()
|
|
297
|
+
], ChromaDatabaseTest, "canGenerateEmbedsForNestedValues", null);
|
|
298
|
+
__decorate([
|
|
299
|
+
(0, test_utils_1.test)()
|
|
300
|
+
], ChromaDatabaseTest, "canDoMultipleKeyValuePairsForEmbeddings", null);
|
|
301
|
+
__decorate([
|
|
302
|
+
(0, test_utils_1.test)()
|
|
303
|
+
], ChromaDatabaseTest, "canDoMultipleNestedKeyValuePairsForEmbeddings", null);
|
|
304
|
+
__decorate([
|
|
305
|
+
(0, test_utils_1.test)()
|
|
306
|
+
], ChromaDatabaseTest, "throwsExpectedErrorForUnsupportedFeatures", null);
|
|
307
|
+
__decorate([
|
|
308
|
+
(0, test_utils_1.test)()
|
|
309
|
+
], ChromaDatabaseTest, "runsSuiteOfDatabaseTests", null);
|
|
310
|
+
__decorate([
|
|
311
|
+
(0, test_utils_1.test)()
|
|
312
|
+
], ChromaDatabaseTest, "canSetSingleEmbeddingField", null);
|
|
313
|
+
__decorate([
|
|
314
|
+
(0, test_utils_1.test)()
|
|
315
|
+
], ChromaDatabaseTest, "canSetDifferentSingleEmbeddingField", null);
|
|
316
|
+
__decorate([
|
|
317
|
+
(0, test_utils_1.test)()
|
|
318
|
+
], ChromaDatabaseTest, "canSetMultipleFieldsOnEmbedding", null);
|
|
319
|
+
__decorate([
|
|
320
|
+
(0, test_utils_1.test)()
|
|
321
|
+
], ChromaDatabaseTest, "embeddingFieldsHonorsCollection", null);
|
|
322
|
+
__decorate([
|
|
323
|
+
(0, test_utils_1.test)()
|
|
324
|
+
], ChromaDatabaseTest, "dropDatabaseDeletesAllCollections", null);
|
|
325
|
+
__decorate([
|
|
326
|
+
(0, test_utils_1.test)()
|
|
327
|
+
], ChromaDatabaseTest, "doesTextSearchWith$promptKey", null);
|
|
328
|
+
__decorate([
|
|
329
|
+
(0, test_utils_1.test)()
|
|
330
|
+
], ChromaDatabaseTest, "canFindUsingDifferent$promptKey", null);
|
|
331
|
+
__decorate([
|
|
332
|
+
(0, test_utils_1.test)()
|
|
333
|
+
], ChromaDatabaseTest, "canFindUsingDifferentLimit", null);
|
|
334
|
+
__decorate([
|
|
335
|
+
(0, test_utils_1.test)()
|
|
336
|
+
], ChromaDatabaseTest, "canSearchByPromptAndDocumentFields", null);
|
|
337
|
+
__decorate([
|
|
338
|
+
(0, test_utils_1.test)()
|
|
339
|
+
], ChromaDatabaseTest, "canSearchSamePromptAndDifferentDocumentFields", null);
|
|
340
|
+
const chromaConnect = async (connectionString) => {
|
|
341
|
+
const db = new ChromaDatabase_1.default(connectionString ?? 'chroma://localhost:8000');
|
|
342
|
+
await db.connect();
|
|
343
|
+
const badDatabaseName = (0, test_utils_1.generateId)();
|
|
344
|
+
return {
|
|
345
|
+
db,
|
|
346
|
+
scheme: 'chroma://',
|
|
347
|
+
connectionStringWithRandomBadDatabaseName: `chroma://bad-database/${badDatabaseName}`,
|
|
348
|
+
badDatabaseName,
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
//# sourceMappingURL=ChromaDatabase.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChromaDatabase.test.js","sourceRoot":"","sources":["../../../src/__tests__/behavioral/ChromaDatabase.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA+E;AAC/E,qEAK+B;AAC/B,uCAA6E;AAE7E,0EAAiD;AAEjD,MAAqB,kBAAmB,SAAQ,oBAAkB;IAOpD,MAAM,CAAC,KAAK,CAAC,UAAU;QAC7B,MAAM,KAAK,CAAC,UAAU,EAAE,CAAA;QAExB,wBAAc,CAAC,qBAAqB,EAAE,CAAA;QAEtC,IAAI,CAAC,MAAM,GAAG,IAAI,uBAAY,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC,CAAA;QACjE,IAAI,CAAC,SAAS,GAAG,IAAI,kCAAuB,CAAC;YACzC,KAAK,EAAE,UAAU;YACjB,GAAG,EAAE,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
+
import { AddRecordsParams, UpsertRecordsParams, GetResponse, UpdateRecordsParams, QueryRecordsParams, QueryResponse, CollectionMetadata, CollectionParams, PeekParams, DeleteParams, ID, IDs, Where, IncludeEnum, WhereDocument } from 'chromadb';
|
|
2
|
+
export interface Collection {
|
|
3
|
+
add(params: AddRecordsParams): Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* Upsert items to the collection
|
|
6
|
+
* @param {Object} params - The parameters for the query.
|
|
7
|
+
* @param {ID | IDs} [params.ids] - IDs of the items to add.
|
|
8
|
+
* @param {Embedding | Embeddings} [params.embeddings] - Optional embeddings of the items to add.
|
|
9
|
+
* @param {Metadata | Metadatas} [params.metadatas] - Optional metadata of the items to add.
|
|
10
|
+
* @param {Document | Documents} [params.documents] - Optional documents of the items to add.
|
|
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>;
|
|
165
|
+
}
|
|
166
|
+
interface BaseGetParams {
|
|
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 & {
|
|
175
|
+
$prompt?: string;
|
|
176
|
+
};
|
|
177
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chroma.types.js","sourceRoot":"","sources":["../src/chroma.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import BaseSpruceError from '@sprucelabs/error';
|
|
2
|
+
import ErrorOptions from './../.spruce/errors/options.types';
|
|
3
|
+
export default class SpruceError extends BaseSpruceError<ErrorOptions> {
|
|
4
|
+
/** an easy to understand version of the errors */
|
|
5
|
+
friendlyMessage(): string;
|
|
6
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const error_1 = __importDefault(require("@sprucelabs/error"));
|
|
7
|
+
class SpruceError extends error_1.default {
|
|
8
|
+
/** an easy to understand version of the errors */
|
|
9
|
+
friendlyMessage() {
|
|
10
|
+
const { options } = this;
|
|
11
|
+
let message;
|
|
12
|
+
switch (options?.code) {
|
|
13
|
+
case 'FEATURE_NOT_SUPPORTED':
|
|
14
|
+
message = `I'm sorry, but you can't run ${options.operation} operation on the Chromadb`;
|
|
15
|
+
break;
|
|
16
|
+
default:
|
|
17
|
+
message = super.friendlyMessage();
|
|
18
|
+
}
|
|
19
|
+
const fullMessage = options.friendlyMessage
|
|
20
|
+
? options.friendlyMessage
|
|
21
|
+
: message;
|
|
22
|
+
return fullMessage;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.default = SpruceError;
|
|
26
|
+
//# sourceMappingURL=SpruceError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpruceError.js","sourceRoot":"","sources":["../../src/errors/SpruceError.ts"],"names":[],"mappings":";;;;;AAAA,8DAA+C;AAG/C,MAAqB,WAAY,SAAQ,eAA6B;IAClE,kDAAkD;IAC3C,eAAe;QAClB,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QACxB,IAAI,OAAO,CAAA;QACX,QAAQ,OAAO,EAAE,IAAI,EAAE,CAAC;YACpB,KAAK,uBAAuB;gBACxB,OAAO,GAAG,gCAAgC,OAAO,CAAC,SAAS,4BAA4B,CAAA;gBACvF,MAAK;YACT;gBACI,OAAO,GAAG,KAAK,CAAC,eAAe,EAAE,CAAA;QACzC,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,CAAC,eAAe;YACvC,CAAC,CAAC,OAAO,CAAC,eAAe;YACzB,CAAC,CAAC,OAAO,CAAA;QAEb,OAAO,WAAW,CAAA;IACtB,CAAC;CACJ;AAnBD,8BAmBC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
exports.default = (0, schema_1.buildErrorSchema)({
|
|
5
|
+
id: 'featureNotSupported',
|
|
6
|
+
name: 'Feature not supported',
|
|
7
|
+
fields: {
|
|
8
|
+
operation: {
|
|
9
|
+
type: 'text',
|
|
10
|
+
isRequired: true,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=featureNotSupported.builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"featureNotSupported.builder.js","sourceRoot":"","sources":["../../src/errors/featureNotSupported.builder.ts"],"names":[],"mappings":";;AAAA,+CAAqD;AAErD,kBAAe,IAAA,yBAAgB,EAAC;IAC5B,EAAE,EAAE,qBAAqB;IACzB,IAAI,EAAE,uBAAuB;IAC7B,MAAM,EAAE;QACJ,SAAS,EAAE;YACP,IAAI,EAAE,MAAM;YACZ,UAAU,EAAE,IAAI;SACnB;KACJ;CACJ,CAAC,CAAA"}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.ChromaDatabase = void 0;
|
|
21
|
+
var ChromaDatabase_1 = require("./ChromaDatabase");
|
|
22
|
+
Object.defineProperty(exports, "ChromaDatabase", { enumerable: true, get: function () { return __importDefault(ChromaDatabase_1).default; } });
|
|
23
|
+
const data_stores_1 = require("@sprucelabs/data-stores");
|
|
24
|
+
const ChromaDatabase_2 = __importDefault(require("./ChromaDatabase"));
|
|
25
|
+
__exportStar(require("./ChromaDatabase"), exports);
|
|
26
|
+
data_stores_1.DatabaseFactory.addAdapter('chroma://', ChromaDatabase_2.default);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,mDAA4D;AAAnD,iIAAA,OAAO,OAAkB;AAClC,yDAAyD;AACzD,sEAA6C;AAC7C,mDAAgC;AAEhC,6BAAe,CAAC,UAAU,CAAC,WAAW,EAAE,wBAAc,CAAC,CAAA"}
|