Update app.py
Browse files
app.py
CHANGED
|
@@ -84,11 +84,24 @@ all_splits = text_splitter.split_documents(docs)
|
|
| 84 |
# -------------------------------
|
| 85 |
|
| 86 |
# Create a Chroma vector store using the document splits
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# Create a BM25 retriever from the document splits
|
| 94 |
bm25_retriever = BM25Retriever.from_documents(all_splits)
|
|
|
|
| 84 |
# -------------------------------
|
| 85 |
|
| 86 |
# Create a Chroma vector store using the document splits
|
| 87 |
+
persist_directory = "./chroma_db"
|
| 88 |
+
|
| 89 |
+
# Check if the persist directory exists and contains data.
|
| 90 |
+
if os.path.exists(persist_directory) and os.listdir(persist_directory):
|
| 91 |
+
# Load the persisted vector store
|
| 92 |
+
vectorstore = Chroma(
|
| 93 |
+
persist_directory=persist_directory,
|
| 94 |
+
embedding_function=OpenAIEmbeddings()
|
| 95 |
+
)
|
| 96 |
+
print("Loaded vector store from persist directory.")
|
| 97 |
+
else:
|
| 98 |
+
# Create a new vector store from your document splits and persist it.
|
| 99 |
+
vectorstore = Chroma.from_documents(
|
| 100 |
+
documents=all_splits,
|
| 101 |
+
embedding=OpenAIEmbeddings(),
|
| 102 |
+
persist_directory=persist_directory
|
| 103 |
+
)
|
| 104 |
+
print("Created new vector store and persisted embeddings.")
|
| 105 |
|
| 106 |
# Create a BM25 retriever from the document splits
|
| 107 |
bm25_retriever = BM25Retriever.from_documents(all_splits)
|