from llama_index import Document text_list = [text1, text2, ...] documents = [Document(t) for t in text_list]
response.source_nodes
# 1. Load in Documents os.environ["OPENAI_API_KEY"] = <api key> text1="sammple text 1" text2="sammple text 2" text3="sammple text 3" #doc_id here represents page number node1 = Node(text=text1, doc_id=1) node2 = Node(text=text2, doc_id=2) node3 = Node(text=text3, doc_id=3) nodes=[node1,node2,node3] storage_context = StorageContext.from_defaults() storage_context.docstore.add_documents(nodes) index1 = GPTVectorStoreIndex(nodes, storage_context=storage_context) index = GPTVectorStoreIndex([]) index.insert_nodes(nodes) max_input_size = 4096 # set number of output tokens num_outputs = 256 # set maximum chunk overlap max_chunk_overlap = 20 # set chunk size limit chunk_size_limit = 600 prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit) # define LLM llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-003", max_tokens=num_outputs)) service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor)
documents = SimpleDirectoryReader("./data").load_data() index = GPTVectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine() response = query_engine.query("my query") print(str(response))