Spaces:
Runtime error
Runtime error
Chintan-Donda
commited on
Commit
•
89ee6d6
1
Parent(s):
f181070
Update src/langchain_utils.py
Browse files- 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
|
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 == '
|
333 |
-
self.index =
|
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 == '
|
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 == '
|
518 |
-
self.index =
|
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 =
|
547 |
# Build the Vector store for URLs
|
548 |
-
url_index =
|
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 == '
|
596 |
for doc_type, index in doc_type_indices.items():
|
597 |
-
if not index or not isinstance(index,
|
598 |
-
logger.warning(f'{doc_type} index to be merged is not an instance of type llama_index.
|
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 == '
|
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,
|