Spaces:
Running
Running
Update manabUtils.py
Browse files- manabUtils.py +28 -9
manabUtils.py
CHANGED
|
@@ -44,16 +44,35 @@ def retrieve_chunks_GPC():
|
|
| 44 |
Retreive chunks from HF dataset for GPC
|
| 45 |
"""
|
| 46 |
embedding_model="sentence-transformers/all-MiniLM-L6-v2"
|
|
|
|
| 47 |
|
| 48 |
try:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
-
|
| 58 |
-
|
| 59 |
return retriever
|
|
|
|
| 44 |
Retreive chunks from HF dataset for GPC
|
| 45 |
"""
|
| 46 |
embedding_model="sentence-transformers/all-MiniLM-L6-v2"
|
| 47 |
+
repo_id="manabb/NRLGPC"
|
| 48 |
|
| 49 |
try:
|
| 50 |
+
# Step 1: Create embeddings (FIX: was missing)
|
| 51 |
+
embeddings = HuggingFaceEmbeddings(model_name=embedding_model)
|
| 52 |
+
|
| 53 |
+
# Step 2: Download FAISS files from HF Hub
|
| 54 |
+
faiss_path = hf_hub_download(
|
| 55 |
+
repo_id=repo_id,
|
| 56 |
+
filename="faiss_gpc_goods_merged/index.faiss",
|
| 57 |
+
repo_type="dataset"
|
| 58 |
+
)
|
| 59 |
+
pkl_path = hf_hub_download(
|
| 60 |
+
repo_id=repo_id,
|
| 61 |
+
filename="faiss_gpc_goods_merged/index.pkl",
|
| 62 |
+
repo_type="dataset"
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
# Step 3: Load FAISS vectorstore (FIX: pass embeddings object, not string)
|
| 66 |
+
folder_path = os.path.dirname(faiss_path)
|
| 67 |
+
vectorstore = FAISS.load_local(
|
| 68 |
+
folder_path=folder_path,
|
| 69 |
+
embeddings=embeddings, # FIXED: was 'embedding_model' string
|
| 70 |
+
allow_dangerous_deserialization=True
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# Step 4: Create retriever
|
| 74 |
+
retriever = vectorstore.as_retriever(search_kwargs={"k": 3})
|
| 75 |
except Exception as e:
|
| 76 |
+
print(f"Error in generate_qa_chain: {e}")
|
| 77 |
+
return None
|
| 78 |
return retriever
|