documents = SimpleDirectoryReader(documents_dir, recursive='true', filename_as_id=True, num_files_limit=10).load_data()
document = SimpleDirectoryReader(input_files=[doc_text]).load_data()[0]
... manager.register('insert_into_index') ... @app.route("/uploadFile", methods=["POST"]) def upload_file(): global manager if 'file' not in request.files: return "Please send a POST request with a file", 400 filepath = None try: uploaded_file = request.files["file"] filename = secure_filename(uploaded_file.filename) filepath = os.path.join('documents', os.path.basename(filename)) uploaded_file.save(filepath) if request.form.get("filename_as_doc_id", None) is not None: manager.insert_into_index(filepath, doc_id=filename) else: manager.insert_into_index(filepath) except Exception as e: # cleanup temp file if filepath is not None and os.path.exists(filepath): os.remove(filepath) return "Error: {}".format(str(e)), 500 # cleanup temp file if filepath is not None and os.path.exists(filepath): os.remove(filepath) return "File inserted!", 200
def insert_into_index(doc_text, doc_id=None): global index document = SimpleDirectoryReader(input_files=[doc_text]).load_data()[0] if doc_id is not None: document.doc_id = doc_id with lock: index.insert(document) index.storage_context.persist()
.load_data()[0]
)def insert_into_index(doc_text, doc_id=None): global index documents = SimpleDirectoryReader(input_files=[doc_text], filename_as_id=True).load_data() with lock: for doc in documents index.insert(doc) index.storage_context.persist()