Thomas Richardson commited on
Commit ·
63da829
1
Parent(s): 8324b6b
feature: delete all pinecone data api
Browse files
Brain/src/router/train_router.py
CHANGED
|
@@ -157,4 +157,31 @@ def construct_blueprint_train_api() -> APIRouter:
|
|
| 157 |
200, "deleted one document and train data successfully", result
|
| 158 |
)
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
return router
|
|
|
|
| 157 |
200, "deleted one document and train data successfully", result
|
| 158 |
)
|
| 159 |
|
| 160 |
+
"""@generator.request_body(
|
| 161 |
+
{
|
| 162 |
+
"token": "test_token",
|
| 163 |
+
"uuid": "test_uuid",
|
| 164 |
+
}
|
| 165 |
+
)
|
| 166 |
+
@generator.response( status_code=200, schema={"message": "message", "result": {"document_id": "document_id"}} )"""
|
| 167 |
+
|
| 168 |
+
@router.post("/delete/all/vectors")
|
| 169 |
+
def delete_all_pinecone(data: BasicReq):
|
| 170 |
+
# parsing params
|
| 171 |
+
try:
|
| 172 |
+
setting, firebase_app = firebase_admin_with_setting(data)
|
| 173 |
+
except BrainException as ex:
|
| 174 |
+
return ex.get_response_exp()
|
| 175 |
+
# Services
|
| 176 |
+
train_service = TrainService(firebase_app=firebase_app, setting=setting)
|
| 177 |
+
try:
|
| 178 |
+
result = train_service.delete_all_training_from_pinecone()
|
| 179 |
+
except Exception as e:
|
| 180 |
+
if isinstance(e, BrainException):
|
| 181 |
+
return e.get_response_exp()
|
| 182 |
+
return assembler.to_response(400, "fail to delete one train", "")
|
| 183 |
+
return assembler.to_response(
|
| 184 |
+
200, "deleted one document and train data successfully", result
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
return router
|
Brain/src/service/train_service.py
CHANGED
|
@@ -148,6 +148,12 @@ class TrainService:
|
|
| 148 |
setting=self.setting,
|
| 149 |
)
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
def get_pinecone_index_namespace(self) -> str:
|
| 152 |
self.init_firestore()
|
| 153 |
return get_pinecone_index_namespace(f"trains")
|
|
|
|
| 148 |
setting=self.setting,
|
| 149 |
)
|
| 150 |
|
| 151 |
+
def delete_all_training_from_pinecone(self) -> Any:
|
| 152 |
+
self.init_firestore()
|
| 153 |
+
return delete_all_pinecone(
|
| 154 |
+
namespace=self.get_pinecone_index_namespace(), setting=self.setting
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
def get_pinecone_index_namespace(self) -> str:
|
| 158 |
self.init_firestore()
|
| 159 |
return get_pinecone_index_namespace(f"trains")
|