Embedding and upserting the data in a Chroma collection
We will begin by creating the Chroma client and defining a collection name:
# Import Chroma and instantiate a client. The default Chroma client is ephemeral, meaning it will not save to disk.
import chromadb
client = chromadb.Client()
collection_name="sciq_supports6"
Before creating the collection and upserting the data to the collection, we need to verify whether the collection already exists or not:
# List all collections
collections = client.list_collections()
# Check if the specific collection exists
collection_exists = any(collection.name == collection_name for collection in collections)
print("Collection exists:", collection_exists)
The output will return True
if the collection exists and False
if it doesn’t:
Collection exists: False
If the collection doesn’t exist, we will create a collection with collection_name
defined earlier:
# Create a new Chroma collection...