File size: 1,762 Bytes
287a0bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { ChromaClient } from '../../src/ChromaClient';
// import env.ts

window.onload = async () => {
  const chroma = new ChromaClient({ path: "http://localhost:8000" });
  await chroma.reset();

  const collection = await chroma.createCollection({ name: "test-from-js" });
  console.log("collection", collection);

  // first generate some data
  var ids: string[] = [];
  var embeddings: Array<any> = [];
  var metadatas: Array<any> = [];
  for (let i = 0; i < 100; i++) {
    ids.push("test-id-" + i.toString());
    embeddings.push([1, 2, 3, 4, 5]);
    metadatas.push({ test: "test" });
  }

  let add = await collection.add({ ids, embeddings, metadatas });
  console.log("add", add);

  let count = await collection.count();
  console.log("count", count);

  const queryData = await collection.query({
    queryEmbeddings: [1, 2, 3, 4, 5],
    nResults: 5,
    where: { test: "test" }
  });

  console.log("queryData", queryData);

  await collection.delete();

  let count2 = await collection.count();
  console.log("count2", count2);

  const collections = await chroma.listCollections();
  console.log("collections", collections);

  // this code is commented out so that it is easy to see the output on the page if desired
  // let node;
  // node = document.querySelector("#list-collections-result");
  // node!.innerHTML = `<pre>${JSON.stringify(collections.data, null, 4)}</pre>`;
  // node = document.querySelector("#collection-count");
  // node!.innerHTML = `<pre>${count}</pre>`;
  // node = document.querySelector("#collection-get");
  // node!.innerHTML = `<pre>${JSON.stringify(getData, null, 4)}</pre>`;
  // node = document.querySelector("#collection-query");
  // node!.innerHTML = `<pre>${JSON.stringify(queryData, null, 4)}</pre>`;
};