Skip to main content

Data Object Layer for ChromaDB

Project description

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'}],
... }

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'}],
...     '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.

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

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

>>> collection['cake'] = {
...     "documents": "contents for cake",
... }
>>> sorted(collection)  # sorting because order is not guaranteed
['cake', 'of', 'piece']
>>> 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,
... }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chromadol-0.1.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chromadol-0.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file chromadol-0.1.1.tar.gz.

File metadata

  • Download URL: chromadol-0.1.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for chromadol-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ba3ed6c4dbfb787ec5a21644582d5a1a0de802de4f315ffcac765939a2d81237
MD5 2639f85546e4bbb853863a6eb6f25980
BLAKE2b-256 30fd59ae6bbbf10b62fc6a52336ea92fb9e0237a065a3306b946532026532bea

See more details on using hashes here.

File details

Details for the file chromadol-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: chromadol-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for chromadol-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 123ecc3bc2cf1c9e6d7fef727a26be2568cc09b5de46a244a3cb6f8c9365a890
MD5 b0d6cc7cb0e36408e6fdd50008e9ca9d
BLAKE2b-256 bd92c43ac940fc16d1cdf0b02eccdae97f33d3d93f88a5b7b154821d62be89ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page