Update app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ collection_name = "paper"
|
|
| 41 |
upload_dir = "uploaded_files"
|
| 42 |
if not os.path.exists(upload_dir):
|
| 43 |
os.makedirs(upload_dir)
|
| 44 |
-
# We
|
| 45 |
|
| 46 |
# -------------------------------------------------------
|
| 47 |
# Function to process uploaded files and update the index.
|
|
@@ -81,10 +81,12 @@ def process_upload(files):
|
|
| 81 |
if collection_name not in existing_collections:
|
| 82 |
client.create_collection(
|
| 83 |
collection_name=collection_name,
|
| 84 |
-
vectors_config=
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
| 88 |
)
|
| 89 |
# Wait briefly for the collection creation to complete.
|
| 90 |
time.sleep(1)
|
|
@@ -101,6 +103,7 @@ def process_upload(files):
|
|
| 101 |
|
| 102 |
# Build the index if it doesn't exist; otherwise, update it.
|
| 103 |
if index is None:
|
|
|
|
| 104 |
index = VectorStoreIndex.from_documents(
|
| 105 |
SimpleDirectoryReader(upload_dir).load_data(),
|
| 106 |
storage_context=storage_context
|
|
|
|
| 41 |
upload_dir = "uploaded_files"
|
| 42 |
if not os.path.exists(upload_dir):
|
| 43 |
os.makedirs(upload_dir)
|
| 44 |
+
# We do not clear the folder to keep previously uploaded files.
|
| 45 |
|
| 46 |
# -------------------------------------------------------
|
| 47 |
# Function to process uploaded files and update the index.
|
|
|
|
| 81 |
if collection_name not in existing_collections:
|
| 82 |
client.create_collection(
|
| 83 |
collection_name=collection_name,
|
| 84 |
+
vectors_config={
|
| 85 |
+
"text-dense": models.VectorParams(
|
| 86 |
+
size=1536, # text-embedding-ada-002 produces 1536-dimensional vectors.
|
| 87 |
+
distance=models.Distance.COSINE
|
| 88 |
+
)
|
| 89 |
+
}
|
| 90 |
)
|
| 91 |
# Wait briefly for the collection creation to complete.
|
| 92 |
time.sleep(1)
|
|
|
|
| 103 |
|
| 104 |
# Build the index if it doesn't exist; otherwise, update it.
|
| 105 |
if index is None:
|
| 106 |
+
# Load all documents from the persistent folder.
|
| 107 |
index = VectorStoreIndex.from_documents(
|
| 108 |
SimpleDirectoryReader(upload_dir).load_data(),
|
| 109 |
storage_context=storage_context
|