SVashishta1
commited on
Commit
·
2feba09
1
Parent(s):
19966eb
Error Fix
Browse files- backend/main.py +12 -6
- backend/vector_db.py +12 -0
backend/main.py
CHANGED
|
@@ -63,13 +63,19 @@ class DocumentAssistant:
|
|
| 63 |
|
| 64 |
def reset_database(self):
|
| 65 |
"""Reset the ChromaDB database"""
|
| 66 |
-
# This is a placeholder - you'll need to implement this in your DocumentAssistant class
|
| 67 |
-
# Typically, this would involve deleting all collections or recreating the database
|
| 68 |
try:
|
| 69 |
-
#
|
| 70 |
-
self.vector_db
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
except Exception as e:
|
| 74 |
print(f"Error resetting database: {str(e)}")
|
| 75 |
return False
|
|
|
|
| 63 |
|
| 64 |
def reset_database(self):
|
| 65 |
"""Reset the ChromaDB database"""
|
|
|
|
|
|
|
| 66 |
try:
|
| 67 |
+
# Reset the vector database
|
| 68 |
+
if hasattr(self, 'vector_db') and self.vector_db is not None:
|
| 69 |
+
success = self.vector_db.reset_collection()
|
| 70 |
+
|
| 71 |
+
# Also clear the SimpleDB
|
| 72 |
+
if hasattr(self, 'db') and self.db is not None:
|
| 73 |
+
self.db.clear_all()
|
| 74 |
+
|
| 75 |
+
return success
|
| 76 |
+
else:
|
| 77 |
+
print("Vector database not initialized")
|
| 78 |
+
return False
|
| 79 |
except Exception as e:
|
| 80 |
print(f"Error resetting database: {str(e)}")
|
| 81 |
return False
|
backend/vector_db.py
CHANGED
|
@@ -55,6 +55,18 @@ class ChromaVectorDB:
|
|
| 55 |
|
| 56 |
if results and results['ids']:
|
| 57 |
self.collection.delete(ids=results['ids'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# Create sample data
|
| 60 |
data = pd.DataFrame({
|
|
|
|
| 55 |
|
| 56 |
if results and results['ids']:
|
| 57 |
self.collection.delete(ids=results['ids'])
|
| 58 |
+
|
| 59 |
+
def reset_collection(self):
|
| 60 |
+
"""Reset the collection by deleting and recreating it"""
|
| 61 |
+
try:
|
| 62 |
+
# Delete the collection
|
| 63 |
+
self.client.delete_collection("documents")
|
| 64 |
+
# Recreate the collection
|
| 65 |
+
self.collection = self.client.get_or_create_collection("documents")
|
| 66 |
+
return True
|
| 67 |
+
except Exception as e:
|
| 68 |
+
print(f"Error resetting collection: {str(e)}")
|
| 69 |
+
return False
|
| 70 |
|
| 71 |
# Create sample data
|
| 72 |
data = pd.DataFrame({
|