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

# autogen.agentchat.contrib.vectordb.chromadb.ChromaVectorDB

<h2 id="autogen.agentchat.contrib.vectordb.chromadb.ChromaVectorDB" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">ChromaVectorDB</span>
</h2>

```python theme={null}
ChromaVectorDB(
    *,
    client=None,
    path: str = 'tmp/db',
    embedding_function: Callable = None,
    metadata: dict = None,
    **kwargs
)
```

A vector database that uses ChromaDB as the backend.<br />Initialize the vector database.<br />

<b>Parameters:</b>

| Name                 | Description                                     |
| -------------------- | ----------------------------------------------- |
| `client=None`        |                                                 |
| `path`               | **Type:** str<br /><br />**Default:** 'tmp/db'  |
| `embedding_function` | **Type:** Callable<br /><br />**Default:** None |
| `metadata`           | **Type:** dict<br /><br />**Default:** None     |
| `**kwargs`           |                                                 |

### Class Attributes

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### active\_collection

<br />

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### embedding\_function

<br />

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-attribute" />

#### type

<br />

<br />

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### create\_collection

```python theme={null}
create_collection(
    self,
    collection_name: str,
    overwrite: bool = False,
    get_or_create: bool = True
) -> Collection
```

Create a collection in the vector database.<br />Case 1. if the collection does not exist, create the collection.<br />Case 2. the collection exists, if overwrite is True, it will overwrite the collection.<br />Case 3. the collection exists and overwrite is False, if get\_or\_create is True, it will get the collection,
otherwise it raise a ValueError.<br />

<b>Parameters:</b>

| Name              | Description |                                                                                                                                        |
| ----------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `collection_name` | str         | The name of the collection.<br /><br />**Type:** str                                                                                   |
| `overwrite`       | bool        | Whether to overwrite the collection if it exists.<br /><br />Default is False.<br /><br />**Type:** bool<br /><br />**Default:** False |
| `get_or_create`   | bool        | Whether to get the collection if it exists.<br /><br />Default is True.<br /><br />**Type:** bool<br /><br />**Default:** True         |

<b>Returns:</b>

| Type       | Description                          |
| ---------- | ------------------------------------ |
| Collection | Collection \| The collection object. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### delete\_collection

```python theme={null}
delete_collection(self, collection_name: str) -> None
```

Delete the collection from the vector database.<br />

<b>Parameters:</b>

| Name              | Description |                                                      |
| ----------------- | ----------- | ---------------------------------------------------- |
| `collection_name` | str         | The name of the collection.<br /><br />**Type:** str |

<b>Returns:</b>

| Type | Description |
| ---- | ----------- |
| None | None        |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### delete\_docs

```python theme={null}
delete_docs(
    self,
    ids: list[str | int],
    collection_name: str = None,
    **kwargs
) -> None
```

Delete documents from the collection of the vector database.<br />

<b>Parameters:</b>

| Name              | Description   |                                                                                                               |
| ----------------- | ------------- | ------------------------------------------------------------------------------------------------------------- |
| `ids`             | List\[ItemID] | A list of document ids.<br /><br />Each id is a typed `ItemID`.<br /><br />**Type:** list\[str \| int]        |
| `collection_name` | str           | The name of the collection.<br /><br />Default is None.<br /><br />**Type:** str<br /><br />**Default:** None |
| `**kwargs`        |               |                                                                                                               |

<b>Returns:</b>

| Type | Description |
| ---- | ----------- |
| None | None        |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### get\_collection

```python theme={null}
get_collection(self, collection_name: str = None) -> Collection
```

Get the collection from the vector database.<br />

<b>Parameters:</b>

| Name              | Description |                                                                                                                                                                         |
| ----------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `collection_name` | str         | The name of the collection.<br /><br />Default is None.<br /><br />If None, return the current active collection.<br /><br />**Type:** str<br /><br />**Default:** None |

<b>Returns:</b>

| Type       | Description                          |
| ---------- | ------------------------------------ |
| Collection | Collection \| The collection object. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### get\_docs\_by\_ids

```python theme={null}
get_docs_by_ids(
    self,
    ids: list[str | int] = None,
    collection_name: str = None,
    include=None,
    **kwargs
) -> list[Document]
```

