class_docstr: This handler handles connection and execution of the LanceDB statements.
class_docstr_tok: ["This","handler","handles","connection","and","execution","of","the","LanceDB","statements","."]
docstr: Insert data into the LanceDB database.
  In case of create table statements the there is a mismatch between the column types of the `data` pandas dataframe filled with data
  and the empty base table column types which raises a pa.lib.ArrowNotImplementedError, in that case the base table is deleted (doesn't matter as it is empty)
  and recreated with the right datatypes
docstr_tok: ["Insert","data","into","the","LanceDB","database",".","In","case","of","create","table","statements","the","there","is","a","mismatch","between","the","column","types","of","the","`","data","`","pandas","dataframe","filled","with","data","and","the","empty","base","table","column","types","which","raises","a","pa.lib.ArrowNotImplementedError",",","in","that","case","the","base","table","is","deleted","(","does","n't","matter","as","it","is","empty",")","and","recreated","with","the","right","datatypes"]
code: def insert(
      self,
      table_name: str,
      data: pd.DataFrame,
      columns: List[str] = None,
  ) -> HandlerResponse:
      """
      Insert data into the LanceDB database.
      In case of create table statements the there is a mismatch between the column types of the `data` pandas dataframe filled with data
      and the empty base table column types which raises a pa.lib.ArrowNotImplementedError, in that case the base table is deleted (doesn't matter as it is empty)
      and recreated with the right datatypes
      """
      try:
          collection = self._client.open_table(table_name)
          df = data[
              [
                  TableField.ID.value,
                  TableField.CONTENT.value,
                  TableField.METADATA.value,
                  TableField.EMBEDDINGS.value,
              ]
          ]
          pa_data = pa.Table.from_pandas(df, preserve_index=False)
          vec_data = vec_to_table(
              df[TableField.EMBEDDINGS.value].values.tolist()
          )
          new_pa_data = pa_data.append_column(
              "vector", vec_data["vector"]
          )
          collection.add(new_pa_data)
      except pa.lib.ArrowNotImplementedError:
          collection_df = collection.to_pandas()
          column_dtypes = collection_df.dtypes
          df = df.astype(column_dtypes)
          new_df = pd.concat([collection_df, df])
          new_df["id"] = new_df["id"].apply(str)
          pa_data = pa.Table.from_pandas(new_df, preserve_index=False)
          vec_data = vec_to_table(
              df[TableField.EMBEDDINGS.value].values.tolist()
          )
          new_pa_data = pa_data.append_column(
              "vector", vec_data["vector"]
          )
          self.drop_table(table_name)
          self._client.create_table(table_name, new_pa_data)
      except Exception as e:
          return Response(
              resp_type=RESPONSE_TYPE.ERROR,
              error_message=f"Unable to insert data into collection `{table_name}`: {e}",
          )
      return Response(resp_type=RESPONSE_TYPE.OK)
  
imports: from collections import OrderedDict
  from typing import List, Optional
  import lancedb
  import pandas
  import pyarrow
  from lance.vector import vec_to_table
  import duckdb
  import json
  from mindsdb.integrations.libs.const import HANDLER_CONNECTION_ARG_TYPE
  from mindsdb.integrations.libs.response import RESPONSE_TYPE
  from mindsdb.integrations.libs.response import HandlerResponse
  from mindsdb.integrations.libs.response import HandlerResponse
  from mindsdb.integrations.libs.response import HandlerStatusResponse
  from mindsdb.integrations.libs.vectordatabase_handler import FilterCondition, FilterOperator, TableField, VectorStoreHandler
  from mindsdb.utilities import log
label_desc: Use image node_id 10 for calling the LanceDBHandler obj's underlying member method code with example usage: obj.insert(table_name, data, columns) and returns: Response, Response