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

Method handle_build_index

backend/server.py:863–986  ·  view source on GitHub ↗
(self, index_id: str)

Source from the content-addressed store, hash-verified

861 self.send_json_response({'message':f"Uploaded {len(uploaded_files)} files","uploaded_files":uploaded_files})
862
863 def handle_build_index(self, index_id: str):
864 try:
865 index=db.get_index(index_id)
866 if not index:
867 self.send_json_response({'error':'Index not found'}, status_code=404); return
868 file_paths=[d['stored_path'] for d in index.get('documents',[])]
869 if not file_paths:
870 self.send_json_response({'error':'No documents to index'}, status_code=400); return
871
872 # Parse request body for optional flags and configuration
873 latechunk = False
874 docling_chunk = False
875 chunk_size = 512
876 chunk_overlap = 64
877 retrieval_mode = 'hybrid'
878 window_size = 2
879 enable_enrich = True
880 embedding_model = None
881 enrich_model = None
882 batch_size_embed = 50
883 batch_size_enrich = 25
884 overview_model = None
885
886 if 'Content-Length' in self.headers and int(self.headers['Content-Length']) > 0:
887 try:
888 length = int(self.headers['Content-Length'])
889 body = self.rfile.read(length)
890 opts = json.loads(body.decode('utf-8'))
891 latechunk = bool(opts.get('latechunk', False))
892 docling_chunk = bool(opts.get('doclingChunk', False))
893 chunk_size = int(opts.get('chunkSize', 512))
894 chunk_overlap = int(opts.get('chunkOverlap', 64))
895 retrieval_mode = str(opts.get('retrievalMode', 'hybrid'))
896 window_size = int(opts.get('windowSize', 2))
897 enable_enrich = bool(opts.get('enableEnrich', True))
898 embedding_model = opts.get('embeddingModel')
899 enrich_model = opts.get('enrichModel')
900 batch_size_embed = int(opts.get('batchSizeEmbed', 50))
901 batch_size_enrich = int(opts.get('batchSizeEnrich', 25))
902 overview_model = opts.get('overviewModel')
903 except Exception:
904 # Keep defaults on parse error
905 pass
906
907 # Set per-index overview file path
908 overview_path = f"index_store/overviews/{index_id}.jsonl"
909
910 # Ensure config_override includes overview_path
911 def ensure_overview_path(cfg: dict):
912 cfg["overview_path"] = overview_path
913
914 # we'll inject later when we build config_override
915
916 # Delegate to advanced RAG API same as session indexing
917 rag_api_url = "http://localhost:8001/index"
918 import requests, json as _json
919 # Use the index's dedicated LanceDB table so retrieval matches
920 table_name = index.get("vector_table_name")

Callers 1

do_POSTMethod · 0.95

Calls 3

send_json_responseMethod · 0.95
get_indexMethod · 0.80
update_index_metadataMethod · 0.80

Tested by

no test coverage detected