Spaces:
Running
Running
Switch to standard FAISS library
Browse files
agents/demystifier_agent.py
CHANGED
|
@@ -7,7 +7,7 @@ from pydantic import BaseModel, Field
|
|
| 7 |
# --- Core LangChain & Document Processing Imports ---
|
| 8 |
from langchain_community.document_loaders import PyPDFLoader
|
| 9 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 10 |
-
from
|
| 11 |
from langchain_core.prompts import PromptTemplate
|
| 12 |
from langchain_core.runnables import RunnablePassthrough
|
| 13 |
from langchain_core.output_parsers import StrOutputParser
|
|
@@ -30,11 +30,8 @@ def process_document_for_demystification(file_path: str):
|
|
| 30 |
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
|
| 31 |
chunks = splitter.split_documents(documents)
|
| 32 |
|
| 33 |
-
print("--- Creating
|
| 34 |
-
vectorstore =
|
| 35 |
-
# SimpleVectorStore doesn't support as_retriever directly in the same way as FAISS without modification,
|
| 36 |
-
# but we can wrap it or just use it as a retriever if we implemented as_retriever.
|
| 37 |
-
# Actually, VectorStore base class has as_retriever.
|
| 38 |
retriever = vectorstore.as_retriever(search_kwargs={"k": 3})
|
| 39 |
rag_chain = create_rag_chain(retriever)
|
| 40 |
|
|
|
|
| 7 |
# --- Core LangChain & Document Processing Imports ---
|
| 8 |
from langchain_community.document_loaders import PyPDFLoader
|
| 9 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 10 |
+
from langchain_community.vectorstores import FAISS
|
| 11 |
from langchain_core.prompts import PromptTemplate
|
| 12 |
from langchain_core.runnables import RunnablePassthrough
|
| 13 |
from langchain_core.output_parsers import StrOutputParser
|
|
|
|
| 30 |
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
|
| 31 |
chunks = splitter.split_documents(documents)
|
| 32 |
|
| 33 |
+
print("--- Creating FAISS vector store for Q&A ---")
|
| 34 |
+
vectorstore = FAISS.from_documents(chunks, embedding=embedding_model)
|
|
|
|
|
|
|
|
|
|
| 35 |
retriever = vectorstore.as_retriever(search_kwargs={"k": 3})
|
| 36 |
rag_chain = create_rag_chain(retriever)
|
| 37 |
|