MCPcopy
hub / github.com/PromtEngineer/localGPT / handle_index_documents

Method handle_index_documents

backend/server.py:698–731  ·  view source on GitHub ↗

Triggers indexing for all documents in a session.

(self, session_id: str)

Source from the content-addressed store, hash-verified

696 })
697
698 def handle_index_documents(self, session_id: str):
699 """Triggers indexing for all documents in a session."""
700 print(f"🔥 Received request to index documents for session {session_id[:8]}...")
701 try:
702 file_paths = db.get_documents_for_session(session_id)
703 if not file_paths:
704 self.send_json_response({"message": "No documents to index for this session."}, status_code=200)
705 return
706
707 print(f"Found {len(file_paths)} documents to index. Sending to RAG API...")
708
709 rag_api_url = "http://localhost:8001/index"
710 rag_response = requests.post(rag_api_url, json={"file_paths": file_paths, "session_id": session_id})
711
712 if rag_response.status_code == 200:
713 print("✅ RAG API successfully indexed documents.")
714 # Merge key config values into index metadata
715 idx_meta = {
716 "session_linked": True,
717 "retrieval_mode": "hybrid",
718 }
719 try:
720 db.update_index_metadata(session_id, idx_meta) # session_id used as index_id in text table naming
721 except Exception as e:
722 print(f"⚠️ Failed to update index metadata for session index: {e}")
723 self.send_json_response(rag_response.json())
724 else:
725 error_info = rag_response.text
726 print(f"❌ RAG API indexing failed ({rag_response.status_code}): {error_info}")
727 self.send_json_response({"error": f"Indexing failed: {error_info}"}, status_code=500)
728
729 except Exception as e:
730 print(f"❌ Exception during indexing: {str(e)}")
731 self.send_json_response({"error": f"An unexpected error occurred: {str(e)}"}, status_code=500)
732
733 def handle_pdf_upload(self, session_id: str):
734 """

Callers 1

do_POSTMethod · 0.95

Calls 3

send_json_responseMethod · 0.95
update_index_metadataMethod · 0.80

Tested by

no test coverage detected