From 882e2370c104a99a4339d03d3096946fb985c64e Mon Sep 17 00:00:00 2001 From: KoalaTrapLord <265133236+KoalaTrapLord@users.noreply.github.com> Date: Sun, 29 Mar 2026 04:29:35 -0400 Subject: [PATCH] fix(#127): persist built_at in ChromaDB collection metadata as sidecar fallback - _write_build_meta: after writing build_meta.json, also stamps built_at onto the collection via col.modify() (best-effort, swallows exceptions) - _collection_is_current: if sidecar built_at is missing/zero, falls back to collection.metadata["built_at"] so a deleted sidecar doesn't force an unnecessary full rebuild when the ChromaDB data is still valid --- services/rag_store.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/services/rag_store.py b/services/rag_store.py index bab888a..015b874 100644 --- a/services/rag_store.py +++ b/services/rag_store.py @@ -198,6 +198,12 @@ def _write_build_meta(card_count: int, forge_coverage: int = 0) -> None: ) except Exception as exc: logger.warning("Could not write build_meta.json: %s", exc) + # Fix #127: also persist built_at in ChromaDB collection metadata + try: + col = _get_collection() + col.modify(metadata={"hnsw:space": "cosine", "built_at": time.time()}) + except Exception: + pass # best-effort — sidecar is primary def _collection_is_current(collection, bulk_card_count: int) -> bool: @@ -207,6 +213,13 @@ def _collection_is_current(collection, bulk_card_count: int) -> bool: return False meta = _read_build_meta() built_at = meta.get("built_at", 0) + # Fix #127: fallback to collection metadata if sidecar is missing + if not built_at: + try: + col_meta = collection.metadata or {} + built_at = col_meta.get("built_at", 0) + except Exception: + pass if built_at: age_days = (time.time() - float(built_at)) / 86400 if age_days > 14: