> ## 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.tidb

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

<a id="camel.storages.vectordb_storages.tidb.EnumEncoder" />

## EnumEncoder

```python theme={"system"}
class EnumEncoder(JSONEncoder):
```

<a id="camel.storages.vectordb_storages.tidb.EnumEncoder.default" />

### default

```python theme={"system"}
def default(self, obj):
```

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage" />

## TiDBStorage

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

An implementation of the `BaseVectorStorage` for interacting with TiDB.

The detailed information about TiDB is available at:
`TiDB Vector Search <https://pingcap.com/ai>`\_

**Parameters:**

* **vector\_dim** (int): The dimension of storing vectors.
* **url\_and\_api\_key** (Optional\[Union\[Tuple\[str, str], str]]): A tuple containing the database url and API key for connecting to a TiDB cluster. The URL should be in the format: "mysql+pymysql://`<username>`:`<password>`@`<host>`:`<port>`/`<db_name>`". TiDB will not use the API Key, but retains the definition for interface compatible.
* **collection\_name** (Optional\[str]): Name of the collection. The collection name will be used as the table name in TiDB. If not provided, set it to the current time with iso format. \*\*kwargs (Any): Additional keyword arguments for initializing TiDB connection.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    vector_dim: int,
    collection_name: Optional[str] = None,
    url_and_api_key: Optional[Union[Tuple[str, str], str]] = None,
    **kwargs: Any
):
```

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage._create_client" />

### \_create\_client

```python theme={"system"}
def _create_client(self, database_url: Optional[str] = None, **kwargs: Any):
```

Initializes the TiDB client with the provided connection details.

**Parameters:**

* **database\_url** (Optional\[str]): The database connection string for the TiDB server. \*\*kwargs: Additional keyword arguments passed to the TiDB client.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage._get_table_model" />

### \_get\_table\_model

```python theme={"system"}
def _get_table_model(self, collection_name: str):
```

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage._open_and_create_table" />

### \_open\_and\_create\_table

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

Opens an existing table or creates a new table in TiDB.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage._check_table" />

### \_check\_table

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

Ensuring the specified table matches the specified vector
dimensionality.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage._generate_table_name" />

### \_generate\_table\_name

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

**Returns:**

str: A unique, valid table name.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage._get_table_info" />

### \_get\_table\_info

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

**Returns:**

Dict\[str, Any]: A dictionary containing details about the
table.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage._validate_and_convert_vectors" />

### \_validate\_and\_convert\_vectors

```python theme={"system"}
def _validate_and_convert_vectors(self, records: List[VectorRecord]):
```

Validates and converts VectorRecord instances to VectorDBRecord
instances.

**Parameters:**

* **records** (List\[VectorRecord]): List of vector records to validate and convert.

**Returns:**

List\[VectorDBRecord]: A list of VectorDBRecord instances.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage.add" />

### add

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

Adds a list of vectors to the specified table.

**Parameters:**

* **records** (List\[VectorRecord]): List of vectors to be added. \*\*kwargs (Any): Additional keyword arguments pass to insert.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage.delete" />

### delete

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

Deletes a list of vectors identified by their IDs from the
storage.

**Parameters:**

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

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage.status" />

### status

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

**Returns:**

VectorDBStatus: An object containing information about the
table's status.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage.query" />

### query

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

Searches for similar vectors in the storage 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 passed to search.

**Returns:**

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

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage.clear" />

### clear

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

Removes all vectors from the TiDB table. This method
deletes the existing table and then recreates it with the same
schema to effectively remove all stored vectors.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage.load" />

### load

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

Load the collection hosted on cloud service.

<a id="camel.storages.vectordb_storages.tidb.TiDBStorage.client" />

### client

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

**Returns:**

Any: The TiDB client instance.
