code: import logging
  import os
  import sys
  from shutil import rmtree
  
  import openai
  from llama_index import ServiceContext, SimpleDirectoryReader, TreeIndex
  from llama_index.llms.openai import OpenAI
  
  logging.basicConfig(stream=sys.stdout, level=logging.INFO)
  logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
  
  openai.api_key = "OPENAI_KEY" 
  
  service_context = ServiceContext.from_defaults(llm=OpenAI())
  
  
  def build_index(data_dir: str, knowledge_base_dir: str) -> None:
      """Build the vector index from the markdown files in the directory."""
      print("Building vector index...")
      documents = SimpleDirectoryReader(data_dir).load_data()
  
      index = TreeIndex.from_documents(documents, service_context=service_context)
      index.storage_context.persist(persist_dir=knowledge_base_dir)
      print("Done.")
      
  
  def main() -> None:
      """Build the vector index from the markdown files in the directory."""
      base_dir = os.path.dirname(os.path.abspath(__file__))
      knowledge_base_dir = os.path.join(base_dir, "kb")
      # Delete Storage Directory
      if os.path.exists(knowledge_base_dir):
          rmtree(knowledge_base_dir)
      data_dir = os.path.join(base_dir, "content", "blogs")
      build_index(data_dir, knowledge_base_dir)
  
  
  if __name__ == "__main__":
      main()
  
apis: llama_index.SimpleDirectoryReader llama_index.TreeIndex.from_documents llama_index.llms.openai.OpenAI
extract_api: [((194, 252), 'logging.basicConfig', 'logging.basicConfig', ([], {'stream': 'sys.stdout', 'level': 'logging.INFO'}), '(stream=sys.stdout, level=logging.INFO)\n', (213, 252), False, 'import logging\n'), ((284, 324), 'logging.StreamHandler', 'logging.StreamHandler', ([], {'stream': 'sys.stdout'}), '(stream=sys.stdout)\n', (305, 324), False, 'import logging\n'), ((673, 741), 'llama_index.TreeIndex.from_documents', 'TreeIndex.from_documents', (['documents'], {'service_context': 'service_context'}), '(documents, service_context=service_context)\n', (697, 741), False, 'from llama_index import ServiceContext, SimpleDirectoryReader, TreeIndex\n'), ((1011, 1039), 'os.path.join', 'os.path.join', (['base_dir', '"""kb"""'], {}), "(base_dir, 'kb')\n", (1023, 1039), False, 'import os\n'), ((1078, 1112), 'os.path.exists', 'os.path.exists', (['knowledge_base_dir'], {}), '(knowledge_base_dir)\n', (1092, 1112), False, 'import os\n'), ((1164, 1206), 'os.path.join', 'os.path.join', (['base_dir', '"""content"""', '"""blogs"""'], {}), "(base_dir, 'content', 'blogs')\n", (1176, 1206), False, 'import os\n'), ((253, 272), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (270, 272), False, 'import logging\n'), ((410, 418), 'llama_index.llms.openai.OpenAI', 'OpenAI', ([], {}), '()\n', (416, 418), False, 'from llama_index.llms.openai import OpenAI\n'), ((959, 984), 'os.path.abspath', 'os.path.abspath', (['__file__'], {}), '(__file__)\n', (974, 984), False, 'import os\n'), ((1122, 1148), 'shutil.rmtree', 'rmtree', (['knowledge_base_dir'], {}), '(knowledge_base_dir)\n', (1128, 1148), False, 'from shutil import rmtree\n'), ((616, 647), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['data_dir'], {}), '(data_dir)\n', (637, 647), False, 'from llama_index import ServiceContext, SimpleDirectoryReader, TreeIndex\n')]