load ST model once into RAM (no disk, no external API)
Browse files
rag.py
CHANGED
|
@@ -105,17 +105,16 @@ def get_texts() -> List[str]:
|
|
| 105 |
|
| 106 |
## ------------------------------------------------------------------
|
| 107 |
# ------# ------------------------------------------------------------------
|
|
|
|
| 108 |
@lru_cache(maxsize=1)
|
| 109 |
def get_vectorstore() -> FAISS:
|
| 110 |
texts = get_texts()
|
| 111 |
|
| 112 |
-
# ---
|
| 113 |
-
from
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
api_url="https://router.huggingface.co/hf-inference" # ← new router
|
| 118 |
-
)
|
| 119 |
# ------------------------------------------------------------------------
|
| 120 |
|
| 121 |
if not texts: # no data → empty FAISS
|
|
|
|
| 105 |
|
| 106 |
## ------------------------------------------------------------------
|
| 107 |
# ------# ------------------------------------------------------------------
|
| 108 |
+
# ------------------------------------------------------------------
|
| 109 |
@lru_cache(maxsize=1)
|
| 110 |
def get_vectorstore() -> FAISS:
|
| 111 |
texts = get_texts()
|
| 112 |
|
| 113 |
+
# --- FINAL: load 384 KB model once into RAM (no cache, no disk) --------
|
| 114 |
+
from sentence_transformers import SentenceTransformer
|
| 115 |
+
model = SentenceTransformer("all-MiniLM-L6-v2", device="cpu", cache_folder=None)
|
| 116 |
+
from langchain.embeddings import SentenceTransformerEmbeddings
|
| 117 |
+
embeddings = SentenceTransformerEmbeddings(model=model)
|
|
|
|
|
|
|
| 118 |
# ------------------------------------------------------------------------
|
| 119 |
|
| 120 |
if not texts: # no data → empty FAISS
|