load local MiniLM folder (no optimum, no internet)
Browse files
rag.py
CHANGED
|
@@ -103,27 +103,23 @@ def get_texts() -> List[str]:
|
|
| 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:
|
| 112 |
import os
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
return [self.pipe(t)[0][0] for t in texts]
|
| 123 |
-
def embed_query(self, text):
|
| 124 |
-
return self.embed_documents([text])[0]
|
| 125 |
-
|
| 126 |
-
embeddings = OptimumMiniLM()
|
| 127 |
# ------------------------------------------------------------------------
|
| 128 |
|
| 129 |
if not texts: # no data → empty FAISS
|
|
|
|
| 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: load local MiniLM (no internet, no cache) -----------------
|
| 113 |
import os
|
| 114 |
+
local_model_path = os.path.abspath(
|
| 115 |
+
os.path.join(os.path.dirname(__file__), "st_model")
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
from sentence_transformers import SentenceTransformer
|
| 119 |
+
model = SentenceTransformer(local_model_path, device="cpu", cache_folder=None)
|
| 120 |
+
|
| 121 |
+
from langchain.embeddings import SentenceTransformerEmbeddings
|
| 122 |
+
embeddings = SentenceTransformerEmbeddings(model=model)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
# ------------------------------------------------------------------------
|
| 124 |
|
| 125 |
if not texts: # no data → empty FAISS
|