Spaces:
Running
Running
“vinit5112”
commited on
Commit
·
1edfa40
1
Parent(s):
65726e0
post changes
Browse files- backend/vector_store.py +21 -4
backend/vector_store.py
CHANGED
@@ -76,7 +76,7 @@ class VectorStore:
|
|
76 |
Create the collection with proper configuration.
|
77 |
|
78 |
Returns:
|
79 |
-
bool: True if collection was created successfully
|
80 |
"""
|
81 |
try:
|
82 |
print(f"Creating new collection: {self.collection_name}")
|
@@ -120,6 +120,11 @@ class VectorStore:
|
|
120 |
return True
|
121 |
|
122 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
123 |
error_msg = f"Failed to create collection {self.collection_name}: {str(e)}"
|
124 |
logger.error(error_msg, exc_info=True)
|
125 |
print(error_msg)
|
@@ -135,11 +140,23 @@ class VectorStore:
|
|
135 |
try:
|
136 |
# First, check if collection exists and is accessible
|
137 |
if await self._collection_exists_and_accessible():
|
|
|
138 |
return True
|
139 |
|
140 |
-
# If not accessible, try to create it
|
141 |
-
print(f"Collection '{self.collection_name}' not
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
except Exception as e:
|
145 |
error_msg = f"Failed to ensure collection exists: {str(e)}"
|
|
|
76 |
Create the collection with proper configuration.
|
77 |
|
78 |
Returns:
|
79 |
+
bool: True if collection was created successfully or already exists
|
80 |
"""
|
81 |
try:
|
82 |
print(f"Creating new collection: {self.collection_name}")
|
|
|
120 |
return True
|
121 |
|
122 |
except Exception as e:
|
123 |
+
# Check if the error is because collection already exists
|
124 |
+
if "already exists" in str(e).lower() or "ALREADY_EXISTS" in str(e):
|
125 |
+
print(f"Collection '{self.collection_name}' already exists, using existing collection")
|
126 |
+
return True
|
127 |
+
|
128 |
error_msg = f"Failed to create collection {self.collection_name}: {str(e)}"
|
129 |
logger.error(error_msg, exc_info=True)
|
130 |
print(error_msg)
|
|
|
140 |
try:
|
141 |
# First, check if collection exists and is accessible
|
142 |
if await self._collection_exists_and_accessible():
|
143 |
+
print(f"Collection '{self.collection_name}' is ready to use")
|
144 |
return True
|
145 |
|
146 |
+
# If not accessible, try to create it (or verify it exists)
|
147 |
+
print(f"Collection '{self.collection_name}' not immediately accessible, attempting to create/verify...")
|
148 |
+
created = await self._create_collection()
|
149 |
+
|
150 |
+
# After creation attempt, verify it's accessible
|
151 |
+
if created and await self._collection_exists_and_accessible():
|
152 |
+
print(f"Collection '{self.collection_name}' is now ready to use")
|
153 |
+
return True
|
154 |
+
elif created:
|
155 |
+
# Created successfully but not immediately accessible, which is okay
|
156 |
+
print(f"Collection '{self.collection_name}' created/verified successfully")
|
157 |
+
return True
|
158 |
+
else:
|
159 |
+
return False
|
160 |
|
161 |
except Exception as e:
|
162 |
error_msg = f"Failed to ensure collection exists: {str(e)}"
|