Skip to main content

Data Object Layer for ChromaDB

Project description

chromadol

Data Object Layer for ChromaDB

To install: pip install chromadol

Documentation

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.4.tar.gz (16.4 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.4-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chromadol-0.1.4.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for chromadol-0.1.4.tar.gz
Algorithm Hash digest
SHA256 256451f3016d095921b8b196a3ef91c49c7053f9e8d2a3a80d9e0f3c0d012349
MD5 133ea7890dea15f4b2c26818b7acc882
BLAKE2b-256 179461d437608366093e09f35c995562711ddf76d374fa00fbb12d38a4858f97

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chromadol-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for chromadol-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4ed529dd18642bc46347eaf0a524ac2b878e2da16c9ff61fd0964560f47233af
MD5 4393c06932782da593ed06390d1695a8
BLAKE2b-256 0501bd2c6934685376602984247edc01c364c0c060ff01ab88f24a89ef95cd7f

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