Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset the vector db in favour of a new embedding model #98

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions context_chat_backend/repair/repair4000_date20241108175224.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import shutil

'''
Reset the vector db in favour of a new embedding model
'''

vector_db_path = os.path.join(
os.getenv('APP_PERSISTENT_STORAGE', 'persistent_storage'),
'vector_db_data',
)

if os.path.exists(vector_db_path):
shutil.rmtree(vector_db_path)
os.makedirs(vector_db_path, mode=0o770)
21 changes: 16 additions & 5 deletions context_chat_backend/repair/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def get_previous_version(version_info_path: str) -> tuple[int, bool]:
'''
'+' at the end of the patch version indicates that repairs have been run.
'''
if not os.path.exists(version_info_path):
version_string = os.environ['APP_VERSION']
else:
if os.path.exists(version_info_path):
with open(version_info_path) as f:
version_string = f.read()
else:
version_string = os.environ['APP_VERSION']

major, minor, patch = version_string.split('.')
current_repairs_run = patch.endswith('+') and version_string.rstrip('+') == os.environ['APP_VERSION']
Expand All @@ -26,6 +26,8 @@ def main():
Run repairs that have not been run before.
Repair files can either have no functions or a run() function.
'''
print('Running repairs...', flush=True)

persistent_storage_path = os.getenv('APP_PERSISTENT_STORAGE', 'persistent_storage')
version_info_path = os.path.join(persistent_storage_path, 'version.info')

Expand All @@ -36,26 +38,35 @@ def main():
(previous_app_version, current_repairs_run) = get_previous_version(version_info_path)

if current_repairs_run:
print('Repairs have already been run.', flush=True)
return

for repair_filename in repair_filenames:
pattern = re.compile(r'^repair(\d+)_date\d+\.py$')
matches = pattern.match(repair_filename)
if not matches:
return
print(f'Ignoring invalid repair file: {repair_filename}', flush=True)
continue

introduced_version = int(matches.group(1))

if introduced_version < previous_app_version:
print(f'No repairs to run for version {introduced_version}.', flush=True)
break

print(f'Running repair {repair_filename}...', flush=True, end='')

mod = import_module(f'.repair.{repair_filename[:-3]}', 'context_chat_backend')
if hasattr(mod, 'run'):
mod.run()
mod.run(previous_app_version)

print('completed.', flush=True)

with open(version_info_path, 'w') as f:
f.write(os.environ['APP_VERSION'] + '+')

print('Repairs completed.', flush=True)


if __name__ == '__main__':
main()
Loading