Spaces:
Runtime error
Runtime error
Chintan Donda
commited on
Commit
·
41f059d
1
Parent(s):
3036eab
Fixing bug in LangChain utils
Browse files- src/langchain_utils.py +11 -10
src/langchain_utils.py
CHANGED
@@ -52,6 +52,9 @@ class LANGCHAIN_UTILS:
|
|
52 |
(ic, dict(
|
53 |
(ds, None) for ds in list(constants_utils.DATA_SOURCES.values()))
|
54 |
) for ic in constants_utils.INDEX_CATEGORY)
|
|
|
|
|
|
|
55 |
|
56 |
# Data loaded as a Document format in the current context for the doc_type in consideration
|
57 |
self.documents = []
|
@@ -227,11 +230,9 @@ class LANGCHAIN_UTILS:
|
|
227 |
elif doc_type == 'textfile':
|
228 |
# Load data from text files & Convert texts into Document format
|
229 |
self.documents.extend(
|
230 |
-
self.
|
231 |
-
|
232 |
-
|
233 |
-
doc_type=doc_type
|
234 |
-
)
|
235 |
))
|
236 |
|
237 |
elif doc_type == 'directory':
|
@@ -248,12 +249,12 @@ class LANGCHAIN_UTILS:
|
|
248 |
def create_index(
|
249 |
self
|
250 |
):
|
251 |
-
logger.info(f'Creating index')
|
252 |
-
|
253 |
if not self.documents:
|
254 |
logger.warning(f'Empty documents. Index cannot be created!')
|
255 |
return None
|
256 |
|
|
|
|
|
257 |
############## Build the Vector store for docs ##############
|
258 |
# Vector store using Facebook AI Similarity Search
|
259 |
if self.index_type == 'FAISS':
|
@@ -368,7 +369,7 @@ class LANGCHAIN_UTILS:
|
|
368 |
if index:
|
369 |
self.index_category_doc_type_wise_index[index_category][doc_type] = index
|
370 |
|
371 |
-
|
372 |
|
373 |
logger.info(f'New Vector/Index store for: {index_category} created successfully!')
|
374 |
|
@@ -427,12 +428,12 @@ class LANGCHAIN_UTILS:
|
|
427 |
index,
|
428 |
index_filepath
|
429 |
):
|
430 |
-
logger.info(f'Saving index to: {index_filepath}')
|
431 |
-
|
432 |
if not index:
|
433 |
logger.warning(f'Cannot write an empty index to: {index_filepath}!')
|
434 |
return
|
435 |
|
|
|
|
|
436 |
if not os.path.exists(index_filepath):
|
437 |
os.makedirs(index_filepath)
|
438 |
|
|
|
52 |
(ic, dict(
|
53 |
(ds, None) for ds in list(constants_utils.DATA_SOURCES.values()))
|
54 |
) for ic in constants_utils.INDEX_CATEGORY)
|
55 |
+
# Initialize master index for each INDEX_CATEGORY
|
56 |
+
for ic in constants_utils.INDEX_CATEGORY:
|
57 |
+
self.index_category_doc_type_wise_index[ic][constants_utils.INDEX_CATEGORY_MASTER_INDEX_DOC_TYPE] = None
|
58 |
|
59 |
# Data loaded as a Document format in the current context for the doc_type in consideration
|
60 |
self.documents = []
|
|
|
230 |
elif doc_type == 'textfile':
|
231 |
# Load data from text files & Convert texts into Document format
|
232 |
self.documents.extend(
|
233 |
+
self.data_loader_utils_obj.load_documents_from_text(
|
234 |
+
doc_filepath=doc_filepath,
|
235 |
+
doc_type=doc_type
|
|
|
|
|
236 |
))
|
237 |
|
238 |
elif doc_type == 'directory':
|
|
|
249 |
def create_index(
|
250 |
self
|
251 |
):
|
|
|
|
|
252 |
if not self.documents:
|
253 |
logger.warning(f'Empty documents. Index cannot be created!')
|
254 |
return None
|
255 |
|
256 |
+
logger.info(f'Creating index')
|
257 |
+
|
258 |
############## Build the Vector store for docs ##############
|
259 |
# Vector store using Facebook AI Similarity Search
|
260 |
if self.index_type == 'FAISS':
|
|
|
369 |
if index:
|
370 |
self.index_category_doc_type_wise_index[index_category][doc_type] = index
|
371 |
|
372 |
+
logger.info(f'New Vector/Index store for: {index_category} from data source: {doc_type} created successfully!')
|
373 |
|
374 |
logger.info(f'New Vector/Index store for: {index_category} created successfully!')
|
375 |
|
|
|
428 |
index,
|
429 |
index_filepath
|
430 |
):
|
|
|
|
|
431 |
if not index:
|
432 |
logger.warning(f'Cannot write an empty index to: {index_filepath}!')
|
433 |
return
|
434 |
|
435 |
+
logger.info(f'Saving index to: {index_filepath}')
|
436 |
+
|
437 |
if not os.path.exists(index_filepath):
|
438 |
os.makedirs(index_filepath)
|
439 |
|