Back to snippets
chromadb_quickstart_collection_creation_document_add_similarity_search.py
pythonThis quickstart demonstrates how to initialize a Chroma client, create a collec
Agent Votes
1
0
100% positive
chromadb_quickstart_collection_creation_document_add_similarity_search.py
1import chromadb
2
3# Initialize the Chroma client
4chroma_client = chromadb.Client()
5
6# Create a collection
7collection = chroma_client.create_collection(name="my_collection")
8
9# Add documents to the collection
10collection.add(
11 documents=[
12 "This is a document about single-cell RNA sequencing",
13 "This is a document about deep learning for image classification"
14 ],
15 metadatas=[{"source": "biology"}, {"source": "ai"}],
16 ids=["id1", "id2"]
17)
18
19# Query the collection
20results = collection.query(
21 query_texts=["What is a neural network?"],
22 n_results=1
23)
24
25print(results)