Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,8 @@ import io
|
|
| 13 |
|
| 14 |
app = FastAPI()
|
| 15 |
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
| 16 |
-
|
|
|
|
| 17 |
documents = []
|
| 18 |
|
| 19 |
templates = Jinja2Templates(directory=".")
|
|
@@ -65,7 +66,8 @@ def get_database_length():
|
|
| 65 |
|
| 66 |
@app.post("/admin/database/reset")
|
| 67 |
def reset_database():
|
| 68 |
-
index
|
|
|
|
| 69 |
documents = []
|
| 70 |
return {"message": "Database reset"}
|
| 71 |
|
|
@@ -82,6 +84,14 @@ def download_documents():
|
|
| 82 |
|
| 83 |
return response
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
@app.get("/admin/database/download")
|
| 86 |
def download_database():
|
| 87 |
# Save the FAISS index and documents list to a single file
|
|
|
|
| 13 |
|
| 14 |
app = FastAPI()
|
| 15 |
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
| 16 |
+
embedding_dimension = 384 # 384 is the dimensionality of the MiniLM model
|
| 17 |
+
index = faiss.IndexFlatL2(embedding_dimension)
|
| 18 |
documents = []
|
| 19 |
|
| 20 |
templates = Jinja2Templates(directory=".")
|
|
|
|
| 66 |
|
| 67 |
@app.post("/admin/database/reset")
|
| 68 |
def reset_database():
|
| 69 |
+
global index
|
| 70 |
+
index = faiss.IndexFlatL2(embedding_dimension)
|
| 71 |
documents = []
|
| 72 |
return {"message": "Database reset"}
|
| 73 |
|
|
|
|
| 84 |
|
| 85 |
return response
|
| 86 |
|
| 87 |
+
##### TESTING ######
|
| 88 |
+
@app.get("/admin/documents/upload")
|
| 89 |
+
def upload_documents(request: EmbedRequest):
|
| 90 |
+
documents.extend(request.texts)
|
| 91 |
+
return {
|
| 92 |
+
"message": f"{len(new_documents)} new documents uploaded"
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
@app.get("/admin/database/download")
|
| 96 |
def download_database():
|
| 97 |
# Save the FAISS index and documents list to a single file
|