code: from pathlib import Path
  from llama_hub.file.unstructured import UnstructuredReader
  from pathlib import Path
  from llama_index import download_loader
  from llama_index import SimpleDirectoryReader, VectorStoreIndex
  from dotenv import load_dotenv
  import os
  from llama_index.node_parser import SimpleNodeParser
  import pinecone
  from llama_index.vector_stores import PineconeVectorStore
  from llama_index import GPTVectorStoreIndex, StorageContext, ServiceContext
  from llama_index.embeddings.openai import OpenAIEmbedding
  import openai
  
  ####################################################
  #                                                  #
  # This file upserts documents in data to pinecone. #
  #                                                  #
  ####################################################
  
  load_dotenv()
  openai.api_key = os.getenv('api_key')
  # find API key in console at app.pinecone.io
  os.environ['PINECONE_API_KEY'] = os.getenv('pinecone_api_key')
  # environment is found next to API key in the console
  os.environ['PINECONE_ENVIRONMENT'] = os.getenv('pinecone_env')
  
  # loader = UnstructuredReader()
  
  # initialize connection to pinecone
  pinecone.init(
      api_key=os.environ['PINECONE_API_KEY'],
      environment=os.environ['PINECONE_ENVIRONMENT']
  )
  
  # setup the index/query process, ie the embedding model (and completion if used)
  embed_model = OpenAIEmbedding(model='text-embedding-ada-002', embed_batch_size=100)
  service_context = ServiceContext.from_defaults(embed_model=embed_model)
  
  # Readers
  PDFReader = download_loader("PDFReader")
  MarkdownReader = download_loader("MarkdownReader")
  
  # Load docs
  def upsert_docs(input_dir: str, index_name: str):
      print(f"Building from {input_dir} under index {index_name}...\n")
      documents = SimpleDirectoryReader(input_dir=input_dir).load_data()
      
      # create the index if it does not exist already
      if index_name not in pinecone.list_indexes():
          pinecone.create_index(
              name=index_name,
              dimension=1536,
              metric='cosine'
          )
  
      # connect to the index
      pineconeIndex = pinecone.Index(index_name)
  
      vectorStore = PineconeVectorStore(
          pinecone_index=pineconeIndex
      )
  
      # setup our storage (vector db)
      storageContext = StorageContext.from_defaults(
          vector_store=vectorStore
      )
  
      index = GPTVectorStoreIndex.from_documents(
          documents=documents, 
          storage_context=storageContext,
          service_context=service_context
      )
      print(f"Done building !\n")
  
  upsert_docs(input_dir="upsert_doc/docs", index_name="ruikang-guo-knowledge-base")
  
apis: llama_index.GPTVectorStoreIndex.from_documents llama_index.vector_stores.PineconeVectorStore llama_index.ServiceContext.from_defaults llama_index.StorageContext.from_defaults llama_index.SimpleDirectoryReader llama_index.download_loader llama_index.embeddings.openai.OpenAIEmbedding
extract_api: [((796, 809), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (807, 809), False, 'from dotenv import load_dotenv\n'), ((827, 847), 'os.getenv', 'os.getenv', (['"""api_key"""'], {}), "('api_key')\n", (836, 847), False, 'import os\n'), ((926, 955), 'os.getenv', 'os.getenv', (['"""pinecone_api_key"""'], {}), "('pinecone_api_key')\n", (935, 955), False, 'import os\n'), ((1047, 1072), 'os.getenv', 'os.getenv', (['"""pinecone_env"""'], {}), "('pinecone_env')\n", (1056, 1072), False, 'import os\n'), ((1143, 1249), 'pinecone.init', 'pinecone.init', ([], {'api_key': "os.environ['PINECONE_API_KEY']", 'environment': "os.environ['PINECONE_ENVIRONMENT']"}), "(api_key=os.environ['PINECONE_API_KEY'], environment=os.\n    environ['PINECONE_ENVIRONMENT'])\n", (1156, 1249), False, 'import pinecone\n'), ((1351, 1420), 'llama_index.embeddings.openai.OpenAIEmbedding', 'OpenAIEmbedding', ([], {'model': '"""text-embedding-ada-002"""', 'embed_batch_size': '(100)'}), "(model='text-embedding-ada-002', embed_batch_size=100)\n", (1366, 1420), False, 'from llama_index.embeddings.openai import OpenAIEmbedding\n'), ((1439, 1492), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'embed_model': 'embed_model'}), '(embed_model=embed_model)\n', (1467, 1492), False, 'from llama_index import GPTVectorStoreIndex, StorageContext, ServiceContext\n'), ((1516, 1544), 'llama_index.download_loader', 'download_loader', (['"""PDFReader"""'], {}), "('PDFReader')\n", (1531, 1544), False, 'from llama_index import download_loader\n'), ((1562, 1595), 'llama_index.download_loader', 'download_loader', (['"""MarkdownReader"""'], {}), "('MarkdownReader')\n", (1577, 1595), False, 'from llama_index import download_loader\n'), ((2081, 2107), 'pinecone.Index', 'pinecone.Index', (['index_name'], {}), '(index_name)\n', (2095, 2107), False, 'import pinecone\n'), ((2127, 2176), 'llama_index.vector_stores.PineconeVectorStore', 'PineconeVectorStore', ([], {'pinecone_index': 'pineconeIndex'}), '(pinecone_index=pineconeIndex)\n', (2146, 2176), False, 'from llama_index.vector_stores import PineconeVectorStore\n'), ((2249, 2303), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'vector_store': 'vectorStore'}), '(vector_store=vectorStore)\n', (2277, 2303), False, 'from llama_index import GPTVectorStoreIndex, StorageContext, ServiceContext\n'), ((2331, 2456), 'llama_index.GPTVectorStoreIndex.from_documents', 'GPTVectorStoreIndex.from_documents', ([], {'documents': 'documents', 'storage_context': 'storageContext', 'service_context': 'service_context'}), '(documents=documents, storage_context=\n    storageContext, service_context=service_context)\n', (2365, 2456), False, 'from llama_index import GPTVectorStoreIndex, StorageContext, ServiceContext\n'), ((1882, 1905), 'pinecone.list_indexes', 'pinecone.list_indexes', ([], {}), '()\n', (1903, 1905), False, 'import pinecone\n'), ((1915, 1986), 'pinecone.create_index', 'pinecone.create_index', ([], {'name': 'index_name', 'dimension': '(1536)', 'metric': '"""cosine"""'}), "(name=index_name, dimension=1536, metric='cosine')\n", (1936, 1986), False, 'import pinecone\n'), ((1745, 1787), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', ([], {'input_dir': 'input_dir'}), '(input_dir=input_dir)\n', (1766, 1787), False, 'from llama_index import SimpleDirectoryReader, VectorStoreIndex\n')]