Update app.py
Browse files
app.py
CHANGED
|
@@ -178,32 +178,27 @@ class VectorSystem:
|
|
| 178 |
if not question:
|
| 179 |
return "⚠️ Please enter a Question."
|
| 180 |
|
| 181 |
-
#
|
| 182 |
-
# Lower Score = Better Match (L2 Distance)
|
| 183 |
results = self.vector_store.similarity_search_with_score(question, k=3)
|
| 184 |
|
| 185 |
output_text = "### 🔍 Expanded Context Analysis:\n"
|
| 186 |
|
| 187 |
for i, (doc, score) in enumerate(results):
|
| 188 |
-
# Get the ID of the matched chunk
|
| 189 |
chunk_id = doc.metadata['id']
|
| 190 |
|
| 191 |
-
# Retrieve Previous and Next chunks
|
| 192 |
-
#
|
| 193 |
-
prev_chunk = self.all_chunks[chunk_id - 1] if chunk_id > 0 else "
|
| 194 |
-
next_chunk = self.all_chunks[chunk_id + 1] if chunk_id < len(self.all_chunks) - 1 else "
|
| 195 |
|
| 196 |
output_text += f"\n#### 🎯 Match #{i+1} (Distance Score: {score:.4f})\n"
|
| 197 |
-
output_text += f"*A lower score means a closer match.*\n\n"
|
| 198 |
|
| 199 |
-
#
|
| 200 |
-
output_text += f"> **Preceding Context:** ...{prev_chunk[-200:]}\n"
|
| 201 |
|
| 202 |
-
|
| 203 |
-
output_text += f"> **MATCH
|
|
|
|
| 204 |
|
| 205 |
-
# Display Succeeding Context
|
| 206 |
-
output_text += f"> **Succeeding Context:** {next_chunk[:200]}...\n"
|
| 207 |
output_text += "---\n"
|
| 208 |
|
| 209 |
return output_text
|
|
|
|
| 178 |
if not question:
|
| 179 |
return "⚠️ Please enter a Question."
|
| 180 |
|
| 181 |
+
# Lower Score = Better Match
|
|
|
|
| 182 |
results = self.vector_store.similarity_search_with_score(question, k=3)
|
| 183 |
|
| 184 |
output_text = "### 🔍 Expanded Context Analysis:\n"
|
| 185 |
|
| 186 |
for i, (doc, score) in enumerate(results):
|
|
|
|
| 187 |
chunk_id = doc.metadata['id']
|
| 188 |
|
| 189 |
+
# Retrieve Previous and Next chunks
|
| 190 |
+
# Logic: If it's the first chunk (ID 0), there is no 'prev', so returns empty string
|
| 191 |
+
prev_chunk = self.all_chunks[chunk_id - 1] if chunk_id > 0 else "(Start of Text)"
|
| 192 |
+
next_chunk = self.all_chunks[chunk_id + 1] if chunk_id < len(self.all_chunks) - 1 else "(End of Text)"
|
| 193 |
|
| 194 |
output_text += f"\n#### 🎯 Match #{i+1} (Distance Score: {score:.4f})\n"
|
|
|
|
| 195 |
|
| 196 |
+
# --- CHANGED HERE: Removed [-200:] and [:200] ---
|
|
|
|
| 197 |
|
| 198 |
+
output_text += f"> **Preceding Context:**\n{prev_chunk}\n\n"
|
| 199 |
+
output_text += f"> **MATCH:**\n**{doc.page_content}**\n\n"
|
| 200 |
+
output_text += f"> **Succeeding Context:**\n{next_chunk}\n"
|
| 201 |
|
|
|
|
|
|
|
| 202 |
output_text += "---\n"
|
| 203 |
|
| 204 |
return output_text
|