Skip to content

Commit 6e9a236

Browse files
committed
fix: sample app
1 parent 991c7c1 commit 6e9a236

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as traceloop from "@traceloop/node-server-sdk";
2+
import { ChromaClient, OpenAIEmbeddingFunction, Collection } from "chromadb";
3+
4+
const client = new ChromaClient();
5+
6+
const embedder = new OpenAIEmbeddingFunction({
7+
openai_api_key: process.env.OPENAI_API_KEY ?? "",
8+
});
9+
10+
traceloop.initialize({
11+
appName: "sample_chromadb",
12+
apiKey: process.env.TRACELOOP_API_KEY,
13+
disableBatch: true,
14+
});
15+
16+
const sampleAdd = async (collection: Collection) => {
17+
const addedResponse = await collection.add({
18+
ids: ["id1", "id2"],
19+
metadatas: [{ source: "my_source" }, { source: "my_source" }],
20+
documents: ["This is a document", "This is another document"],
21+
});
22+
23+
console.log(addedResponse);
24+
};
25+
26+
traceloop.withAssociationProperties({}, async () => {
27+
const collection = await client.createCollection({
28+
name: "my_collection",
29+
embeddingFunction: embedder,
30+
});
31+
32+
sampleAdd(collection);
33+
});

0 commit comments

Comments
 (0)