maintenance.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Maintenance - Database cleanup operations for QMD.
  3. *
  4. * Wraps low-level store operations that the CLI needs for housekeeping.
  5. * Takes an internal Store in the constructor — allowed to access DB directly.
  6. */
  7. import type { Store } from "./store.js";
  8. import {
  9. vacuumDatabase,
  10. cleanupOrphanedContent,
  11. cleanupOrphanedVectors,
  12. deleteLLMCache,
  13. deleteInactiveDocuments,
  14. clearAllEmbeddings,
  15. } from "./store.js";
  16. export class Maintenance {
  17. private store: Store;
  18. constructor(store: Store) {
  19. this.store = store;
  20. }
  21. /** Run VACUUM on the SQLite database to reclaim space */
  22. vacuum(): void {
  23. vacuumDatabase(this.store.db);
  24. }
  25. /** Remove content rows that are no longer referenced by any document */
  26. cleanupOrphanedContent(): number {
  27. return cleanupOrphanedContent(this.store.db);
  28. }
  29. /** Remove vector embeddings for content that no longer exists */
  30. cleanupOrphanedVectors(): number {
  31. return cleanupOrphanedVectors(this.store.db);
  32. }
  33. /** Clear the LLM response cache (query expansion, reranking) */
  34. clearLLMCache(): number {
  35. return deleteLLMCache(this.store.db);
  36. }
  37. /** Delete documents marked as inactive (removed from filesystem) */
  38. deleteInactiveDocs(): number {
  39. return deleteInactiveDocuments(this.store.db);
  40. }
  41. /** Clear all vector embeddings (forces re-embedding) */
  42. clearEmbeddings(): void {
  43. clearAllEmbeddings(this.store.db);
  44. }
  45. }