File size: 709 Bytes
38f846a
 
 
 
 
e13715a
 
 
38f846a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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")