-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchroma_test.ts
31 lines (26 loc) · 925 Bytes
/
chroma_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as chroma from "./chroma-module/instance";
import GPT_CONFIG from "./gpt-module/config";
const init = async () => {
const embedder = chroma.getOpenAiEmbedder(GPT_CONFIG.API_KEY);
const collectioName = "test_col";
let collection;
// get an existing collection
collection = await chroma.getCollection(collectioName, embedder);
if (!collection) {
collection = await chroma.createCollection(collectioName, embedder);
}
console.log(`get/create collection: ${JSON.stringify(collection)}`);
const response = await chroma.addData(
collection,
["id1", "id2"],
// [{ source: "my_source" }, { source: "my_source" }],
["This is a document", "This is another document"]
);
console.log(`add data: ${response}`);
const data = await chroma.getData({
collection,
queryTexts: ["This is a query document"],
});
console.log(`query data: ${JSON.stringify(data)}`);
};
init();