Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -59,7 +59,7 @@ from youtube_transcript_api._errors import TranscriptsDisabled, VideoUnavailable
|
|
59 |
from langchain.schema import Document
|
60 |
|
61 |
from langchain_community.vectorstores import FAISS
|
62 |
-
from
|
63 |
from langchain.tools.retriever import create_retriever_tool
|
64 |
#from langchain_community.tools import create_retriever_tool
|
65 |
from typing import TypedDict, Annotated, List
|
@@ -429,18 +429,24 @@ embedding_model = HuggingFaceEmbeddings(
|
|
429 |
# -----------------------------
|
430 |
# Create FAISS index and save it
|
431 |
# -----------------------------
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
|
437 |
-
vector_store.save_local("/home/wendy/Downloads/faiss_index")
|
438 |
|
439 |
# -----------------------------
|
440 |
# Load FAISS index properly
|
441 |
# -----------------------------
|
442 |
loaded_store = FAISS.load_local("/home/wendy/Downloads/faiss_index", embedding_model)
|
443 |
|
|
|
444 |
# -----------------------------
|
445 |
# Create LangChain Retriever Tool
|
446 |
# -----------------------------
|
|
|
59 |
from langchain.schema import Document
|
60 |
|
61 |
from langchain_community.vectorstores import FAISS
|
62 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
63 |
from langchain.tools.retriever import create_retriever_tool
|
64 |
#from langchain_community.tools import create_retriever_tool
|
65 |
from typing import TypedDict, Annotated, List
|
|
|
429 |
# -----------------------------
|
430 |
# Create FAISS index and save it
|
431 |
# -----------------------------
|
432 |
+
try:
|
433 |
+
vector_store = FAISS.load_local(
|
434 |
+
"/home/wendy/Downloads/faiss_index/faiss_index",
|
435 |
+
embedding_model,
|
436 |
+
allow_dangerous_deserialization=True
|
437 |
+
)
|
438 |
+
except Exception as e:
|
439 |
+
print(f"Error loading index: {str(e)}")
|
440 |
+
# Fallback to rebuilding index
|
441 |
+
vector_store = FAISS.from_documents(docs, embedding_model)
|
442 |
|
|
|
443 |
|
444 |
# -----------------------------
|
445 |
# Load FAISS index properly
|
446 |
# -----------------------------
|
447 |
loaded_store = FAISS.load_local("/home/wendy/Downloads/faiss_index", embedding_model)
|
448 |
|
449 |
+
|
450 |
# -----------------------------
|
451 |
# Create LangChain Retriever Tool
|
452 |
# -----------------------------
|