Update app.py
Browse files
app.py
CHANGED
@@ -45,23 +45,28 @@ def create_retriever_from_chroma(vectorstore_path="docs/chroma/", search_type='m
|
|
45 |
|
46 |
|
47 |
# Check if vectorstore exists
|
48 |
-
|
49 |
# Load the existing vectorstore
|
50 |
-
|
51 |
-
|
|
|
|
|
52 |
# Load documents from the specified data path
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
|
59 |
|
60 |
# Create the vectorstore
|
61 |
-
|
62 |
documents=split_docs, embedding=embeddings, persist_directory=vectorstore_path
|
63 |
)
|
64 |
-
|
65 |
|
66 |
retriever=vectorstore.as_retriever(search_type = search_type, search_kwargs={"k": k})
|
67 |
|
|
|
45 |
|
46 |
|
47 |
# Check if vectorstore exists
|
48 |
+
if os.path.exists(vectorstore_path) and os.listdir(vectorstore_path):
|
49 |
# Load the existing vectorstore
|
50 |
+
st.write("Vector store exists and is loaded")
|
51 |
+
vectorstore = Chroma(persist_directory=vectorstore_path,embedding_function=embeddings)
|
52 |
+
|
53 |
+
else:
|
54 |
# Load documents from the specified data path
|
55 |
+
st.write("Vector store doesnt exist and will be created now")
|
56 |
+
loader = DirectoryLoader('./data/', glob="./*.txt", loader_cls=TextLoader)
|
57 |
+
docs = loader.load()
|
58 |
+
st.write("Docs loaded")
|
59 |
+
|
60 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap,separators=["\n \n \n", "\n \n", "\n1" , "(?<=\. )", " ", ""])
|
61 |
+
split_docs = text_splitter.split_documents(docs)
|
62 |
|
63 |
|
64 |
|
65 |
# Create the vectorstore
|
66 |
+
vectorstore = Chroma.from_documents(
|
67 |
documents=split_docs, embedding=embeddings, persist_directory=vectorstore_path
|
68 |
)
|
69 |
+
st.write("VectorStore is created")
|
70 |
|
71 |
retriever=vectorstore.as_retriever(search_type = search_type, search_kwargs={"k": k})
|
72 |
|