import chromadb
# Stores the database files in this folder and loads them on the next run.
client = chromadb.PersistentClient(path="./chroma_data")
# No embedding function is given, so Chroma uses its default one.
collection = client.get_or_create_collection(name="notes")
# A record whose id already exists is ignored, so re-running is safe.
collection.add(
ids=["note1", "note2", "note3"],
documents=[
"The office wifi password is changed on the first Monday of each month.",
"Maria prefers meetings in the afternoon, never before 10am.",
"The quarterly report is due on the last Friday of March.",
],
)
results = collection.query(
query_texts=["When does Maria like to meet?"],
n_results=2,
)
for doc, distance in zip(results["documents"][0], results["distances"][0]):
print(round(distance, 3), doc)