load local ONNX MiniLM with absolute path (no cache)
Browse files
rag.py
CHANGED
|
@@ -109,9 +109,17 @@ def get_texts() -> List[str]:
|
|
| 109 |
def get_vectorstore() -> FAISS:
|
| 110 |
texts = get_texts()
|
| 111 |
|
| 112 |
-
# --- FINAL:
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
# ------------------------------------------------------------------------
|
| 116 |
|
| 117 |
if not texts: # no data → empty FAISS
|
|
|
|
| 109 |
def get_vectorstore() -> FAISS:
|
| 110 |
texts = get_texts()
|
| 111 |
|
| 112 |
+
# --- FINAL: load local ONNX MiniLM (no internet, no disk write) -------
|
| 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
|