> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.storages.vectordb storages.chroma

<a id="camel.storages.vectordb_storages.chroma" />

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage" />

## ChromaStorage

```python theme={"system"}
class ChromaStorage(BaseVectorStorage):
```

An implementation of the `BaseVectorStorage` for interacting with
ChromaDB, a vector database for embeddings.
ChromaDB is an open-source AI-native vector database focused on developer
productivity and happiness. The detailed information about ChromaDB is
available at: `ChromaDB <https://docs.trychroma.com/>`\_

This class provides multiple ways to connect to ChromaDB instances:

* Ephemeral (in-memory for testing/prototyping)
* Persistent (local file storage)
* HTTP (remote ChromaDB server)
* Cloud (ChromaDB Cloud - future support)

**Parameters:**

* **vector\_dim** (int): The dimension of storing vectors.
* **collection\_name** (Optional\[str], optional): Name for the collection in ChromaDB. If not provided, auto-generated with timestamp. (default: :obj:`None`)
* **client\_type** (`Literal["ephemeral", "persistent", "http", "cloud"]`): Type of ChromaDB client to use. Supported types: 'ephemeral', 'persistent', 'http', 'cloud'. (default: :obj:`"ephemeral"`) # Persistent client parameters
* **path** (Optional\[str], optional): Path to directory for persistent storage. Only used when client\_type='persistent'. (default: :obj:`"./chroma"`) # HTTP client parameters
* **host** (str, optional): Host for remote ChromaDB server. (default: :obj:`"localhost"`)
* **port** (int, optional): Port for remote ChromaDB server. (default: :obj:`8000`)
* **ssl** (bool, optional): Whether to use SSL for HTTP connections. (default: :obj:`False`)
* **headers** (Optional\[Dict\[str, str]], optional): Additional headers for HTTP client requests. (default: :obj:`None`) # Cloud client parameters
* **api\_key** (Optional\[str], optional): API key for ChromaDB Cloud. (default: :obj:`None`)
* **cloud\_host** (str, optional): ChromaDB Cloud host. (default: :obj:`"api.trychroma.com"`)
* **cloud\_port** (int, optional): ChromaDB Cloud port. (default: :obj:`8000`)
* **enable\_ssl** (bool, optional): Whether to enable SSL for cloud connection.(default: :obj:`True`) # Common parameters for all client types
* **settings** (Optional\[Any], optional): ChromaDB settings object for advanced configuration. (default: :obj:`None`)
* **tenant** (Optional\[str], optional): Tenant name for multi-tenancy support. (default: :obj:`None`)
* **database** (Optional\[str], optional): Database name for multi-database support. (default: :obj:`None`)
* **distance** (VectorDistance, optional): The distance metric for vector comparison. (default: :obj:`VectorDistance.COSINE`)
* **delete\_collection\_on\_del** (bool, optional): Flag to determine if the collection should be deleted upon object destruction. (default: :obj:`False`)

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    vector_dim: int,
    collection_name: Optional[str] = None,
    client_type: Literal['ephemeral', 'persistent', 'http', 'cloud'] = 'ephemeral',
    path: Optional[str] = './chroma',
    host: str = 'localhost',
    port: int = 8000,
    ssl: bool = False,
    headers: Optional[Dict[str, str]] = None,
    api_key: Optional[str] = None,
    cloud_host: str = 'api.trychroma.com',
    cloud_port: int = 8000,
    enable_ssl: bool = True,
    settings: Optional[Any] = None,
    tenant: Optional[str] = None,
    database: Optional[str] = None,
    distance: VectorDistance = VectorDistance.COSINE,
    delete_collection_on_del: bool = False,
    **kwargs: Any
):
```

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.__del__" />

### **del**

```python theme={"system"}
def __del__(self):
```

Deletes the collection if :obj:`delete_collection_on_del` is set to
:obj:`True`.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._validate_client_type" />

### \_validate\_client\_type

```python theme={"system"}
def _validate_client_type(
    self,
    client_type: Literal['ephemeral', 'persistent', 'http', 'cloud']
):
```

Validates client type parameter.

**Parameters:**

* **client\_type** (`Literal["ephemeral", "persistent", "http", "cloud"]`): The client type to validate.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._validate_client_config" />

### \_validate\_client\_config

```python theme={"system"}
def _validate_client_config(self):
```

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._get_connection_client" />

### \_get\_connection\_client

```python theme={"system"}
def _get_connection_client(self):
```

Get ChromaDB client based on client type and user settings.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._create_ephemeral_client" />

### \_create\_ephemeral\_client

```python theme={"system"}
def _create_ephemeral_client(self, chromadb_module: Any):
```

Create an ephemeral ChromaDB client (in-memory).

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._create_persistent_client" />

### \_create\_persistent\_client

```python theme={"system"}
def _create_persistent_client(self, chromadb_module: Any):
```

Create a persistent ChromaDB client (local file storage).

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._create_http_client" />

### \_create\_http\_client

```python theme={"system"}
def _create_http_client(self, chromadb_module: Any):
```

Create an HTTP ChromaDB client (remote server).

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._create_cloud_client" />

### \_create\_cloud\_client

```python theme={"system"}
def _create_cloud_client(self, chromadb_module: Any):
```

Create a cloud ChromaDB client.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._get_common_client_kwargs" />

### \_get\_common\_client\_kwargs

```python theme={"system"}
def _get_common_client_kwargs(self):
```

Get common kwargs for all ChromaDB clients.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._generate_collection_name" />

### \_generate\_collection\_name

```python theme={"system"}
def _generate_collection_name(self):
```

**Returns:**

str: Generated collection name based on current timestamp.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._get_distance_function" />

### \_get\_distance\_function

```python theme={"system"}
def _get_distance_function(self):
```

**Returns:**

str: ChromaDB distance function name.

References:
[https://docs.trychroma.com/docs/collections/configure](https://docs.trychroma.com/docs/collections/configure)

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._get_or_create_collection" />

### \_get\_or\_create\_collection

```python theme={"system"}
def _get_or_create_collection(self):
```

**Returns:**

ChromaDB collection object.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.add" />

### add

```python theme={"system"}
def add(self, records: List[VectorRecord], **kwargs: Any):
```

Adds vector records to ChromaDB collection.

**Parameters:**

* **records** (List\[VectorRecord]): List of vector records to be saved. \*\*kwargs (Any): Additional keyword arguments for ChromaDB add operation.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.delete" />

### delete

```python theme={"system"}
def delete(self, ids: List[str], **kwargs: Any):
```

Deletes vectors by their IDs from ChromaDB collection.

**Parameters:**

* **ids** (List\[str]): List of unique identifiers for the vectors to be deleted. \*\*kwargs (Any): Additional keyword arguments for ChromaDB delete operation.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.status" />

### status

```python theme={"system"}
def status(self):
```

**Returns:**

VectorDBStatus: The vector database status containing dimension
and count information.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.query" />

### query

```python theme={"system"}
def query(self, query: VectorDBQuery, **kwargs: Any):
```

Searches for similar vectors in ChromaDB based on the provided
query.

**Parameters:**

* **query** (VectorDBQuery): The query object containing the search vector and the number of top similar vectors to retrieve. \*\*kwargs (Any): Additional keyword arguments for ChromaDB query operation.

**Returns:**

List\[VectorDBQueryResult]: A list of vectors retrieved from the
storage based on similarity to the query vector.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage._distance_to_similarity" />

### \_distance\_to\_similarity

```python theme={"system"}
def _distance_to_similarity(self, distance: float):
```

Convert distance to similarity score based on distance metric.

**Parameters:**

* **distance** (float): Distance value from ChromaDB.

**Returns:**

float: Similarity score (higher means more similar).

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.clear" />

### clear

```python theme={"system"}
def clear(self):
```

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.load" />

### load

```python theme={"system"}
def load(self):
```

Load the collection hosted on cloud service.

For ChromaDB, collections are automatically available when client
connects, so this method is a no-op.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.delete_collection" />

### delete\_collection

```python theme={"system"}
def delete_collection(self):
```

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.client" />

### client

```python theme={"system"}
def client(self):
```

**Returns:**

chromadb.Client: The ChromaDB client instance.

<a id="camel.storages.vectordb_storages.chroma.ChromaStorage.collection" />

### collection

```python theme={"system"}
def collection(self):
```

**Returns:**

ChromaDB collection instance.
