Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,22 @@ from utills import load_txt_documents, split_docs, load_uploaded_documents, retr
|
|
16 |
from langchain.text_splitter import TokenTextSplitter, RecursiveCharacterTextSplitter
|
17 |
from langchain_community.document_loaders.directory import DirectoryLoader
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
data_path = "data"
|
20 |
|
21 |
|
@@ -130,18 +146,7 @@ def create_conversational_rag_chain(vectorstore):
|
|
130 |
return conversation_chain
|
131 |
|
132 |
|
133 |
-
|
134 |
-
model_name = "sentence-transformers/all-mpnet-base-v2"
|
135 |
-
model_kwargs = {'device': 'cpu'}
|
136 |
-
encode_kwargs = {'normalize_embeddings': True}
|
137 |
-
embeddings = HuggingFaceEmbeddings(
|
138 |
-
model_name=model_name,
|
139 |
-
model_kwargs=model_kwargs,
|
140 |
-
encode_kwargs=encode_kwargs
|
141 |
-
)
|
142 |
-
vectorstore = Chroma.from_documents(
|
143 |
-
documents=text_chunks, embedding=embeddings, persist_directory="docs/chroma/")
|
144 |
-
return vectorstore
|
145 |
|
146 |
if __name__ == "__main__":
|
147 |
main()
|
|
|
16 |
from langchain.text_splitter import TokenTextSplitter, RecursiveCharacterTextSplitter
|
17 |
from langchain_community.document_loaders.directory import DirectoryLoader
|
18 |
|
19 |
+
|
20 |
+
def get_vectorstore(text_chunks):
|
21 |
+
model_name = "sentence-transformers/all-mpnet-base-v2"
|
22 |
+
model_kwargs = {'device': 'cpu'}
|
23 |
+
encode_kwargs = {'normalize_embeddings': True}
|
24 |
+
embeddings = HuggingFaceEmbeddings(
|
25 |
+
model_name=model_name,
|
26 |
+
model_kwargs=model_kwargs,
|
27 |
+
encode_kwargs=encode_kwargs
|
28 |
+
)
|
29 |
+
vectorstore = Chroma.from_documents(
|
30 |
+
documents=text_chunks, embedding=embeddings, persist_directory="docs/chroma/")
|
31 |
+
return vectorstore
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
data_path = "data"
|
36 |
|
37 |
|
|
|
146 |
return conversation_chain
|
147 |
|
148 |
|
149 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
if __name__ == "__main__":
|
152 |
main()
|