File size: 1,275 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
var fs = require("fs");
var path = require("path");

var express = require("express");
var chroma = require("chromadb");

var app = express();
app.get("/", async (req, res) => {
  const cc = new chroma.ChromaClient({ path: "http://localhost:8000" });
  await cc.reset();

  const google = new chroma.GoogleGenerativeAiEmbeddingFunction({ googleApiKey:"<APIKEY>" });

  const collection = await cc.createCollection({
    name: "test-from-js",
    embeddingFunction: google,
  });

  await collection.add({
    ids: ["doc1", "doc2"],
    documents: [
      "doc1",
      "doc2",
    ]
  });

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

  const googleQuery = new chroma.GoogleGenerativeAiEmbeddingFunction({ googleApiKey:"<APIKEY>", taskType: 'RETRIEVAL_QUERY' });

  const queryCollection = await cc.getCollection({
    name: "test-from-js",
    embeddingFunction: googleQuery,
  });

  const query = await collection.query({
    queryTexts: ["doc1"],
    nResults: 1
  });
  console.log("query", query);

  console.log("COMPLETED");

  const collections = await cc.listCollections();
  console.log('collections', collections)

  res.send('Hello World!');
});
app.listen(3000, function () {
  console.log("Example app listening on port 3000!");
});