vivekchakraverty commited on
Commit
a9e0a97
·
verified ·
1 Parent(s): 5041908

Load RAG index eagerly at container startup instead of on first request

Browse files
Files changed (1) hide show
  1. modules/rag.py +8 -2
modules/rag.py CHANGED
@@ -1,6 +1,7 @@
1
  """
2
- Loads the prebuilt local RAG index (rag_index/, built by scripts/build_index.py)
3
- and retrieves anonymized context chunks. Never crawls or chunks anything itself.
 
4
 
5
  Retrieved chunks carry no title/author/URL/domain — the index physically does not
6
  store that metadata — so callers can only ever label them "Source 1", "Source 2", ...
@@ -71,6 +72,11 @@ def is_available() -> bool:
71
  return _collection is not None
72
 
73
 
 
 
 
 
 
74
  def retrieve(query: str, top_k: int = 8, category: str | list[str] | None = None) -> list[str]:
75
  """Returns ["Source 1: <text>", "Source 2: <text>", ...], or [] if unavailable.
76
 
 
1
  """
2
+ Loads the prebuilt local RAG index (rag_index/, built by
3
+ scripts/build_index_from_crawler.py) and retrieves anonymized context chunks.
4
+ Never crawls or chunks anything itself.
5
 
6
  Retrieved chunks carry no title/author/URL/domain — the index physically does not
7
  store that metadata — so callers can only ever label them "Source 1", "Source 2", ...
 
72
  return _collection is not None
73
 
74
 
75
+ def chunk_count() -> int:
76
+ _load()
77
+ return _collection.count() if _collection is not None else 0
78
+
79
+
80
  def retrieve(query: str, top_k: int = 8, category: str | list[str] | None = None) -> list[str]:
81
  """Returns ["Source 1: <text>", "Source 2: <text>", ...], or [] if unavailable.
82