code: """
  This script demonstrates how to use the llama_index library to create and query a vector store index.
  It loads documents from a directory, creates an index, and allows querying the index.
  
  usage: python hello_persist.py "What is the author's name and job now?"
  """
  
  import os
  import sys
  import argparse
  import logging
  from dotenv import load_dotenv
  from llama_index.core import (
      VectorStoreIndex,
      SimpleDirectoryReader,
      StorageContext,
      load_index_from_storage,
      Settings,
  )
  from llama_index.embeddings.openai import OpenAIEmbedding
  
  def main(query):
      try:
          # Load environment variables
          load_dotenv()
  
          # Configure logging
          logging.basicConfig(stream=sys.stdout, level=logging.INFO)
          logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
  
          # Configure embedding model
          Settings.embed_model = OpenAIEmbedding(model_name="text-embedding-3-small")
  
          # Set up storage directory
          storage_directory = "./storage"
  
          if not os.path.exists(storage_directory):
              logging.info("Creating new index...")
              documents = SimpleDirectoryReader("data").load_data()
              index = VectorStoreIndex.from_documents(documents)
              index.storage_context.persist(persist_dir=storage_directory)
          else:
              logging.info("Loading existing index...")
              storage_context = StorageContext.from_defaults(persist_dir=storage_directory)
              index = load_index_from_storage(storage_context)
  
          # Query the index
          query_engine = index.as_query_engine()
          response = query_engine.query(query)
          print(response)
  
      except Exception as e:
          logging.error(f"An error occurred: {str(e)}")
  
  if __name__ == "__main__":
      parser = argparse.ArgumentParser(description="Query a vector store index.")
      parser.add_argument("--query", default="What is the author's name and job now?", help="The query to ask the index.")
      args = parser.parse_args()
  
      main(args.query)
apis: llama_index.core.StorageContext.from_defaults llama_index.core.VectorStoreIndex.from_documents llama_index.core.SimpleDirectoryReader llama_index.core.load_index_from_storage llama_index.embeddings.openai.OpenAIEmbedding
extract_api: [((1804, 1870), 'argparse.ArgumentParser', 'argparse.ArgumentParser', ([], {'description': '"""Query a vector store index."""'}), "(description='Query a vector store index.')\n", (1827, 1870), False, 'import argparse\n'), ((628, 641), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (639, 641), False, 'from dotenv import load_dotenv\n'), ((679, 737), 'logging.basicConfig', 'logging.basicConfig', ([], {'stream': 'sys.stdout', 'level': 'logging.INFO'}), '(stream=sys.stdout, level=logging.INFO)\n', (698, 737), False, 'import logging\n'), ((887, 939), 'llama_index.embeddings.openai.OpenAIEmbedding', 'OpenAIEmbedding', ([], {'model_name': '"""text-embedding-3-small"""'}), "(model_name='text-embedding-3-small')\n", (902, 939), False, 'from llama_index.embeddings.openai import OpenAIEmbedding\n'), ((777, 817), 'logging.StreamHandler', 'logging.StreamHandler', ([], {'stream': 'sys.stdout'}), '(stream=sys.stdout)\n', (798, 817), False, 'import logging\n'), ((1032, 1065), 'os.path.exists', 'os.path.exists', (['storage_directory'], {}), '(storage_directory)\n', (1046, 1065), False, 'import os\n'), ((1079, 1116), 'logging.info', 'logging.info', (['"""Creating new index..."""'], {}), "('Creating new index...')\n", (1091, 1116), False, 'import logging\n'), ((1203, 1245), 'llama_index.core.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['documents'], {}), '(documents)\n', (1234, 1245), False, 'from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage, Settings\n'), ((1345, 1386), 'logging.info', 'logging.info', (['"""Loading existing index..."""'], {}), "('Loading existing index...')\n", (1357, 1386), False, 'import logging\n'), ((1417, 1476), 'llama_index.core.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'persist_dir': 'storage_directory'}), '(persist_dir=storage_directory)\n', (1445, 1476), False, 'from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage, Settings\n'), ((1497, 1537), 'llama_index.core.load_index_from_storage', 'load_index_from_storage', (['storage_context'], {}), '(storage_context)\n', (1520, 1537), False, 'from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage, Settings\n'), ((746, 765), 'logging.getLogger', 'logging.getLogger', ([], {}), '()\n', (763, 765), False, 'import logging\n'), ((1141, 1170), 'llama_index.core.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""data"""'], {}), "('data')\n", (1162, 1170), False, 'from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext, load_index_from_storage, Settings\n')]