class_docstr: Base class for handlers associated to vector databases.
class_docstr_tok: ["Base","class","for","handlers","associated","to","vector","databases","."]
code: def do_upsert(self, table_name, df):
      # if handler supports it, call upsert method
  
      id_col = TableField.ID.value
      content_col = TableField.CONTENT.value
  
      def gen_hash(v):
          return hashlib.md5(str(v).encode()).hexdigest()
  
      if id_col not in df.columns:
          # generate for all
          df[id_col] = df[content_col].apply(gen_hash)
      else:
          # generate for empty
          for i in range(len(df)):
              if pd.isna(df.loc[i, id_col]):
                  df.loc[i, id_col] = gen_hash(df.loc[i, content_col])
  
      # remove duplicated ids
      df = df.drop_duplicates([TableField.ID.value])
  
      # id is string TODO is it ok?
      df[id_col] = df[id_col].apply(str)
  
      if hasattr(self, "upsert"):
          self.upsert(table_name, df)
          return
  
      # find existing ids
      res = self.select(
          table_name,
          columns=[id_col],
          conditions=[
              FilterCondition(
                  column=id_col,
                  op=FilterOperator.IN,
                  value=list(df[id_col]),
              )
          ],
      )
      existed_ids = list(res[id_col])
  
      # update existed
      df_update = df[df[id_col].isin(existed_ids)]
      df_insert = df[~df[id_col].isin(existed_ids)]
  
      if not df_update.empty:
          self.update(table_name, df_update, [id_col])
      if not df_insert.empty:
          self.insert(table_name, df_insert)
  
imports: import ast
  import hashlib
  from enum import Enum
  from typing import Any, List, Optional
  import pandas
  from mindsdb_sql.parser.ast import BinaryOperation, Constant, CreateTable, Delete, DropTables, Insert, Select, Star, Tuple, Update
  from mindsdb_sql.parser.ast.base import ASTNode
  from mindsdb.integrations.libs.response import RESPONSE_TYPE, HandlerResponse
  from mindsdb.utilities import log
  from mindsdb.integrations.utilities.sql_utils import conditions_to_filter
  from ..utilities.sql_utils import query_traversal
  from .base import BaseHandler
label_desc: Use image node_id 12 for calling the VectorStoreHandler obj's underlying member method code with example usage: obj.do_upsert(table_name, df) and returns: hashlib