Spaces:
Sleeping
Sleeping
Komalpreet Kaur Claude Haiku 4.5 commited on
feat: auto-build neural mesh from chat conversations
Browse filesAfter each chat exchange, the user's message and Soma's response are
now automatically ingested into ChromaDB (sensory memory) and
extracted as knowledge triples into Neo4j (semantic memory). This
runs in the background via asyncio so it doesn't slow down the
streaming response.
New users start with blank memory and their neural mesh grows
organically as they chat β no manual consolidation required.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- app/api/endpoints.py +16 -0
app/api/endpoints.py
CHANGED
|
@@ -17,6 +17,17 @@ from app.auth.auth import get_current_user
|
|
| 17 |
router = APIRouter()
|
| 18 |
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# ββ Brain Vitals βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 21 |
|
| 22 |
@router.get("/brain/vitals")
|
|
@@ -202,6 +213,11 @@ async def process_query_stream(request: QueryRequest, current_user: str = Depend
|
|
| 202 |
add_message(current_user, "user", request.text)
|
| 203 |
add_message(current_user, "assistant", final_response)
|
| 204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
yield f"event: final_result\ndata: {json.dumps({'response': final_response})}\n\n"
|
| 206 |
|
| 207 |
except Exception as e:
|
|
|
|
| 17 |
router = APIRouter()
|
| 18 |
|
| 19 |
|
| 20 |
+
# ββ Background memory builder ββββββββββββββββββββββββββββββββββββ
|
| 21 |
+
|
| 22 |
+
async def _build_memory(exchange_text: str, user_id: str):
|
| 23 |
+
"""Ingest a chat exchange into sensory + semantic memory in the background."""
|
| 24 |
+
try:
|
| 25 |
+
await asyncio.to_thread(ingest_text, exchange_text, {"type": "chat_exchange"}, user_id)
|
| 26 |
+
await asyncio.to_thread(extract_and_store_knowledge, exchange_text, user_id)
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print(f"Background memory build error: {e}")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
# ββ Brain Vitals βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 32 |
|
| 33 |
@router.get("/brain/vitals")
|
|
|
|
| 213 |
add_message(current_user, "user", request.text)
|
| 214 |
add_message(current_user, "assistant", final_response)
|
| 215 |
|
| 216 |
+
# Auto-build neural mesh: ingest exchange into
|
| 217 |
+
# sensory memory (ChromaDB) and semantic memory (Neo4j)
|
| 218 |
+
exchange_text = f"User: {request.text}\nSoma: {final_response}"
|
| 219 |
+
asyncio.create_task(_build_memory(exchange_text, current_user))
|
| 220 |
+
|
| 221 |
yield f"event: final_result\ndata: {json.dumps({'response': final_response})}\n\n"
|
| 222 |
|
| 223 |
except Exception as e:
|