code: import logging
  import sys
  
  logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
  logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
  
  import os
  from dotenv import load_dotenv
  load_dotenv()
  
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
  bulk_data = True
  
  # ----------------------------------
  
  async def connect_to_elasticsearch():
      # Instantiate the Elasticsearch client right away to check we can connect
  
      from elasticsearch import AsyncElasticsearch
      es_client = AsyncElasticsearch(
          [os.getenv("ES_URL")],
          ssl_assert_fingerprint=os.getenv("ES_CERTIFICATE_FINGERPRINT"),
          basic_auth=(os.getenv("ES_USERNAME"), os.getenv("ES_PASSWORD"))
      )
      
      await es_client.info() # this connects to the cluster and gets its version
      if bulk_data:        
          await es_client.indices.delete(index=os.getenv("ES_DEFAULT_INDEX"), ignore=[400, 404])
  
      return es_client
  
  
  
  def load_data(es_client):
      from llama_index import SimpleDirectoryReader
  
      # Creates a reader for the /data folder        
      if bulk_data:
          documents = SimpleDirectoryReader("python/data").load_data(show_progress=True)
  
      # Creates the ES vector store
      from llama_index.vector_stores import ElasticsearchStore
      ES_DEFAULT_INDEX = os.getenv("ES_DEFAULT_INDEX")
  
      es_vector_store = ElasticsearchStore(
          index_name=ES_DEFAULT_INDEX,
          es_client=es_client ,
          
      )
  
      # Service ctx for debug
      from llama_index import ServiceContext
      from llama_index.llms import OpenAI
      
      llm = OpenAI(model="gpt-3.5-turbo", temperature=0)
      
      from llama_index.embeddings import HuggingFaceEmbedding    
      embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
  
      service_context = ServiceContext.from_defaults(
          # callback_manager=callback_manager, 
          llm=llm,
          embed_model=embed_model
      )
  
      # Creates the index
      import llama_index
      llama_index.set_global_handler("simple")
  
      from llama_index import VectorStoreIndex
      from llama_index.storage.storage_context import StorageContext
  
      storage_context = StorageContext.from_defaults(vector_store=es_vector_store)
      
      if bulk_data:
          index = VectorStoreIndex.from_documents(
              documents, 
              storage_context=storage_context, 
              service_context=service_context
          )
      else:
          index = VectorStoreIndex.from_vector_store(
              vector_store=es_vector_store, 
              service_context=service_context)        
      
      from llama_hub.youtube_transcript import YoutubeTranscriptReader
  
      loader = YoutubeTranscriptReader()
      documents = loader.load_data(ytlinks=['https://www.youtube.com/watch?v=i3OYlaoj-BM'])
  
      index = VectorStoreIndex.from_documents(
              documents, storage_context=storage_context, service_context=service_context
          )
  
      return index
  
  async def main():
      es_client = await connect_to_elasticsearch()
      index = load_data(es_client)
      
      # set Logging to DEBUG for more detailed outputs
      query_engine = index.as_query_engine()
      
      # What is Prince and what can you tell me about Hyphenation?
      while (True):
          question = input("Enter your question: ")
          if question == "":
              question = "what is the address of the bank of yes logic?"
          response = query_engine.query(question)
          
          print("**************************** REFERENCES ****************************")
          print("Refs " + str(response.source_nodes))
          print("**************************** Q&A ****************************")
          print("Q: " + question)
          print("A: " + str(response))        
  
  import asyncio
  
  loop = asyncio.get_event_loop()
  loop.run_until_complete(main())
  
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.ServiceContext.from_defaults llama_index.set_global_handler llama_index.storage.storage_context.StorageContext.from_defaults llama_index.SimpleDirectoryReader llama_index.llms.OpenAI llama_index.VectorStoreIndex.from_vector_store llama_index.embeddings.HuggingFaceEmbedding llama_index.vector_stores.ElasticsearchStore
extract_api: [((27, 86), 'logging.basicConfig', 'logging.basicConfig', ([], {'stream': 'sys.stdout', 'level': 'logging.DEBUG'}), '(stream=sys.stdout, level=logging.DEBUG)\n', (46, 86), False, 'import logging\n'), ((202, 215), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (213, 215), False, 'from dotenv import load_dotenv\n'), ((234, 261), 'os.getenv', 'os.getenv', (['"""OPENAI_API_KEY"""'], {}), "('OPENAI_API_KEY')\n", (243, 261), False, 'import os\n'), ((3747, 3771), 'asyncio.get_event_loop', 'asyncio.get_event_loop', ([], {}), '()\n', (3769, 3771), False, 'import asyncio\n'), ((118, 158), 'logging.StreamHandler', 'logging.StreamHandler', ([], {'stream': 'sys.stdout'}), '(stream=sys.stdout)\n', (139, 158), False, 'import logging\n'), ((1284, 1313), 'os.getenv', 'os.getenv', (['"""ES_DEFAULT_INDEX"""'], {}), "('ES_DEFAULT_INDEX')\n", (1293, 1313), False, 'import os\n'), ((1337, 1405), 'llama_index.vector_stores.ElasticsearchStore', 'ElasticsearchStore', ([], {'index_name': 'ES_DEFAULT_INDEX', 'es_client': 'es_client'}), '(index_name=ES_DEFAULT_INDEX, es_client=es_client)\n', (1355, 1405), False, 'from llama_index.vector_stores import ElasticsearchStore\n'), ((1566, 1610), 'llama_index.llms.OpenAI', 'OpenAI', ([], {'model': '"""gpt-3.5-turbo"""', 'temperature': '(0)'}), "(model='gpt-3.5-turbo', temperature=0)\n", (1572, 1610), False, 'from llama_index.llms import OpenAI\n'), ((1698, 1771), 'llama_index.embeddings.HuggingFaceEmbedding', 'HuggingFaceEmbedding', ([], {'model_name': '"""sentence-transformers/all-MiniLM-L6-v2"""'}), "(model_name='sentence-transformers/all-MiniLM-L6-v2')\n", (1718, 1771), False, 'from llama_index.embeddings import HuggingFaceEmbedding\n'), ((1795, 1857), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm': 'llm', 'embed_model': 'embed_model'}), '(llm=llm, embed_model=embed_model)\n', (1823, 1857), False, 'from llama_index import ServiceContext\n'), ((1978, 2018), 'llama_index.set_global_handler', 'llama_index.set_global_handler', (['"""simple"""'], {}), "('simple')\n", (2008, 2018), False, 'import llama_index\n'), ((2155, 2213), 'llama_index.storage.storage_context.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'vector_store': 'es_vector_store'}), '(vector_store=es_vector_store)\n', (2183, 2213), False, 'from llama_index.storage.storage_context import StorageContext\n'), ((2656, 2681), 'llama_hub.youtube_transcript.YoutubeTranscriptReader', 'YoutubeTranscriptReader', ([], {}), '()\n', (2679, 2681), False, 'from llama_hub.youtube_transcript import YoutubeTranscriptReader\n'), ((2785, 2897), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {'storage_context': 'storage_context', 'service_context': 'service_context'}), '(documents, storage_context=storage_context,\n    service_context=service_context)\n', (2816, 2897), False, 'from llama_index import VectorStoreIndex\n'), ((87, 106), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (104, 106), False, 'import logging\n'), ((2253, 2365), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {'storage_context': 'storage_context', 'service_context': 'service_context'}), '(documents, storage_context=storage_context,\n    service_context=service_context)\n', (2284, 2365), False, 'from llama_index import VectorStoreIndex\n'), ((2436, 2537), 'llama_index.VectorStoreIndex.from_vector_store', 'VectorStoreIndex.from_vector_store', ([], {'vector_store': 'es_vector_store', 'service_context': 'service_context'}), '(vector_store=es_vector_store,\n    service_context=service_context)\n', (2470, 2537), False, 'from llama_index import VectorStoreIndex\n'), ((529, 548), 'os.getenv', 'os.getenv', (['"""ES_URL"""'], {}), "('ES_URL')\n", (538, 548), False, 'import os\n'), ((582, 621), 'os.getenv', 'os.getenv', (['"""ES_CERTIFICATE_FINGERPRINT"""'], {}), "('ES_CERTIFICATE_FINGERPRINT')\n", (591, 621), False, 'import os\n'), ((643, 667), 'os.getenv', 'os.getenv', (['"""ES_USERNAME"""'], {}), "('ES_USERNAME')\n", (652, 667), False, 'import os\n'), ((669, 693), 'os.getenv', 'os.getenv', (['"""ES_PASSWORD"""'], {}), "('ES_PASSWORD')\n", (678, 693), False, 'import os\n'), ((1098, 1134), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""python/data"""'], {}), "('python/data')\n", (1119, 1134), False, 'from llama_index import SimpleDirectoryReader\n'), ((856, 885), 'os.getenv', 'os.getenv', (['"""ES_DEFAULT_INDEX"""'], {}), "('ES_DEFAULT_INDEX')\n", (865, 885), False, 'import os\n')]