Enhance document loading process with detailed logging and improved error handling
Browse files- api/fastapi_server.py +9 -2
api/fastapi_server.py
CHANGED
|
@@ -232,19 +232,26 @@ def build_knowledge_base():
|
|
| 232 |
# Create folder in advance
|
| 233 |
os.makedirs(VECTOR_STORE_PATH, exist_ok=True)
|
| 234 |
|
| 235 |
-
# Load documents
|
| 236 |
for url in URLS:
|
| 237 |
try:
|
|
|
|
| 238 |
loader = WebBaseLoader(url)
|
| 239 |
docs = loader.load()
|
|
|
|
| 240 |
documents.extend(docs)
|
| 241 |
print(f"Loaded {url}")
|
| 242 |
except Exception as e:
|
| 243 |
print(f"Failed to load {url}: {str(e)}")
|
|
|
|
| 244 |
continue
|
| 245 |
|
|
|
|
|
|
|
| 246 |
if not documents:
|
| 247 |
-
|
|
|
|
|
|
|
| 248 |
|
| 249 |
# Split into chunks
|
| 250 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
|
|
| 232 |
# Create folder in advance
|
| 233 |
os.makedirs(VECTOR_STORE_PATH, exist_ok=True)
|
| 234 |
|
| 235 |
+
# Load documents with detailed logging
|
| 236 |
for url in URLS:
|
| 237 |
try:
|
| 238 |
+
print(f"Attempting to load {url}")
|
| 239 |
loader = WebBaseLoader(url)
|
| 240 |
docs = loader.load()
|
| 241 |
+
print(f"Successfully loaded {url}, got {len(docs)} documents")
|
| 242 |
documents.extend(docs)
|
| 243 |
print(f"Loaded {url}")
|
| 244 |
except Exception as e:
|
| 245 |
print(f"Failed to load {url}: {str(e)}")
|
| 246 |
+
print(f"Full error: {traceback.format_exc()}")
|
| 247 |
continue
|
| 248 |
|
| 249 |
+
print(f"Total documents loaded: {len(documents)}")
|
| 250 |
+
|
| 251 |
if not documents:
|
| 252 |
+
error_msg = "No documents loaded! Check if the URLs are accessible and contain valid content."
|
| 253 |
+
print(error_msg)
|
| 254 |
+
raise HTTPException(status_code=500, detail=error_msg)
|
| 255 |
|
| 256 |
# Split into chunks
|
| 257 |
text_splitter = RecursiveCharacterTextSplitter(
|