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

Method batch_create_from_config

create_index_script.py:260–311  ·  view source on GitHub ↗

Create index from batch configuration file.

(self, config_file: str)

Source from the content-addressed store, hash-verified

258 print(f"❌ Error testing index: {e}")
259
260 def batch_create_from_config(self, config_file: str) -> None:
261 """Create index from batch configuration file."""
262 try:
263 with open(config_file, 'r') as f:
264 batch_config = json.load(f)
265
266 index_name = batch_config.get("index_name", "Batch Index")
267 index_description = batch_config.get("index_description", "")
268 documents = batch_config.get("documents", [])
269 processing_config = batch_config.get("processing", {})
270
271 if not documents:
272 print("❌ No documents specified in batch configuration")
273 return
274
275 # Validate documents exist
276 valid_documents = []
277 for doc_path in documents:
278 if os.path.exists(doc_path):
279 valid_documents.append(doc_path)
280 else:
281 print(f"⚠️ Document not found: {doc_path}")
282
283 if not valid_documents:
284 print("❌ No valid documents found")
285 return
286
287 print(f"🚀 Creating batch index: {index_name}")
288 print(f"📄 Processing {len(valid_documents)} documents...")
289
290 # Create index
291 index_id = self.db.create_index(
292 name=index_name,
293 description=index_description,
294 metadata=processing_config
295 )
296
297 # Add documents
298 for doc_path in valid_documents:
299 filename = os.path.basename(doc_path)
300 self.db.add_document_to_index(index_id, filename, doc_path)
301
302 # Process documents
303 self.pipeline.process_documents(valid_documents)
304
305 print(f"✅ Batch index '{index_name}' created successfully!")
306 print(f"Index ID: {index_id}")
307
308 except Exception as e:
309 print(f"❌ Error creating batch index: {e}")
310 import traceback
311 traceback.print_exc()
312
313
314def create_sample_batch_config():

Callers 1

mainFunction · 0.95

Calls 2

create_indexMethod · 0.80
add_document_to_indexMethod · 0.80

Tested by

no test coverage detected