2424from pathlib import Path
2525
2626from ingestion .config import IngestionConfig
27+ from ingestion import git_changes
2728
2829
2930# Directories under the workspace root that are not part of the indexed
@@ -106,12 +107,14 @@ def main(argv=None):
106107
107108 repo_dirs = _ensure_repos (root , config , argv )
108109 last_ingestion = vectordb .get_last_ingestion ()
109- candidate_files = _candidate_files (repo_dirs , last_ingestion )
110+ candidate_files , stale_files = git_changes .candidate_file_changes (
111+ repo_dirs , last_ingestion )
110112
111113 print (f"indexing { len (repo_dirs )} repo(s): "
112114 f"{ ', ' .join (d .name for d in repo_dirs )} " )
113115 if last_ingestion :
114116 print (f"last successful ingestion: { last_ingestion } " )
117+ _delete_stale_files (stale_files , vectordb )
115118 count = run (repo_dirs , candidate_files = candidate_files )
116119 vectordb .set_last_ingestion (_utc_now_iso8601 ())
117120 print (f"indexed { count } chunks into '{ config .qdrant_collection } '" )
@@ -129,9 +132,6 @@ def main(argv=None):
129132def _ensure_repos (root , config , names = None ):
130133 root .mkdir (parents = True , exist_ok = True )
131134 _ensure_development (root , config .development_repo_url )
132- repo_dirs = _discover_repos (root , names )
133- if repo_dirs :
134- return repo_dirs
135135 _run_k_clone (root , config .kli_organization , config .kli_workspace )
136136 repo_dirs = _discover_repos (root , names )
137137 if not repo_dirs :
@@ -190,23 +190,19 @@ def _candidate_files(repo_dirs, last_ingestion):
190190 return candidates
191191
192192
193+ # Delete vector-store chunks for files that disappeared from git history
194+ # (deleted files, or the old side of renames).
195+ def _delete_stale_files (stale_files , vectordb ):
196+ for repository , source_paths in stale_files .items ():
197+ for source_path in source_paths :
198+ vectordb .delete_file (repository , source_path )
199+
200+
193201# Repo-relative file paths touched since `since` (ISO 8601), newest activity
194202# first in git history but returned here as a deduplicated set.
195203def _git_changed_files_since (repo_dir , since ):
196- try :
197- result = subprocess .run (
198- ["git" , "-C" , str (repo_dir ), "log" , f"--since={ since } " ,
199- "--name-only" , "--pretty=format:" ],
200- capture_output = True , text = True , check = False , timeout = 15 )
201- except (FileNotFoundError , subprocess .TimeoutExpired ):
202- return set ()
203- if result .returncode != 0 :
204- return set ()
205- return {
206- line .strip ().replace ("\\ " , "/" )
207- for line in result .stdout .splitlines ()
208- if line .strip ()
209- }
204+ candidates , _ = git_changes .candidate_file_changes ([repo_dir ], since )
205+ return candidates .get (Path (repo_dir ).name , set ())
210206
211207
212208# Current UTC timestamp in compact ISO 8601 form used by the metadata
0 commit comments