chromadol.base

Base objects for chromadol.

Functions

get_collection(collection, *[, codec, client])

identity(x)

Classes

AppendableChromaCollection(collection)

ChromaCollection with append and extend, auto-generating uuid keys.

ChromaClient([client, decoder, get_or_create])

ChromaCollection(collection)

ChromaDocuments(collection)

ChromaCollection but reading and writing only the 'documents' field.

ChromaMetadatas(collection)

ChromaCollection but reading and writing only the 'metadatas' field.

ChromaUris(collection)

ChromaCollection but reading and writing only the 'uris' field.

class chromadol.base.AppendableChromaCollection(collection)[source]

Bases: AppendableChromaCollection

ChromaCollection with append and extend, auto-generating uuid keys.

Items are the raw chromadb kwargs mappings that ChromaCollection.__setitem__() accepts (e.g. {"documents": ..., "metadatas": ...}) – use this when you need to append more than the single field the codec-ed stores below expose.

class chromadol.base.ChromaClient(client=None, *, decoder=<class 'chromadol.base.ChromaCollection'>, get_or_create=True, **create_collection_kwargs)[source]

Bases: MutableMapping

clear()[source]

This method is here, in fact, to disable the clear method, that would otherwise be inherited from MutableMapping. It’s existence is too dangerous, as it would delete all collections in the client. If you want to actually delete all collections in the client, do so explicitly by iterating over the client and deleting each collection, as such:

>>> for k in chroma_client_instance:
...     del chroma_client_instance[k]
class chromadol.base.ChromaCollection(collection)[source]

Bases: MutableMapping

get_include: tuple[str, ...] | None = None

The include that reads pass to collection.get. None keeps chromadb’s default (documents and metadatas); a single-field store whose field is not in that default (e.g. uris) names it here.

class chromadol.base.ChromaDocuments(collection)[source]

Bases: ChromaDocuments

ChromaCollection but reading and writing only the ‘documents’ field.

append and extend take the same values __setitem__ takes (that is, the ‘documents’ field’s value), generating uuid keys for them. To write raw chromadb kwargs instead, use AppendableChromaCollection.

class chromadol.base.ChromaMetadatas(collection)[source]

Bases: Store

ChromaCollection but reading and writing only the ‘metadatas’ field.

Mainly a read view: chromadb refuses an upsert that carries neither documents nor images, so writing metadata alone raises (that is also why this one has no append). Write metadata with the documents, through ChromaCollection or AppendableChromaCollection.

class chromadol.base.ChromaUris(collection)[source]

Bases: ChromaUris

ChromaCollection but reading and writing only the ‘uris’ field.

Writing uris needs a collection created with a data_loader (see chromadol.data_loaders): the record is embedded from the data it loads. chromadb only does that in add (upsert and update embed only documents or images), so a new key is added and an existing key is replaced (delete, then add, keeping its metadata), and restored if the add fails.