code: def add_kb(kb_name=u"Untitled", kb_type=None, tries=10):
      
      created = False
      name = kb_name
      i = 0
      while(i < tries and created is False):
          try:
              kb = models.KnwKB(name=name, description="", kbtype=kb_type)
              created = True
              db.session.add(kb)
              db.session.commit()
          except IntegrityError:
              db.session.rollback()
              # get the highest id to calculate the new name
              result = db.session.execute(
                  db.select([models.KnwKB.id])
                  .order_by(db.desc(models.KnwKB.id))
                  .limit(1)).first()
              index = result[0] + 1 if result is not None else 1
              name = kb_name + " " + str(index)
              i = i + 1
              created = False
          except Exception:
              db.session.rollback()
              raise
  
      if created is False:
          # TODO raise the right exception
          raise Exception(_("Can't create knowledge base \"%(name)s\".\n"
                            "Probabily the server is busy! "
                            "Try again later.", name=kb_name))
  
      return kb.id
docs: Add a new kb in database, return the id.
  
      Add a new kb in database, and returns its id
      The name of the kb will be 'Untitled#'
      such that it is unique.
  
      :param kb_name: the name of the kb
      :param kb_type: the type of the kb, incl 'taxonomy' and 'dynamic'.
                     None for typical (leftside-rightside).
      :param tries: exit after <n> retry
      :return: the id of the newly created kb