Retrieve documents from the collection of the vector database based on the ids.<br />

<b>Parameters:</b>

| Name              | Description   |                                                                                                                                                                            |
| ----------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ids`             | List\[ItemID] | A list of document ids.<br /><br />If None, will return all the documents.<br /><br />Default is None.<br /><br />**Type:** list\[str \| int]<br /><br />**Default:** None |
| `collection_name` | str           | The name of the collection.<br /><br />Default is None.<br /><br />**Type:** str<br /><br />**Default:** None                                                              |
| `include=None`    |               |                                                                                                                                                                            |
| `**kwargs`        |               |                                                                                                                                                                            |

<b>Returns:</b>

| Type                                                                                    | Description                     |
| --------------------------------------------------------------------------------------- | ------------------------------- |
| list\[[Document](/docs/api-reference/autogen/agentchat/contrib/vectordb/base/Document)] | List\[Document] \| The results. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### insert\_docs

```python theme={null}
insert_docs(
    self,
    docs: list[Document],
    collection_name: str = None,
    upsert: bool = False
) -> None
```

Insert documents into the collection of the vector database.<br />

<b>Parameters:</b>

| Name              | Description     |                                                                                                                                                                                       |
| ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `docs`            | List\[Document] | A list of documents.<br /><br />Each document is a TypedDict `Document`.<br /><br />**Type:** list\[[Document](/docs/api-reference/autogen/agentchat/contrib/vectordb/base/Document)] |
| `collection_name` | str             | The name of the collection.<br /><br />Default is None.<br /><br />**Type:** str<br /><br />**Default:** None                                                                         |
| `upsert`          | bool            | Whether to update the document if it exists.<br /><br />Default is False.<br /><br />**Type:** bool<br /><br />**Default:** False                                                     |

<b>Returns:</b>

| Type | Description |
| ---- | ----------- |
| None | None        |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### retrieve\_docs

```python theme={null}
retrieve_docs(
    self,
    queries: list[str],
    collection_name: str = None,
    n_results: int = 10,
    distance_threshold: float = -1,
    **kwargs: Any
) -> list[list[tuple[Document, float]]]
```

Retrieve documents from the collection of the vector database based on the queries.<br />

<b>Parameters:</b>

| Name                 | Description   |                                                                                                                                                                                                                |
| -------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `queries`            | List\[str]    | A list of queries.<br /><br />Each query is a string.<br /><br />**Type:** list\[str]                                                                                                                          |
| `collection_name`    | str           | The name of the collection.<br /><br />Default is None.<br /><br />**Type:** str<br /><br />**Default:** None                                                                                                  |
| `n_results`          | int           | The number of relevant documents to return.<br /><br />Default is 10.<br /><br />**Type:** int<br /><br />**Default:** 10                                                                                      |
| `distance_threshold` | float         | The threshold for the distance score, only distance smaller than it will be returned.<br /><br />Don't filter with it if ` 0`.<br /><br />Default is -1.<br /><br />**Type:** float<br /><br />**Default:** -1 |
| `**kwargs`           | **Type:** Any |                                                                                                                                                                                                                |

<b>Returns:</b>

| Type                                                                                                          | Description                                                                                                                |
| ------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| list\[list\[tuple\[[Document](/docs/api-reference/autogen/agentchat/contrib/vectordb/base/Document), float]]] | QueryResults \| The query results. Each query result is a list of list of tuples containing the document and the distance. |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### update\_docs

```python theme={null}
update_docs(
    self,
    docs: list[Document],
    collection_name: str = None
) -> None
```

Update documents in the collection of the vector database.<br />

<b>Parameters:</b>

| Name              | Description     |                                                                                                                                   |
| ----------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `docs`            | List\[Document] | A list of documents.<br /><br />**Type:** list\[[Document](/docs/api-reference/autogen/agentchat/contrib/vectordb/base/Document)] |
| `collection_name` | str             | The name of the collection.<br /><br />Default is None.<br /><br />**Type:** str<br /><br />**Default:** None                     |

<b>Returns:</b>

| Type | Description |
| ---- | ----------- |
| None | None        |

<br />
