Chintan-Donda commited on
Commit
89ee6d6
1 Parent(s): f181070

Update src/langchain_utils.py

Browse files
Files changed (1) hide show
  1. src/langchain_utils.py +12 -12
src/langchain_utils.py CHANGED
@@ -13,7 +13,7 @@ import chromadb
13
  from langchain.chains.question_answering import load_qa_chain
14
  from langchain.chains.qa_with_sources import load_qa_with_sources_chain
15
  from langchain.prompts import PromptTemplate
16
- from llama_index import GPTSimpleVectorIndex, GPTListIndex
17
  from langchain.vectorstores import FAISS
18
 
19
  import pickle
@@ -329,8 +329,8 @@ class LANGCHAIN_UTILS:
329
  )
330
 
331
  # Vector store using GPT vector index
332
- elif self.index_type == 'GPTSimpleVectorIndex':
333
- self.index = GPTSimpleVectorIndex.from_documents(self.documents)
334
 
335
  logger.info(f'Index created successfully!')
336
  return self.index
@@ -486,7 +486,7 @@ class LANGCHAIN_UTILS:
486
  elif self.index_type == 'Chroma':
487
  index.persist()
488
 
489
- elif self.index_type == 'GPTSimpleVectorIndex':
490
  index.save_to_disk(index_filepath)
491
 
492
  elif self.index_type == 'pickle':
@@ -514,8 +514,8 @@ class LANGCHAIN_UTILS:
514
  embedding_function=self.embeddings
515
  )
516
 
517
- elif self.index_type == 'GPTSimpleVectorIndex':
518
- self.index = GPTSimpleVectorIndex.load_from_disk(self.index_filepath)
519
 
520
  elif self.index_type == 'pickle':
521
  with open(self.index_filepath, "rb") as f:
@@ -543,9 +543,9 @@ class LANGCHAIN_UTILS:
543
  url_documents
544
  ):
545
  # Build the Vector store for docs
546
- doc_index = GPTSimpleVectorIndex.from_documents(doc_documents)
547
  # Build the Vector store for URLs
548
- url_index = GPTSimpleVectorIndex.from_documents(url_documents)
549
 
550
  # Set summary of each index
551
  doc_index.set_text("index_from_docs")
@@ -592,10 +592,10 @@ class LANGCHAIN_UTILS:
592
  continue
593
  raise NotImplementedError
594
 
595
- elif self.index_type == 'GPTSimpleVectorIndex':
596
  for doc_type, index in doc_type_indices.items():
597
- if not index or not isinstance(index, GPTSimpleVectorIndex):
598
- logger.warning(f'{doc_type} index to be merged is not an instance of type llama_index.GPTSimpleVectorIndex')
599
  continue
600
  import pdb; pdb.set_trace()
601
  raise NotImplementedError
@@ -676,7 +676,7 @@ class LANGCHAIN_UTILS:
676
  k=similarity_top_k
677
  )
678
 
679
- elif self.index_type == 'GPTSimpleVectorIndex':
680
  # Querying the index
681
  response = index.query(
682
  question,
 
13
  from langchain.chains.question_answering import load_qa_chain
14
  from langchain.chains.qa_with_sources import load_qa_with_sources_chain
15
  from langchain.prompts import PromptTemplate
16
+ from llama_index import GPTVectorStoreIndex, GPTListIndex
17
  from langchain.vectorstores import FAISS
18
 
19
  import pickle
 
329
  )
330
 
331
  # Vector store using GPT vector index
332
+ elif self.index_type == 'GPTVectorStoreIndex':
333
+ self.index = GPTVectorStoreIndex.from_documents(self.documents)
334
 
335
  logger.info(f'Index created successfully!')
336
  return self.index
 
486
  elif self.index_type == 'Chroma':
487
  index.persist()
488
 
489
+ elif self.index_type == 'GPTVectorStoreIndex':
490
  index.save_to_disk(index_filepath)
491
 
492
  elif self.index_type == 'pickle':
 
514
  embedding_function=self.embeddings
515
  )
516
 
517
+ elif self.index_type == 'GPTVectorStoreIndex':
518
+ self.index = GPTVectorStoreIndex.load_from_disk(self.index_filepath)
519
 
520
  elif self.index_type == 'pickle':
521
  with open(self.index_filepath, "rb") as f:
 
543
  url_documents
544
  ):
545
  # Build the Vector store for docs
546
+ doc_index = GPTVectorStoreIndex.from_documents(doc_documents)
547
  # Build the Vector store for URLs
548
+ url_index = GPTVectorStoreIndex.from_documents(url_documents)
549
 
550
  # Set summary of each index
551
  doc_index.set_text("index_from_docs")
 
592
  continue
593
  raise NotImplementedError
594
 
595
+ elif self.index_type == 'GPTVectorStoreIndex':
596
  for doc_type, index in doc_type_indices.items():
597
+ if not index or not isinstance(index, GPTVectorStoreIndex):
598
+ logger.warning(f'{doc_type} index to be merged is not an instance of type llama_index.GPTVectorStoreIndex')
599
  continue
600
  import pdb; pdb.set_trace()
601
  raise NotImplementedError
 
676
  k=similarity_top_k
677
  )
678
 
679
+ elif self.index_type == 'GPTVectorStoreIndex':
680
  # Querying the index
681
  response = index.query(
682
  question,