Created
August 15, 2023 13:44
-
-
Save tazarov/1a83a33f13d56ef48e542920437e43fa to your computer and use it in GitHub Desktop.
This gist illustrates how to store vectors of your documents in chroma without providing your actual text documents. Useful if your docs contain sensitive info or you are mindful of the storage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
from chromadb.utils import embedding_functions | |
import chromadb | |
ef = embedding_functions.DefaultEmbeddingFunction() | |
docs = ["Article by john", "Article by Jack", "Article by Jill"] | |
client = chromadb.Client() | |
embeddings = ef(docs) | |
collection = client.get_or_create_collection("test-where-list") | |
collection.upsert(documents=["" for _ in range(len(docs))], embeddings=embeddings, metadatas=[{"source": "blogger.com","author":"John"}, {"source": "medium","author":"Jack"}, {"source": "notion","author":"Jill"}],ids=[str(uuid.uuid4()) for _ in range(len(docs))]) | |
#collection.get(include=["embeddings","metadatas"]) | |
qr = collection.query(query_texts=["All articles by John"], include=["metadatas","distances"]) | |
print(qr) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment