force offline local MiniLM folder (no cache)
Browse files
rag.py
CHANGED
|
@@ -103,15 +103,24 @@ def get_texts() -> List[str]:
|
|
| 103 |
print(f"⚠ Dataset fetch failed: {e} – using empty corpus")
|
| 104 |
return []
|
| 105 |
|
| 106 |
-
# ------------------------------------------------------------------
|
| 107 |
# ------------------------------------------------------------------
|
| 108 |
@lru_cache(maxsize=1)
|
| 109 |
def get_vectorstore() -> FAISS:
|
| 110 |
texts = get_texts()
|
| 111 |
|
| 112 |
-
# --- FINAL:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
from sentence_transformers import SentenceTransformer
|
| 114 |
-
model = SentenceTransformer(
|
| 115 |
|
| 116 |
from langchain.embeddings import SentenceTransformerEmbeddings
|
| 117 |
embeddings = SentenceTransformerEmbeddings(model=model)
|
|
|
|
| 103 |
print(f"⚠ Dataset fetch failed: {e} – using empty corpus")
|
| 104 |
return []
|
| 105 |
|
|
|
|
| 106 |
# ------------------------------------------------------------------
|
| 107 |
@lru_cache(maxsize=1)
|
| 108 |
def get_vectorstore() -> FAISS:
|
| 109 |
texts = get_texts()
|
| 110 |
|
| 111 |
+
# --- FINAL: load local MiniLM (no internet, no cache) -----------------
|
| 112 |
+
import os
|
| 113 |
+
local_model_path = os.path.abspath(
|
| 114 |
+
os.path.join(os.path.dirname(__file__), "st_model")
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# force offline + local only
|
| 118 |
+
os.environ["TRANSFORMERS_OFFLINE"] = "1"
|
| 119 |
+
os.environ["HF_DATASETS_OFFLINE"] = "1"
|
| 120 |
+
os.environ["SENTENCE_TRANSFORMERS_HOME"] = local_model_path
|
| 121 |
+
|
| 122 |
from sentence_transformers import SentenceTransformer
|
| 123 |
+
model = SentenceTransformer(local_model_path, device="cpu", cache_folder=None)
|
| 124 |
|
| 125 |
from langchain.embeddings import SentenceTransformerEmbeddings
|
| 126 |
embeddings = SentenceTransformerEmbeddings(model=model)
|