Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -76,16 +76,31 @@ async def setup_kb(kb_file: UploadFile = File(...)):
|
|
| 76 |
# Prepare texts, ids, and metadata
|
| 77 |
texts, ids, metadatas = [], [], []
|
| 78 |
for i, item in enumerate(data):
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
item_id = item.get("id") or str(i)
|
|
|
|
| 81 |
|
| 82 |
if not text:
|
| 83 |
print(f"⚠️ Skipping item {i} - no text content")
|
| 84 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
texts.append(
|
| 87 |
ids.append(str(item_id))
|
| 88 |
-
metadatas.append({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
if not texts:
|
| 91 |
raise HTTPException(status_code=400, detail="No valid text content found in JSON.")
|
|
|
|
| 76 |
# Prepare texts, ids, and metadata
|
| 77 |
texts, ids, metadatas = [], [], []
|
| 78 |
for i, item in enumerate(data):
|
| 79 |
+
# Try multiple possible field names for text content
|
| 80 |
+
text = (item.get("answer") or
|
| 81 |
+
item.get("text") or
|
| 82 |
+
item.get("content") or "")
|
| 83 |
+
|
| 84 |
item_id = item.get("id") or str(i)
|
| 85 |
+
category = item.get("category", "")
|
| 86 |
|
| 87 |
if not text:
|
| 88 |
print(f"⚠️ Skipping item {i} - no text content")
|
| 89 |
continue
|
| 90 |
+
|
| 91 |
+
# Create a richer text for embedding by combining relevant fields
|
| 92 |
+
# This helps with better semantic search
|
| 93 |
+
combined_text = text
|
| 94 |
+
if category:
|
| 95 |
+
combined_text = f"Category: {category}. {text}"
|
| 96 |
|
| 97 |
+
texts.append(combined_text)
|
| 98 |
ids.append(str(item_id))
|
| 99 |
+
metadatas.append({
|
| 100 |
+
"id": str(item_id),
|
| 101 |
+
"category": category,
|
| 102 |
+
"original_index": i
|
| 103 |
+
})
|
| 104 |
|
| 105 |
if not texts:
|
| 106 |
raise HTTPException(status_code=400, detail="No valid text content found in JSON.")
|