NimrodDev commited on
Commit
f688f90
·
1 Parent(s): ea6472f

load local MiniLM folder (no optimum, no internet)

Browse files
Files changed (1) hide show
  1. rag.py +11 -15
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: use optimum ONNX MiniLM (already on disk) -----------------
112
  import os
113
- from optimum.pipelines import pipeline
114
- from langchain.embeddings.base import Embeddings
115
-
116
- class OptimumMiniLM(Embeddings):
117
- def __init__(self):
118
- self.pipe = pipeline("feature-extraction",
119
- model="optimum/all-MiniLM-L6-v2",
120
- device="cpu")
121
- def embed_documents(self, texts):
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