QueryYourDocs / examples /chromadb_.py
LVKinyanjui's picture
Reliably upserted to chromadb and resolved dependency issues
e13715a
raw
history blame
No virus
709 Bytes
import chromadb
from uuid import uuid4
# @st.cache_resource
chroma_client = chromadb.Client()
collection_name = 'example_collection'
# collection = chroma_client.create_collection(name=collection_name)
collection = chroma_client.get_or_create_collection(collection_name)
# Data
documents = [
"This is a document about pineapple",
"This is a document about oranges"
]
ids = [str(uuid4()) for doc in documents]
# Upserting
collection.add(
documents= documents,
ids=ids
)
# Querying
results = collection.query(
query_texts=["This is a query document about hawaii"], # Chroma will embed this for you
n_results=2 # how many results to return
)
print(results)
print("Done")