BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications.
Python ai-agentsai-memoryknowledge-graphknowledge-managementknowledge-representationreccomendation-system
fix(retrieval): structured data historical content
Christian1308951ef07e
diff --git a/src/constants/data.py b/src/constants/data.pyindex a1d0f8a..de9e7db 100644--- a/src/constants/data.py+++ b/src/constants/data.py@@ -4,7 +4,7 @@ Created Date: Saturday October 25th 2025Author: Christian Nonis <[email protected]>-----Last Modified: Saturday October 25th 2025 11:48:51 am-Modified By: the developer formerly known as Christian Nonis at <[email protected]>+Modified By: Christian Nonis <[email protected]>-----"""@@ -49,6 +49,7 @@ class StructuredData(BaseModel):)brain_version: str = Field(description="The version of the brain when the structured data was inserted.",+ default="0.0.0",)diff --git a/src/services/api/controllers/retrieve.py b/src/services/api/controllers/retrieve.pyindex a4d9c8e..d19080b 100644--- a/src/services/api/controllers/retrieve.py+++ b/src/services/api/controllers/retrieve.py@@ -9,6 +9,7 @@ Modified By: Christian Nonis <[email protected]>"""import asyncio+import jsonfrom typing import Optionalfrom fastapi import HTTPException@@ -389,7 +390,6 @@ async def get_context(request: GetContextRequestBody) -> GetContextResponse:elements = _entity_extractor.extract_elements(request.text)relationships = []historical_context = []- historical_context_futures = []text_context = ""def _find_vs_nodes(text: str):@@ -433,14 +433,18 @@ async def get_context(request: GetContextRequestBody) -> GetContextResponse:limit=request.historical_limit,))- historical_context = await asyncio.gather(*_futures)- historical_context = [text_chunk.text for text_chunk in historical_context]+ text_chunks, structured_data = await asyncio.gather(*_futures)+ historical_context = [text_chunk.text for text_chunk in text_chunks] + [+ json.dumps(structured_data.data)+ for structured_data in structured_data+ if len(structured_data.data.items()) > 0+ ]return historical_contextfutures.append(asyncio.to_thread(_find_vs_nodes, request.text))- historical_context_futures.append(asyncio.to_thread(_get_historical_context))for chunk in elements.tokens:futures.append(asyncio.to_thread(_find_vs_nodes, chunk["text"]))+ futures.append(_get_historical_context())await asyncio.gather(*futures)diff --git a/src/workers/tasks/ingestion.py b/src/workers/tasks/ingestion.pyindex b8fc957..4e218b4 100644--- a/src/workers/tasks/ingestion.py+++ b/src/workers/tasks/ingestion.py@@ -617,7 +617,10 @@ def ingest_structured_data(self, args: dict):vector_store_adapter.add_vectors(vectors=[vector], store="nodes")new_structured_data = StructuredData(id=uuid,- data=element.json_data,+ data={+ **(element.json_data if element.json_data else {}),+ **(element.textual_data if element.textual_data else {}),+ },types=element.types,metadata=element.metadata,brain_version=BRAIN_VERSION,