Skip to content

Commit

Permalink
fix: doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwhalen committed Jan 3, 2024
1 parent acfd50d commit ffadb09
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 24 deletions.
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,42 @@ would be like this:
... 'documents': ['contents for piece', 'contents for of'],
... 'metadatas': [{'author': 'me'}, {'author': 'you'}],
... }
>>> list(collection)
['piece', 'of']
>>>
>>> assert collection[['piece', 'of']] == {
... 'ids': ['piece', 'of'],

Now we have two documents in the collection:

>>> len(collection)
2

Note, though, that the order of the documents is not guaranteed.

>>> sorted(collection)
['of', 'piece']

>>> assert collection['piece'] == {
... 'ids': ['piece'],
... 'embeddings': None,
... 'metadatas': [{'author': 'me'}, {'author': 'you'}],
... 'documents': ['contents for piece', 'contents for of'],
... 'metadatas': [{'author': 'me'}],
... 'documents': ['contents for piece'],
... 'uris': None,
... 'data': None,
... 'data': None
... }

>>> assert collection['of'] == {
... 'ids': ['of'],
... 'embeddings': None,
... 'metadatas': [{'author': 'you'}],
... 'documents': ['contents for of'],
... 'uris': None,
... 'data': None
... }

You can also read multiple documents at once.
But note that the order of the documents is not guaranteed.

>>> collection[['piece', 'of']] == collection[['of', 'piece']]
True

But you can read or write one document at a time too.
You can read or write one document at a time too.

>>> collection['cake'] = {
... "documents": "contents for cake",
Expand Down
36 changes: 29 additions & 7 deletions chromadol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,42 @@
... 'documents': ['contents for piece', 'contents for of'],
... 'metadatas': [{'author': 'me'}, {'author': 'you'}],
... }
Now we have two documents in the collection:
>>> len(collection)
2
Note, though, that the order of the documents is not guaranteed.
>>> sorted(collection)
['of', 'piece']
>>>
>>> assert collection[['piece', 'of']] == {
... 'ids': ['piece', 'of'],
>>> assert collection['piece'] == {
... 'ids': ['piece'],
... 'embeddings': None,
... 'metadatas': [{'author': 'me'}, {'author': 'you'}],
... 'documents': ['contents for piece', 'contents for of'],
... 'metadatas': [{'author': 'me'}],
... 'documents': ['contents for piece'],
... 'uris': None,
... 'data': None,
... 'data': None
... }
>>> assert collection['of'] == {
... 'ids': ['of'],
... 'embeddings': None,
... 'metadatas': [{'author': 'you'}],
... 'documents': ['contents for of'],
... 'uris': None,
... 'data': None
... }
You can also read multiple documents at once.
But note that the order of the documents is not guaranteed.
>>> collection[['piece', 'of']] == collection[['of', 'piece']]
True
But you can read or write one document at a time too.
You can read or write one document at a time too.
>>> collection['cake'] = {
... "documents": "contents for cake",
Expand Down
33 changes: 25 additions & 8 deletions chromadol/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,40 @@ def test_simple():
# note that just accessing the collection creates it (by default)
assert list(client) == ['chromadol_test']
assert list(collection) == []
assert len(collection) == 0

# chromadb is designed to operate on multiple documents at once, so
# specifying it's keys and contents (and any extras) list this:
collection[['piece', 'of']] = {
'documents': ['contents for piece', 'contents for of'],
'metadatas': [{'author': 'me'}, {'author': 'you'}],
}

# Now we have two documents in the collection:

assert len(collection) == 2

# Note, though, that the order of the documents is not guaranteed.

assert sorted(collection) == ['of', 'piece']

assert collection[['piece', 'of']] == {
'ids': ['piece', 'of'],
'embeddings': None,
'metadatas': [{'author': 'me'}, {'author': 'you'}],
'documents': ['contents for piece', 'contents for of'],
'uris': None,
'data': None,
}
assert collection['piece'] == {'ids': ['piece'],
'embeddings': None,
'metadatas': [{'author': 'me'}],
'documents': ['contents for piece'],
'uris': None,
'data': None}

assert collection['of'] == {'ids': ['of'],
'embeddings': None,
'metadatas': [{'author': 'you'}],
'documents': ['contents for of'],
'uris': None,
'data': None}

# You can also read multiple documents at once.
# But note that the order of the documents is not guaranteed.
assert collection[['piece', 'of']] == collection[['of', 'piece']]

# But you can read or write one document at a time too.
collection['cake'] = {
Expand Down

0 comments on commit ffadb09

Please sign in to comment.