Spaces:
Running
Running
Update app/policy_vector_db.py
Browse files- app/policy_vector_db.py +4 -9
app/policy_vector_db.py
CHANGED
|
@@ -54,13 +54,11 @@ class PolicyVectorDB:
|
|
| 54 |
batch = new_chunks[i:i + batch_size]
|
| 55 |
texts = [chunk['text'] for chunk in batch]
|
| 56 |
ids = [str(chunk['id']) for chunk in batch]
|
| 57 |
-
|
| 58 |
-
# --- FIX: Ensure metadata is never an empty dictionary ---
|
| 59 |
metadatas = []
|
| 60 |
for chunk in batch:
|
| 61 |
meta = chunk.get('metadata')
|
| 62 |
-
if not meta:
|
| 63 |
-
# Provide a default, non-empty metadata dictionary
|
| 64 |
meta = {"description": "General information chunk."}
|
| 65 |
metadatas.append(self._flatten_metadata(meta))
|
| 66 |
|
|
@@ -98,12 +96,9 @@ def ensure_db_populated(db_instance: PolicyVectorDB, chunks_file_path: str):
|
|
| 98 |
logger.error(f"Chunks file not found at {chunks_file_path}. Cannot populate DB.")
|
| 99 |
return False
|
| 100 |
|
| 101 |
-
|
| 102 |
with open(chunks_file_path, 'r', encoding='utf-8') as f:
|
| 103 |
-
|
| 104 |
-
line = line.strip()
|
| 105 |
-
if line:
|
| 106 |
-
chunks_to_add.append(json.loads(line))
|
| 107 |
|
| 108 |
if not chunks_to_add:
|
| 109 |
logger.warning(f"Chunks file at {chunks_file_path} is empty. No data to add to DB.")
|
|
|
|
| 54 |
batch = new_chunks[i:i + batch_size]
|
| 55 |
texts = [chunk['text'] for chunk in batch]
|
| 56 |
ids = [str(chunk['id']) for chunk in batch]
|
| 57 |
+
|
|
|
|
| 58 |
metadatas = []
|
| 59 |
for chunk in batch:
|
| 60 |
meta = chunk.get('metadata')
|
| 61 |
+
if not meta:
|
|
|
|
| 62 |
meta = {"description": "General information chunk."}
|
| 63 |
metadatas.append(self._flatten_metadata(meta))
|
| 64 |
|
|
|
|
| 96 |
logger.error(f"Chunks file not found at {chunks_file_path}. Cannot populate DB.")
|
| 97 |
return False
|
| 98 |
|
| 99 |
+
# --- FIX: Use json.load() to read the entire standard .json file at once ---
|
| 100 |
with open(chunks_file_path, 'r', encoding='utf-8') as f:
|
| 101 |
+
chunks_to_add = json.load(f)
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
if not chunks_to_add:
|
| 104 |
logger.warning(f"Chunks file at {chunks_file_path} is empty. No data to add to DB.")
|