Spaces:
Sleeping
Sleeping
“vinit5112”
commited on
Commit
·
45f1618
1
Parent(s):
0a7909d
async conflict
Browse files- backend/backend_api.py +12 -2
- backend/vector_store.py +4 -4
backend/backend_api.py
CHANGED
@@ -112,7 +112,7 @@ async def ask_question_stream(request: QuestionRequest):
|
|
112 |
raise HTTPException(status_code=500, detail=f"Error processing streaming question: {str(e)}")
|
113 |
|
114 |
@app.post("/api/upload")
|
115 |
-
async def upload_document(file: UploadFile = File(
|
116 |
"""
|
117 |
Upload a document to the RAG system
|
118 |
"""
|
@@ -120,6 +120,17 @@ async def upload_document(file: UploadFile = File(..., max_length=100*1024*1024)
|
|
120 |
if not rag_system:
|
121 |
raise HTTPException(status_code=500, detail="RAG system not initialized")
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
# Validate file type
|
124 |
allowed_extensions = ['.pdf', '.docx', '.txt']
|
125 |
file_extension = os.path.splitext(file.filename)[1].lower()
|
@@ -132,7 +143,6 @@ async def upload_document(file: UploadFile = File(..., max_length=100*1024*1024)
|
|
132 |
|
133 |
# Create temporary file
|
134 |
with tempfile.NamedTemporaryFile(delete=False, suffix=file_extension) as temp_file:
|
135 |
-
content = await file.read()
|
136 |
temp_file.write(content)
|
137 |
temp_file_path = temp_file.name
|
138 |
|
|
|
112 |
raise HTTPException(status_code=500, detail=f"Error processing streaming question: {str(e)}")
|
113 |
|
114 |
@app.post("/api/upload")
|
115 |
+
async def upload_document(file: UploadFile = File(...)):
|
116 |
"""
|
117 |
Upload a document to the RAG system
|
118 |
"""
|
|
|
120 |
if not rag_system:
|
121 |
raise HTTPException(status_code=500, detail="RAG system not initialized")
|
122 |
|
123 |
+
# Validate file size (100MB limit)
|
124 |
+
content = await file.read()
|
125 |
+
file_size_mb = len(content) / (1024 * 1024)
|
126 |
+
max_size_mb = 100
|
127 |
+
|
128 |
+
if file_size_mb > max_size_mb:
|
129 |
+
raise HTTPException(
|
130 |
+
status_code=413,
|
131 |
+
detail=f"File too large ({file_size_mb:.1f}MB). Maximum size allowed is {max_size_mb}MB."
|
132 |
+
)
|
133 |
+
|
134 |
# Validate file type
|
135 |
allowed_extensions = ['.pdf', '.docx', '.txt']
|
136 |
file_extension = os.path.splitext(file.filename)[1].lower()
|
|
|
143 |
|
144 |
# Create temporary file
|
145 |
with tempfile.NamedTemporaryFile(delete=False, suffix=file_extension) as temp_file:
|
|
|
146 |
temp_file.write(content)
|
147 |
temp_file_path = temp_file.name
|
148 |
|
backend/vector_store.py
CHANGED
@@ -271,15 +271,15 @@ class VectorStore:
|
|
271 |
try:
|
272 |
collection_info = self.client.get_collection(self.collection_name)
|
273 |
return {
|
274 |
-
"name":
|
275 |
"vector_size": collection_info.config.params.vectors.size,
|
276 |
-
"distance": collection_info.config.params.vectors.distance,
|
277 |
"points_count": collection_info.points_count,
|
278 |
-
"
|
279 |
}
|
280 |
except Exception as e:
|
281 |
print(f"Error getting collection info: {e}")
|
282 |
-
return {}
|
283 |
|
284 |
async def verify_collection_health(self) -> bool:
|
285 |
"""Verify that the collection is healthy and accessible"""
|
|
|
271 |
try:
|
272 |
collection_info = self.client.get_collection(self.collection_name)
|
273 |
return {
|
274 |
+
"name": self.collection_name,
|
275 |
"vector_size": collection_info.config.params.vectors.size,
|
276 |
+
"distance": collection_info.config.params.vectors.distance.name,
|
277 |
"points_count": collection_info.points_count,
|
278 |
+
"status": "ready"
|
279 |
}
|
280 |
except Exception as e:
|
281 |
print(f"Error getting collection info: {e}")
|
282 |
+
return {"name": self.collection_name, "status": "error", "error": str(e)}
|
283 |
|
284 |
async def verify_collection_health(self) -> bool:
|
285 |
"""Verify that the collection is healthy and accessible"""
|