9.5. Chroma¶
Chroma(Chroma is the open-source embedding database. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs):
quickstart:
# 1. Install pip install chromadb # 2. Get the Chroma Client import chromadb chroma_client = chromadb.Client() # 3. Create a collection collection = chroma_client.create_collection(name="my_collection") # 4. Add some text documents to the collection collection.add( documents=["This is a document", "This is another document"], metadatas=[{"source": "my_source"}, {"source": "my_source"}], ids=["id1", "id2"] ) # or collection.add( embeddings=[[1.2, 2.3, 4.5], [6.7, 8.2, 9.2]], documents=["This is a document", "This is another document"], metadatas=[{"source": "my_source"}, {"source": "my_source"}], ids=["id1", "id2"] ) # 5. Query the collection results = collection.query( query_texts=["This is a query document"], n_results=2 )