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

Method delete_index

backend/database.py:393–426  ·  view source on GitHub ↗

Delete an index and its related records (documents, session links). Returns True if deleted.

(self, index_id: str)

Source from the content-addressed store, hash-verified

391 return ids
392
393 def delete_index(self, index_id: str) -> bool:
394 """Delete an index and its related records (documents, session links). Returns True if deleted."""
395 conn = sqlite3.connect(self.db_path)
396 try:
397 # Get vector table name before deletion (optional, for LanceDB cleanup)
398 cur = conn.execute('SELECT vector_table_name FROM indexes WHERE id = ?', (index_id,))
399 row = cur.fetchone()
400 vector_table_name = row[0] if row else None
401
402 # Remove child rows first due to foreign‐key constraints
403 conn.execute('DELETE FROM index_documents WHERE index_id = ?', (index_id,))
404 conn.execute('DELETE FROM session_indexes WHERE index_id = ?', (index_id,))
405 cursor = conn.execute('DELETE FROM indexes WHERE id = ?', (index_id,))
406 deleted = cursor.rowcount > 0
407 conn.commit()
408 finally:
409 conn.close()
410
411 if deleted:
412 print(f"🗑️ Deleted index {index_id[:8]}... and related records")
413 # Optional: attempt to drop LanceDB table if available
414 if vector_table_name:
415 try:
416 from rag_system.indexing.embedders import LanceDBManager
417 import os
418 db_path = os.getenv('LANCEDB_PATH') or './rag_system/index_store/lancedb'
419 ldb = LanceDBManager(db_path)
420 db = ldb.db
421 if hasattr(db, 'table_names') and vector_table_name in db.table_names():
422 db.drop_table(vector_table_name)
423 print(f"🚮 Dropped LanceDB table '{vector_table_name}'")
424 except Exception as e:
425 print(f"⚠️ Could not drop LanceDB table '{vector_table_name}': {e}")
426 return deleted
427
428 def update_index_metadata(self, index_id: str, updates: dict):
429 """Merge new key/values into an index's metadata JSON column."""

Callers 1

handle_delete_indexMethod · 0.80

Calls 1

LanceDBManagerClass · 0.90

Tested by

no test coverage detected