AlexKurian commited on
Commit
a2f12e1
·
1 Parent(s): d7b3396

Disable RAG model download for instant startup (Light Mode)

Browse files
Files changed (1) hide show
  1. policy_engine.py +19 -32
policy_engine.py CHANGED
@@ -77,41 +77,28 @@ class PolicyEngine:
77
 
78
  def __init__(self):
79
  """Initialize FAISS index and LLM."""
80
- from huggingface_hub import snapshot_download
81
-
82
- print(f"Initializing PolicyEngine with model: {config.EMBEDDINGS_MODEL}")
 
83
 
84
- # Robust download with retries
85
- try:
86
- snapshot_download(
87
- repo_id=config.EMBEDDINGS_MODEL,
88
- resume_download=True,
89
- etag_timeout=60,
90
- ignore_patterns=["*.onnx", "*.tflite", "*.ot", "*.h5", "*.msgpack", "*.safetensors"]
91
- )
92
- except Exception as e:
93
- print(f"Standard download failed, retrying without hf_transfer: {e}")
94
- os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
95
- # Fallback
96
- pass
97
-
98
- self.embeddings = HuggingFaceEmbeddings(
99
- model_name=config.EMBEDDINGS_MODEL,
100
- model_kwargs={'device': 'cpu'},
101
- encode_kwargs={'normalize_embeddings': True}
102
- )
103
 
104
- try:
105
- self.db = FAISS.load_local(
106
- str(config.FAISS_INDEX_PATH),
107
- self.embeddings,
108
- allow_dangerous_deserialization=True
109
- )
110
- except Exception as e:
111
- print(f"Warning: FAISS index not found at {config.FAISS_INDEX_PATH}")
112
- print(f"Error: {e}")
113
- self.db = None
114
 
 
 
 
 
 
 
 
 
 
 
 
115
  self.llm = ChatGroq(
116
  model=config.LLM_MODEL,
117
  temperature=0.5,
 
77
 
78
  def __init__(self):
79
  """Initialize FAISS index and LLM."""
80
+ # SKIP EMBEDDINGS DOWNLOAD: "Can we not do it at all?"
81
+ # User requested instant startup without RAG.
82
+ # -----------------------------------------------------------------
83
+ # from huggingface_hub import snapshot_download
84
 
85
+ print("\n[INFO] RAG/Embeddings initialization SKIPPED by configuration.")
86
+ print("[INFO] Policy Engine running in 'Direct Query' mode (LLM only).")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
+ self.embeddings = None
89
+ self.db = None
 
 
 
 
 
 
 
 
90
 
91
+ # -----------------------------------------------------------------
92
+ # Original logic commented out to prevent 400MB+ download on Spaces:
93
+ #
94
+ # print(f"Initializing PolicyEngine with model: {config.EMBEDDINGS_MODEL}")
95
+ # try:
96
+ # snapshot_download(...)
97
+ # except Exception: ...
98
+ # self.embeddings = HuggingFaceEmbeddings(...)
99
+ # self.db = FAISS.load_local(...)
100
+ # -----------------------------------------------------------------
101
+
102
  self.llm = ChatGroq(
103
  model=config.LLM_MODEL,
104
  temperature=0.5,