Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from langchain.document_loaders import PyPDFLoader
|
|
3 |
from langchain.document_loaders import TextLoader
|
4 |
from langchain.document_loaders import Docx2txtLoader
|
5 |
from langchain.text_splitter import CharacterTextSplitter
|
|
|
6 |
from langchain.embeddings import HuggingFaceEmbeddings
|
7 |
from langchain.vectorstores import Chroma
|
8 |
from huggingface_hub import notebook_login
|
@@ -37,7 +38,7 @@ llm = ChatGoogleGenerativeAI(
|
|
37 |
max_retries=2,
|
38 |
)
|
39 |
|
40 |
-
|
41 |
embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-mpnet-base-v2')
|
42 |
|
43 |
def load_preprocessed_vectorstore():
|
@@ -58,12 +59,7 @@ def load_preprocessed_vectorstore():
|
|
58 |
|
59 |
document_chunks = text_splitter.split_documents(document)
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
embedding=embeddings,
|
64 |
-
documents=document_chunks,
|
65 |
-
persist_directory="./data32"
|
66 |
-
)
|
67 |
return vector_store
|
68 |
except Exception as e:
|
69 |
st.error(f"Error creating vector store: {e}")
|
|
|
3 |
from langchain.document_loaders import TextLoader
|
4 |
from langchain.document_loaders import Docx2txtLoader
|
5 |
from langchain.text_splitter import CharacterTextSplitter
|
6 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
7 |
from langchain.embeddings import HuggingFaceEmbeddings
|
8 |
from langchain.vectorstores import Chroma
|
9 |
from huggingface_hub import notebook_login
|
|
|
38 |
max_retries=2,
|
39 |
)
|
40 |
|
41 |
+
|
42 |
embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-mpnet-base-v2')
|
43 |
|
44 |
def load_preprocessed_vectorstore():
|
|
|
59 |
|
60 |
document_chunks = text_splitter.split_documents(document)
|
61 |
|
62 |
+
vector_store =Chroma.from_documents(document_chunks,embedding=embeddings, persist_directory='./data')
|
|
|
|
|
|
|
|
|
|
|
63 |
return vector_store
|
64 |
except Exception as e:
|
65 |
st.error(f"Error creating vector store: {e}")
|