code: from pathlib import Path
  from llama_index import Document, SimpleDirectoryReader, download_loader
  from llama_index.query_engine import RetrieverQueryEngine
  from llama_index import GPTVectorStoreIndex, StorageContext, ServiceContext
  from llama_index.embeddings.openai import OpenAIEmbedding
  from llama_index.vector_stores import PineconeVectorStore
  import pinecone
  import os
  from llama_index.node_parser import SimpleNodeParser
  import openai
  from dotenv import load_dotenv
  from os import getenv
  
  
  
  
  def query_research(message):
      load_dotenv()
  
      #openai.api_key_path = getenv('OPENAI_API_KEY')
  
  
      #constructor
      #  def __init__(
      #         self,
      #         api_key,
      #         api_username,
      #         openai_api_key=None,
      #         base_url='https://forum.subspace.network',
      #         verbose=True,
      #     ):
  
      #load PDF
      # PDFReader = download_loader("PDFReader")
      # loader = PDFReader()
      # docs = loader.load_data(file=Path('../../data/whitepaper.pdf'))
  
      docs = SimpleDirectoryReader('/Users/ryanyeung/Code/Crypto/SupportGPT/supportgpt/sources/data').load_data()
      #parse PDF
      parser = SimpleNodeParser()
      nodes = parser.get_nodes_from_documents(docs)
  
      # initialize connection to pinecone
      # pinecone.init(
      #     getenv('PINECONE_API_KEY'),
      #     getenv('PINECONE_ENVIRONMENT'),
      # )
  
      pinecone.init(
          api_key=os.environ['PINECONE_API_KEY'],
                  environment=os.environ['PINECONE_ENVIRONMENT']
      )
  
      # create the index if it does not exist already
      index_name = 'research-test'
      if index_name not in pinecone.list_indexes():
          pinecone.create_index(
              index_name,
              dimension=1536,
              metric='cosine'
          )
  
      # connect to the index
      pinecone_index = pinecone.Index(index_name)
          
  
      # we can select a namespace (acts as a partition in an index)
      namespace = '' # default namespace
      vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
  
  
      # setup our storage (vector db)
      storage_context = StorageContext.from_defaults(
          vector_store=vector_store
      )
      # 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)
  
      index = GPTVectorStoreIndex.from_documents(
          docs, storage_context=storage_context,
          service_context=service_context
      )
  
      # retriever = index.as_retriever(retriever_mode='default')
      # query_engine = RetrieverQueryEngine(retriever)
      # #query_engine = RetrieverQueryEngine.from_args(retriever, response_mode='default')
  
      query_engine = index.as_query_engine()
      res = query_engine.query(message)
  
      return str(res)
  
  
      # print(str(res))
      # print(res.get_formatted_sources())
  
      #pinecone.delete_index(index_name)
apis: llama_index.GPTVectorStoreIndex.from_documents llama_index.vector_stores.PineconeVectorStore llama_index.node_parser.SimpleNodeParser llama_index.ServiceContext.from_defaults llama_index.StorageContext.from_defaults llama_index.SimpleDirectoryReader llama_index.embeddings.openai.OpenAIEmbedding
extract_api: [((531, 544), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (542, 544), False, 'from dotenv import load_dotenv\n'), ((1142, 1160), 'llama_index.node_parser.SimpleNodeParser', 'SimpleNodeParser', ([], {}), '()\n', (1158, 1160), False, 'from llama_index.node_parser import SimpleNodeParser\n'), ((1366, 1472), '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", (1379, 1472), False, 'import pinecone\n'), ((1804, 1830), 'pinecone.Index', 'pinecone.Index', (['index_name'], {}), '(index_name)\n', (1818, 1830), False, 'import pinecone\n'), ((1965, 2015), 'llama_index.vector_stores.PineconeVectorStore', 'PineconeVectorStore', ([], {'pinecone_index': 'pinecone_index'}), '(pinecone_index=pinecone_index)\n', (1984, 2015), False, 'from llama_index.vector_stores import PineconeVectorStore\n'), ((2076, 2131), 'llama_index.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'vector_store': 'vector_store'}), '(vector_store=vector_store)\n', (2104, 2131), False, 'from llama_index import GPTVectorStoreIndex, StorageContext, ServiceContext\n'), ((2249, 2318), '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", (2264, 2318), False, 'from llama_index.embeddings.openai import OpenAIEmbedding\n'), ((2341, 2394), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'embed_model': 'embed_model'}), '(embed_model=embed_model)\n', (2369, 2394), False, 'from llama_index import GPTVectorStoreIndex, StorageContext, ServiceContext\n'), ((2408, 2518), 'llama_index.GPTVectorStoreIndex.from_documents', 'GPTVectorStoreIndex.from_documents', (['docs'], {'storage_context': 'storage_context', 'service_context': 'service_context'}), '(docs, storage_context=storage_context,\n    service_context=service_context)\n', (2442, 2518), False, 'from llama_index import GPTVectorStoreIndex, StorageContext, ServiceContext\n'), ((1609, 1632), 'pinecone.list_indexes', 'pinecone.list_indexes', ([], {}), '()\n', (1630, 1632), False, 'import pinecone\n'), ((1642, 1708), 'pinecone.create_index', 'pinecone.create_index', (['index_name'], {'dimension': '(1536)', 'metric': '"""cosine"""'}), "(index_name, dimension=1536, metric='cosine')\n", (1663, 1708), False, 'import pinecone\n'), ((1013, 1106), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""/Users/ryanyeung/Code/Crypto/SupportGPT/supportgpt/sources/data"""'], {}), "(\n    '/Users/ryanyeung/Code/Crypto/SupportGPT/supportgpt/sources/data')\n", (1034, 1106), False, 'from llama_index import Document, SimpleDirectoryReader, download_loader\n')]