From 11eb2946d957bcfce9f6c13d0eb4a3b4c2a5357d Mon Sep 17 00:00:00 2001 From: LLLin000 <809867916@qq.com> Date: Fri, 10 Jul 2026 23:36:55 +0800 Subject: [PATCH] fix: --force drops vec0 tables instead of ChromaDB directory Replace shutil.rmtree on the ChromaDB path with DROP TABLE IF EXISTS on vec0 virtual tables and their companion meta tables. Force rebuild now opens paperforge.db and drops vec_fulltext, vec_body, vec_objects, vec_fulltext_meta, vec_body_meta, and vec_objects_meta. Also replaced the remaining get_vector_db_path reference in the error handler with get_memory_db_path. Removed get_vector_db_path import from embed.py since it is no longer used in active control flow. --- paperforge/commands/embed.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/paperforge/commands/embed.py b/paperforge/commands/embed.py index c964c39a..fa37aaba 100644 --- a/paperforge/commands/embed.py +++ b/paperforge/commands/embed.py @@ -12,7 +12,6 @@ from paperforge.core.result import PFError, PFResult from paperforge.embedding import ( delete_paper_vectors, get_embed_status, - get_vector_db_path, mark_vector_build_state, read_vector_build_state, ) @@ -325,16 +324,22 @@ def run(args: argparse.Namespace) -> int: _force_rebuild = args.force or (resume is False and getattr(args, "resume", False)) if _force_rebuild: _gc.collect() - db_path = get_vector_db_path(vault) - if db_path.exists(): - import shutil - - shutil.rmtree(str(db_path), ignore_errors=True) - if db_path.exists(): - import time - - time.sleep(0.5) - shutil.rmtree(str(db_path), ignore_errors=True) + _db_path = get_memory_db_path(vault) + if _db_path.exists(): + _conn = get_connection(_db_path) + try: + from paperforge.memory.db import ensure_vec_extension + from paperforge.memory.schema import ensure_schema + ensure_vec_extension(_conn) + ensure_schema(_conn) + for _t in ("vec_fulltext", "vec_body", "vec_objects", + "vec_fulltext_meta", "vec_body_meta", "vec_objects_meta"): + _conn.execute(f'DROP TABLE IF EXISTS "{_t}"') + _conn.commit() + except Exception: + pass + finally: + _conn.close() mark_vector_build_state( vault, @@ -579,7 +584,7 @@ def run(args: argparse.Namespace) -> int: deps_installed=True, deps_missing=None, py_version=sys.version.split()[0], - db_exists=get_vector_db_path(vault).exists(), + db_exists=get_memory_db_path(vault).exists(), chunk_count=_actual, body_chunk_count=0, object_chunk_count=0,