index = VectorStoreIndex.from_documents(documents, service_context=service_context, storage_context=storage_context) ## OR define service context globally and no need to pass it to anywhere from llama_index import set_global_service_context set_global_service_context(service_context) index = VectorStoreIndex.from_documents(documents,storage_context=storage_context)
index = VectorStoreIndex.from_documents(documents, service_context=service_context, storage_context=storage_context)
from llama_index import set_global_service_context mongodb_client = pymongo.MongoClient(_mongoURI) db_name = f"{dossier}" store = MongoDBAtlasVectorSearch(mongodb_client, db_name=db_name) storage_context = StorageContext.from_defaults(vector_store=store) # You need to create the service context above this line set_global_service_context(service_context) documents = SimpleDirectoryReader("./Sources").load_data() index = VectorStoreIndex.from_documents(documents,storage_context=storage_context)
from flask import Flask, jsonify import threading app = Flask(__name__) def process_data(data): # Perofrm the indexing here!!! # Process data here (simulated by printing) print(f"Processing data: {data}") # Simulate a long-running task # Replace this with your actual data processing logic import time time.sleep(5) return f"Processed data: {data}" @app.route('/process', methods=['POST']) def process(): # Recieve your files and send it to the method data = request.json # Assuming data is sent in JSON format # Start a new thread to process the data thread = threading.Thread(target=process_data, args=(data,)) thread.start() # Return an immediate response to the client return jsonify({"message": "Indexing data on a separate thread."}) if __name__ == '__main__': app.run(debug=True)
embed_model = AzureOpenAIEmbedding( model=model.LearningModel.Model, deployment_name=model.LearningModel.Name, api_key=openai.api_key, azure_endpoint=openai.base_url, api_version=openai.api_version, embed_batch_size=50 # This is by default 10 )