Created
December 12, 2023 07:06
-
-
Save ic/c5037502d3f271ee61113493cc388446 to your computer and use it in GitHub Desktop.
Conceptual example around a vector store, here Chroma
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
from pprint import pprint as pp | |
import chromadb | |
client = chromadb.Client() | |
collection = client.create_collection("all-my-documents") | |
# "document" is Chroma terminology. In VectorDB and others it is "chunk" | |
# And when querying with Chroma, response "units" are "documents". So better | |
# chop them finely to get good granularity, or not at all to get whole docs. | |
documents = [ | |
"Whatever this is it should at some point include the word document, and nothing else perhaps.", | |
"This is document1", | |
"This is document2", | |
"This is not", | |
"Not at all", | |
"Not even remotely", | |
] | |
collection.add( | |
documents=documents, | |
ids=[f"d{i}" for i in range(len(documents))], | |
) | |
results = collection.query( | |
query_texts=["This is a query document, and nothing else"], | |
n_results=2, | |
) | |
pp(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, great questions.