# chromadol.base

Base objects for chromadol.

### Functions

| `get_collection`(collection, \*[, codec, client])   |    |
|-----------------------------------------------------|----|
| `identity`(x)                                       |    |

### Classes

| [`AppendableChromaCollection`](#chromadol.base.AppendableChromaCollection)(collection)         | ChromaCollection with `append` and `extend`, auto-generating uuid keys.   |
|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| [`ChromaClient`](#chromadol.base.ChromaClient)([client, decoder, get_or_create]) |                                                                           |
| [`ChromaCollection`](#chromadol.base.ChromaCollection)(collection)                   |                                                                           |
| [`ChromaDocuments`](#chromadol.base.ChromaDocuments)(collection)                    | ChromaCollection but reading and writing only the 'documents' field.      |
| [`ChromaMetadatas`](#chromadol.base.ChromaMetadatas)(collection)                    | ChromaCollection but reading and writing only the 'metadatas' field.      |
| [`ChromaUris`](#chromadol.base.ChromaUris)(collection)                         | ChromaCollection but reading and writing only the 'uris' field.           |

### *class* chromadol.base.AppendableChromaCollection(collection)

Bases: [`AppendableChromaCollection`](#chromadol.base.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)

Bases: [`MutableMapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping)

#### clear()

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:

```pycon
>>> for k in chroma_client_instance:
...     del chroma_client_instance[k]
```

### *class* chromadol.base.ChromaCollection(collection)

Bases: [`MutableMapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping)

#### get_include *: [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), ...] | [None](https://docs.python.org/3/builtins/constants.html#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)

Bases: [`ChromaDocuments`](#chromadol.base.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)

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)

Bases: [`ChromaUris`](#chromadol.base.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.
