Skip to content

Commit

Permalink
HOTFIX /delete. Separate Nomic from Supabase for better reliability i…
Browse files Browse the repository at this point in the history
…f either fails
  • Loading branch information
KastanDay committed Mar 12, 2024
1 parent 6134605 commit 25655b4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ai_ta_backend/service/retrieval_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,23 +315,25 @@ def format_for_json_mqr(self, found_docs) -> List[Dict]:

def delete_from_nomic_and_supabase(self, course_name: str, identifier_key: str, identifier_value: str):
try:
print(f"Deleting from Nomic and Supabase for {course_name} using {identifier_key}: {identifier_value}")
print(f"Nomic delete. Course: {course_name} using {identifier_key}: {identifier_value}")
response = self.sqlDb.getMaterialsForCourseAndKeyAndValue(course_name, identifier_key, identifier_value)
if not response.data:
raise Exception(f"No materials found for {course_name} using {identifier_key}: {identifier_value}")
data = response.data[0] # single record fetched
nomic_ids_to_delete = [str(data['id']) + "_" + str(i) for i in range(1, len(data['contexts']) + 1)]

# delete from Nomic
# check if project exists
response = self.sqlDb.getProjectsMapForCourse(course_name)
if not response.data:
raise Exception(f"No document map found for this course: {course_name}")
project_id = response.data[0]['doc_map_id']
self.nomicService.delete_from_document_map(project_id, nomic_ids_to_delete)
except Exception as e:
print(f"Error in deleting file from Nomic or Supabase using {identifier_key}: {identifier_value}", e)
self.sentry.capture_exception(e)

# delete from Supabase
print(f"Deleting from Supabase for {course_name} using {identifier_key}: {identifier_value}")
try:
print(f"Supabase Delete. course: {course_name} using {identifier_key}: {identifier_value}")
response = self.sqlDb.deleteMaterialsForCourseAndKeyAndValue(course_name, identifier_key, identifier_value)
except Exception as e:
print(f"Error in deleting file from Nomic or Supabase using {identifier_key}: {identifier_value}", e)
Expand Down

0 comments on commit 25655b4

Please sign in to comment.