File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments