Skip to content

Commit

Permalink
feat: Actual code
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwhalen committed Jan 3, 2024
1 parent 0435a41 commit 9fb5019
Show file tree
Hide file tree
Showing 14 changed files with 734 additions and 0 deletions.
115 changes: 115 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
wads_configs.json
data/wads_configs.json
wads/data/wads_configs.json

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class


.DS_Store
# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
_build

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
docs/*

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# PyCharm
.idea
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# chromadol
Data Object Layer for ChromaDB


To install: ```pip install chromadol```


# Example usage

To make a `ChromaClient` DOL, you can specify a `chromadb` `Client`, `PersistentClient` (etc.)
instance, or specify a string (which will be interpreted as a path to a directory to
save the data to in a `PersistentClient` instance).

>>> from chromadol import ChromaClient
>>> import tempfile, os
>>> with tempfile.TemporaryDirectory() as temp_dir:
... tempdir = os.path.join(temp_dir, "chromadol_test")
... os.makedirs(tempdir)
>>> client = ChromaClient(tempdir)

Removing all contents of client to be able to run a test on a clean slate

>>> for k in client:
... del client[k]


There's nothing yet:

>>> list(client)
[]

Now let's "get" a collection.

>>> collection = client['chromadol_test']

Note that just accessing the collection creates it (by default)


>>> list(client)
['chromadol_test']

Here's nothing in the collection yet:

>>> list(collection)
[]

So let's write something.
Note that `chromadb` is designed to operate on multiple documents at once,
so the "chromadb-natural" way of specifying it's keys and contents (and any extras)
would be like this:

>>> collection[['piece', 'of']] = {
... 'documents': ['contents for piece', 'contents for of'],
... 'metadatas': [{'author': 'me'}, {'author': 'you'}],
... }
>>> list(collection)
['piece', 'of']
>>>
>>> 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,
... }


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

>>> collection['cake'] = {
... "documents": "contents for cake",
... }
>>> list(collection)
['piece', 'of', 'cake']
>>> assert collection['cake'] == {
... 'ids': ['cake'],
... 'embeddings': None,
... 'metadatas': [None],
... 'documents': ['contents for cake'],
... 'uris': None,
... 'data': None,
... }

In fact, see that if you only want to specify the "documents" part of the information,
you can just write a string instead of a dictionary:

>>> collection['cake'] = 'a different cake'
>>> assert collection['cake'] == {
... 'ids': ['cake'],
... 'embeddings': None,
... 'metadatas': [None],
... 'documents': ['a different cake'],
... 'uris': None,
... 'data': None,
... }
96 changes: 96 additions & 0 deletions chromadol/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""Data Object Layer (DOL) for ChromaDB
Example usage:
To make a `ChromaClient` DOL, you can specify a `chromadb` `Client`, `PersistentClient` (etc.)
instance, or specify a string (which will be interpreted as a path to a directory to
save the data to in a `PersistentClient` instance).
>>> from chromadol import ChromaClient
>>> import tempfile, os
>>> with tempfile.TemporaryDirectory() as temp_dir:
... tempdir = os.path.join(temp_dir, "chromadol_test")
... os.makedirs(tempdir)
>>> client = ChromaClient(tempdir)
Removing all contents of client to be able to run a test on a clean slate
>>> for k in client:
... del client[k]
...
There's nothing yet:
>>> list(client)
[]
Now let's "get" a collection.
>>> collection = client['chromadol_test']
Note that just accessing the collection creates it (by default)
>>> list(client)
['chromadol_test']
Here's nothing in the collection yet:
>>> list(collection)
[]
So let's write something.
Note that `chromadb` is designed to operate on multiple documents at once,
so the "chromadb-natural" way of specifying it's keys and contents (and any extras)
would be like this:
>>> collection[['piece', 'of']] = {
... 'documents': ['contents for piece', 'contents for of'],
... 'metadatas': [{'author': 'me'}, {'author': 'you'}],
... }
>>> list(collection)
['piece', 'of']
>>>
>>> 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,
... }
But you can read or write one document at a time too.
>>> collection['cake'] = {
... "documents": "contents for cake",
... }
>>> list(collection)
['piece', 'of', 'cake']
>>> assert collection['cake'] == {
... 'ids': ['cake'],
... 'embeddings': None,
... 'metadatas': [None],
... 'documents': ['contents for cake'],
... 'uris': None,
... 'data': None,
... }
In fact, see that if you only want to specify the "documents" part of the information,
you can just write a string instead of a dictionary:
>>> collection['cake'] = 'a different cake'
>>> assert collection['cake'] == {
... 'ids': ['cake'],
... 'embeddings': None,
... 'metadatas': [None],
... 'documents': ['a different cake'],
... 'uris': None,
... 'data': None,
... }
"""

from chromadol.base import ChromaCollection, ChromaClient
Loading

0 comments on commit 9fb5019

Please sign in to comment.