willco-afk commited on
Commit
9f3d22b
·
verified ·
1 Parent(s): d405a7d

Create create_chroma_index.py

Browse files
Files changed (1) hide show
  1. create_chroma_index.py +18 -0
create_chroma_index.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import chromadb
2
+ from sentence_transformers import SentenceTransformer
3
+
4
+ # Initialize Chroma client
5
+ client = chromadb.Client()
6
+
7
+ # Initialize SentenceTransformer model
8
+ model = SentenceTransformer('all-MiniLM-L6-v2')
9
+
10
+ # Create or load Chroma collection
11
+ collection = client.create_collection(name="documents")
12
+
13
+ # Add documents and their embeddings to Chroma
14
+ documents = ['document 1 text', 'document 2 text', 'document 3 text']
15
+ embeddings = model.encode(documents)
16
+
17
+ # Insert documents into Chroma
18
+ collection.add(documents=documents, embeddings=embeddings)