Drop a long-doc entry from PageIndex's local SQLite + remove its managed files. Returns ``(did_cleanup, message)``. No-op (returns ``(False, "no PageIndex state")``) when no ``pageindex.db`` exists — short-doc-only KBs never created any. Falls back to matching by ``doc_name`` via `
(
openkb_dir: Path,
kb_dir: Path,
doc_name: str,
doc_id: str | None,
)
| 1146 | |
| 1147 | |
| 1148 | def _cleanup_pageindex( |
| 1149 | openkb_dir: Path, |
| 1150 | kb_dir: Path, |
| 1151 | doc_name: str, |
| 1152 | doc_id: str | None, |
| 1153 | ) -> tuple[bool, str]: |
| 1154 | """Drop a long-doc entry from PageIndex's local SQLite + remove its |
| 1155 | managed files. Returns ``(did_cleanup, message)``. |
| 1156 | |
| 1157 | No-op (returns ``(False, "no PageIndex state")``) when no |
| 1158 | ``pageindex.db`` exists — short-doc-only KBs never created any. |
| 1159 | |
| 1160 | Falls back to matching by ``doc_name`` via ``list_documents()`` when |
| 1161 | the registry entry pre-dates PR #51's ``doc_id`` field. Ambiguous |
| 1162 | multi-match cases are skipped with a warning rather than guessed. |
| 1163 | """ |
| 1164 | if not (openkb_dir / "pageindex.db").exists(): |
| 1165 | return False, "no PageIndex state" |
| 1166 | |
| 1167 | from pageindex import PageIndexClient |
| 1168 | |
| 1169 | _setup_llm_key(kb_dir) |
| 1170 | config = load_config(openkb_dir / "config.yaml") |
| 1171 | model = config.get("model", DEFAULT_CONFIG.get("model", "gpt-5.4")) |
| 1172 | client = PageIndexClient(model=model, storage_path=str(openkb_dir)) |
| 1173 | col = client.collection() |
| 1174 | |
| 1175 | if doc_id is None: |
| 1176 | candidates = [d for d in col.list_documents() if d.get("doc_name") == doc_name] |
| 1177 | if not candidates: |
| 1178 | return False, "no PageIndex doc to delete" |
| 1179 | if len(candidates) > 1: |
| 1180 | return False, ( |
| 1181 | f"{len(candidates)} PageIndex docs match doc_name='{doc_name}'; " |
| 1182 | "skipping (re-add to refresh)" |
| 1183 | ) |
| 1184 | doc_id = candidates[0]["doc_id"] |
| 1185 | |
| 1186 | col.delete_document(doc_id) |
| 1187 | return True, f"deleted PageIndex doc ({doc_id[:12]}…)" |
| 1188 | |
| 1189 | |
| 1190 | def _resolve_doc_identifier(registry, identifier: str) -> list[tuple[str, dict]]: |
no test coverage detected