Spaces:
Sleeping
Sleeping
Download examples/techniques/chromadb_.py from LVKinyanjui/QueryYourDocs: direct link, hf CLI and curl.
- Browser
- Download file 709 Bytes
-
https://huggingface.co/spaces/LVKinyanjui/QueryYourDocs/resolve/main/examples/techniques/chromadb_.py
- Command line
-
hf download hf://spaces/LVKinyanjui/QueryYourDocs/examples/techniques/chromadb_.py
-
curl -L -o chromadb_.py https://huggingface.co/spaces/LVKinyanjui/QueryYourDocs/resolve/main/examples/techniques/chromadb_.py
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") | |