RAGtest / create_chroma_index.py
willco-afk's picture
Create create_chroma_index.py
9f3d22b verified
raw
history blame
550 Bytes
import chromadb
from sentence_transformers import SentenceTransformer
# Initialize Chroma client
client = chromadb.Client()
# Initialize SentenceTransformer model
model = SentenceTransformer('all-MiniLM-L6-v2')
# Create or load Chroma collection
collection = client.create_collection(name="documents")
# Add documents and their embeddings to Chroma
documents = ['document 1 text', 'document 2 text', 'document 3 text']
embeddings = model.encode(documents)
# Insert documents into Chroma
collection.add(documents=documents, embeddings=embeddings)