Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

refactor: standardize context module with comprehensive documentation

KaifAhmad1a0581a2e195a
diff --git a/semantica/context/__init__.py b/semantica/context/__init__.py
index f6f836f4..833401c7 100644
--- a/semantica/context/__init__.py
+++ b/semantica/context/__init__.py
@@ -1,15 +1,36 @@
"""
Context Engineering Module
-This module provides context engineering infrastructure for agents,
-formalizing context as a graph of connections to enable meaningful
-agent understanding and memory.
+This module provides comprehensive context engineering infrastructure for agents,
+formalizing context as a graph of connections to enable meaningful agent
+understanding and memory. It integrates RAG with knowledge graphs to provide
+persistent context for intelligent agents.
-Context engineering layers:
-- Prompting: Natural-language programming for agent goals
-- Memory: RAG with vector databases for context retrieval
-- Tools: MCP servers for consistent tool access
-- Graphs: Knowledge graphs for formalized context as connections
+Key Features:
+ - Context graph construction from entities and relationships
+ - Agent memory management with RAG integration
+ - Entity linking across sources with URI assignment
+ - Hybrid context retrieval (vector + graph + memory)
+ - Conversation history management
+ - Context accumulation and synthesis
+ - Graph-based context traversal and querying
+
+Main Classes:
+ - ContextGraphBuilder: Builds context graphs from various sources
+ - AgentMemory: Manages persistent agent memory with RAG
+ - EntityLinker: Links entities across sources with URIs
+ - ContextRetriever: Retrieves relevant context from multiple sources
+
+Example Usage:
+ >>> from semantica.context import ContextGraphBuilder, AgentMemory
+ >>> builder = ContextGraphBuilder()
+ >>> graph = builder.build_from_entities_and_relationships(entities, relationships)
+ >>> memory = AgentMemory(vector_store=vs, knowledge_graph=kg)
+ >>> memory_id = memory.store("User asked about Python", metadata={"type": "conversation"})
+ >>> results = memory.retrieve("Python", max_results=5)
+
+Author: Semantica Contributors
+License: MIT
"""
from .context_graph import ContextGraphBuilder, ContextNode, ContextEdge
diff --git a/semantica/context/agent_memory.py b/semantica/context/agent_memory.py
index 2e80114a..563b690b 100644
--- a/semantica/context/agent_memory.py
+++ b/semantica/context/agent_memory.py
@@ -1,8 +1,33 @@
"""
Agent Memory Manager
-Manages agent memory and context retrieval, integrating RAG
-with knowledge graphs to give agents persistent context.
+This module provides comprehensive agent memory management and context retrieval,
+integrating RAG (Retrieval-Augmented Generation) with knowledge graphs to give
+agents persistent context across conversations and interactions.
+
+Key Features:
+ - Persistent memory storage for agents
+ - Vector-based context retrieval
+ - Knowledge graph context integration
+ - Conversation history management
+ - Context accumulation over time
+ - Memory retrieval for agent decision-making
+ - Retention policy management
+ - Memory statistics and analytics
+
+Main Classes:
+ - MemoryItem: Memory item data structure
+ - AgentMemory: Agent memory manager with RAG integration
+
+Example Usage:
+ >>> from semantica.context import AgentMemory
+ >>> memory = AgentMemory(vector_store=vs, knowledge_graph=kg)
+ >>> memory_id = memory.store("User asked about Python", metadata={"type": "conversation"})
+ >>> results = memory.retrieve("Python", max_results=5)
+ >>> history = memory.get_conversation_history(conversation_id="conv_123")
+
+Author: Semantica Contributors
+License: MIT
"""
from typing import Any, Dict, List, Optional, Union
diff --git a/semantica/context/context_graph.py b/semantica/context/context_graph.py
index f7306e53..ca58b906 100644
--- a/semantica/context/context_graph.py
+++ b/semantica/context/context_graph.py
@@ -1,8 +1,36 @@
"""
-Context Graph Builder for Semantica framework.
+Context Graph Builder
-Formalizes context as a graph of connections, turning context
-from intuition into infrastructure. Context is connection.
+This module provides comprehensive context graph construction capabilities,
+formalizing context as a graph of connections. It turns context from intuition
+into infrastructure, enabling meaningful connections between concepts, entities,
+and conversations.
+
+Key Features:
+ - Builds context graphs from entities and relationships
+ - Creates meaningful connections between concepts
+ - Assigns URLs/URIs to entities for web-like context
+ - Formalizes context into graph structure
+ - Supports ontology-based context graphs
+ - Enables context traversal and querying
+ - Conversation-based graph construction
+ - Intent and sentiment extraction
+
+Main Classes:
+ - ContextNode: Context graph node data structure
+ - ContextEdge: Context graph edge data structure
+ - ContextGraphBuilder: Context graph builder for formalizing context
+
+Example Usage:
+ >>> from semantica.context import ContextGraphBuilder
+ >>> builder = ContextGraphBuilder()
+ >>> graph = builder.build_from_entities_and_relationships(entities, relationships)
+ >>> builder.add_node("node1", "entity", "Python programming")
+ >>> builder.add_edge("node1", "node2", "related_to", weight=0.9)
+ >>> neighbors = builder.get_neighbors("node1", max_hops=2)
+
+Author: Semantica Contributors
+License: MIT
"""
from typing import Any, Dict, List, Optional, Set, Union
diff --git a/semantica/context/context_retriever.py b/semantica/context/context_retriever.py
index 9208b0b1..7690889d 100644
--- a/semantica/context/context_retriever.py
+++ b/semantica/context/context_retriever.py
@@ -1,8 +1,34 @@
"""
Context Retriever for Agents
-Retrieves relevant context for agents from memory, knowledge graphs,
-and vector stores to inform decision-making.
+This module provides comprehensive context retrieval capabilities for agents,
+retrieving relevant context from memory, knowledge graphs, and vector stores
+to inform decision-making. It supports hybrid retrieval combining multiple
+sources for optimal context relevance.
+
+Key Features:
+ - Retrieve context from multiple sources (memory, graph, vector)
+ - Hybrid retrieval (vector + graph + memory)
+ - Context relevance ranking
+ - Context aggregation and synthesis
+ - Ontology-aware context retrieval
+ - Real-time context updates
+ - Graph expansion for related entities
+ - Multi-hop relationship traversal
+
+Main Classes:
+ - RetrievedContext: Retrieved context item data structure
+ - ContextRetriever: Context retriever for hybrid retrieval
+
+Example Usage:
+ >>> from semantica.context import ContextRetriever
+ >>> retriever = ContextRetriever(memory_store=mem, knowledge_graph=kg, vector_store=vs)
+ >>> results = retriever.retrieve("Python programming", max_results=5)
+ >>> for result in results:
+ ... print(result.content, result.score)
+
+Author: Semantica Contributors
+License: MIT
"""
from typing import Any, Dict, List, Optional
diff --git a/semantica/context/entity_linker.py b/semantica/context/entity_linker.py
index 7bc02090..edc5ba98 100644
--- a/semantica/context/entity_linker.py
+++ b/semantica/context/entity_linker.py
@@ -1,8 +1,35 @@
"""
Entity Linker for Context Engineering
-Links entities across sources to build the web of context,
-assigning each entity a URL and connecting them meaningfully.
+This module provides comprehensive entity linking capabilities for context
+engineering, linking entities across different sources to build the web of
+context. It assigns each entity a unique URL/URI and connects them meaningfully
+to enable semantic understanding.
+
+Key Features:
+ - Links entities across different sources
+ - Assigns unique identifiers (URLs/URIs) to entities
+ - Creates semantic connections between entities
+ - Builds entity connection web
+ - Supports cross-document entity linking
+ - Enables entity disambiguation and resolution
+ - Similarity-based entity matching
+ - Bidirectional entity linking
+
+Main Classes:
+ - EntityLink: Entity link data structure
+ - LinkedEntity: Linked entity with context
+ - EntityLinker: Entity linker for context engineering
+
+Example Usage:
+ >>> from semantica.context import EntityLinker
+ >>> linker = EntityLinker(knowledge_graph=kg)
+ >>> uri = linker.assign_uri("entity_1", "Python", "PROGRAMMING_LANGUAGE")
+ >>> linked_entities = linker.link("Python is a programming language", entities=entities)
+ >>> linker.link_entities("entity_1", "entity_2", "related_to", confidence=0.9)
+
+Author: Semantica Contributors
+License: MIT
"""
from typing import Any, Dict, List, Optional, Set, Tuple