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) |
Thank you, great questions.
if you do n_resultts=3 , do you get "This is document2" in the results?
Yes, consistently.
what about n_results=4, do you get only 3 results, or also some noise output?
We get some "noise". In fact it is about how k-neighbour (approximate) algorithms work. We ask then for the 4 closest neighbours, and it complies:
[
"This is document1",
"Whatever this is it should at some point include the word document, and nothing else perhaps.",
"This is document2",
"This is not"
]
You also the mention the need for training in our call on Friday, but it looks like working out of the box without training here, is that correct?
The example here works on plain English, which is the training dataset, basically. But if we work on say URDF, we're really "out of distribution" and need specific training for generating the "URDF language".
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ic a few questions
if you do n_resultts=3 , do you get "This is document2" in the results?
what about n_results=4, do you get only 3 results, or also some noise output?
You also the mention the need for training in our call on Friday, but it looks like working out of the box without training here, is that correct?