MCPcopy Index your code
hub / github.com/PromtEngineer/localGPT / create_single_index

Method create_single_index

demo_batch_indexing.py:139–195  ·  view source on GitHub ↗

Create a single index from configuration.

(self, index_config: Dict[str, Any])

Source from the content-addressed store, hash-verified

137 return created_indexes
138
139 def create_single_index(self, index_config: Dict[str, Any]) -> Optional[str]:
140 """Create a single index from configuration."""
141 try:
142 # Extract index metadata
143 index_name = index_config.get("name", "Unnamed Index")
144 index_description = index_config.get("description", "")
145 documents = index_config.get("documents", [])
146
147 if not documents:
148 print(f"⚠️ No documents specified for index '{index_name}', skipping...")
149 return None
150
151 # Validate documents
152 valid_documents = self.validate_documents(documents)
153 if not valid_documents:
154 print(f"❌ No valid documents found for index '{index_name}'")
155 return None
156
157 print(f"\n🚀 Creating index: {index_name}")
158 print(f"📄 Processing {len(valid_documents)} documents")
159
160 # Create index record in database
161 index_metadata = {
162 "created_by": "demo_batch_indexing.py",
163 "created_at": datetime.now().isoformat(),
164 "document_count": len(valid_documents),
165 "config_used": index_config.get("processing_options", {})
166 }
167
168 index_id = self.db.create_index(
169 name=index_name,
170 description=index_description,
171 metadata=index_metadata
172 )
173
174 # Add documents to index
175 for doc_path in valid_documents:
176 filename = os.path.basename(doc_path)
177 self.db.add_document_to_index(index_id, filename, doc_path)
178
179 # Process documents through pipeline
180 start_time = time.time()
181 self.pipeline.process_documents(valid_documents)
182 processing_time = time.time() - start_time
183
184 print(f"✅ Index '{index_name}' created successfully!")
185 print(f" Index ID: {index_id}")
186 print(f" Processing time: {processing_time:.2f} seconds")
187 print(f" Documents processed: {len(valid_documents)}")
188
189 return index_id
190
191 except Exception as e:
192 print(f"❌ Error creating index '{index_name}': {e}")
193 import traceback
194 traceback.print_exc()
195 return None
196

Callers 1

create_indexesMethod · 0.95

Calls 3

validate_documentsMethod · 0.95
create_indexMethod · 0.80
add_document_to_indexMethod · 0.80

Tested by

no test coverage detected