2323
2424
2525class ReActWithQueryEngine :
26-
2726 RESPONSE_TYPE = Union [
2827 Response , StreamingResponse , AsyncStreamingResponse , PydanticResponse
2928 ]
3029
31- def __init__ (self , input_dir : str , similarity_top_k : int = 3 , chunk_size : int = 128 , chunk_overlap : int = 100 , show_progress : bool = False , no_of_iterations : int = 5 ):
30+ def __init__ (self , input_dir : str , similarity_top_k : int = 3 , chunk_size : int = 128 , chunk_overlap : int = 100 ,
31+ show_progress : bool = False , no_of_iterations : int = 5 , required_exts : list [str ] = ['.pdf' , '.txt' ]):
3232 self .index_loaded = False
3333 self .similarity_top_k = similarity_top_k
3434 self .input_dir = input_dir
@@ -38,6 +38,7 @@ def __init__(self, input_dir: str, similarity_top_k: int = 3, chunk_size: int =
3838 self .query_engine_tools = []
3939 self .show_progress = show_progress
4040 self .no_of_iterations = no_of_iterations
41+ self .required_exts = required_exts
4142
4243 # use your prefered vector embeddings model
4344 logger .info ("initializing the OllamaEmbedding" )
@@ -58,7 +59,8 @@ def __init__(self, input_dir: str, similarity_top_k: int = 3, chunk_size: int =
5859
5960 # Create a local Qdrant vector store
6061 logger .info ("initializing the vector store related objects" )
61- self .client : qdrant_client .QdrantClient = qdrant_client .QdrantClient (url = os .environ ['DB_URL' ], api_key = os .environ ['DB_API_KEY' ])
62+ self .client : qdrant_client .QdrantClient = qdrant_client .QdrantClient (url = os .environ ['DB_URL' ],
63+ api_key = os .environ ['DB_API_KEY' ])
6264 self .vector_store = QdrantVectorStore (client = self .client , collection_name = os .environ ['COLLECTION_NAME' ])
6365 self ._load_data_and_create_engine ()
6466
@@ -72,13 +74,15 @@ def _load_data_and_create_engine(self):
7274
7375 if not self .index_loaded :
7476 # load data
75- _docs = SimpleDirectoryReader (input_dir = self .input_dir ).load_data (show_progress = self .show_progress )
77+ _docs = (SimpleDirectoryReader (input_dir = self .input_dir , required_exts = self .required_exts )
78+ .load_data (show_progress = self .show_progress ))
7679
7780 # build and persist index
7881 storage_context = StorageContext .from_defaults (vector_store = self .vector_store )
7982 logger .info ("indexing the docs in VectorStoreIndex" )
80- self ._index = VectorStoreIndex .from_documents (documents = _docs , storage_context = storage_context , show_progress = self .show_progress )
81-
83+ self ._index = VectorStoreIndex .from_documents (documents = _docs , storage_context = storage_context ,
84+ show_progress = self .show_progress )
85+
8286 self ._engine = self ._index .as_query_engine (similarity_top_k = self .similarity_top_k )
8387 self ._create_query_engine_tools ()
8488
0 commit comments