Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix: add_decision kwargs support and quickstart VectorStore backend

KaifAhmad129a608f60ee3
diff --git a/README.md b/README.md
index 5db9030d..0b0ae144 100644
--- a/README.md
+++ b/README.md
@@ -354,7 +354,7 @@ from semantica.context import AgentContext, AgentMemory
from semantica.vector_store import VectorStore
context = AgentContext(
- vector_store=VectorStore(backend="faiss", dimension=768),
+ vector_store=VectorStore(backend="inmemory"),
knowledge_graph=ContextGraph(advanced_analytics=True),
decision_tracking=True,
graph_expansion=True,
diff --git a/docs/bugs/quickstart_api_mismatch.md b/docs/bugs/quickstart_api_mismatch.md
new file mode 100644
index 00000000..ac9d6fe4
--- /dev/null
+++ b/docs/bugs/quickstart_api_mismatch.md
@@ -0,0 +1,31 @@
+---
+title: Quickstart sample code incompatible with v0.3.0 API
+labels: bug, documentation
+version: 0.3.0
+---
+
+## Bug 1 — `ContextGraph.add_decision()` rejects keyword arguments
+
+Running the README's Context & Decision Tracking sample fails immediately:
+
+```
+TypeError: ContextGraph.add_decision() got an unexpected keyword argument 'category'
+```
+
+`add_decision()` only accepted a `Decision` object, but the docs showed and described the kwargs form. Fixed by updating `add_decision()` to accept kwargs directly (delegates to `record_decision`); both call patterns now work and return the decision ID.
+
+---
+
+## Bug 2 — `VectorStore(backend="faiss")` silently drops all stored memories
+
+Running any quickstart snippet with `VectorStore(backend="faiss", dimension=768)` prints:
+
+```
+Failed to store in vector store:
+```
+
+FAISS requires `pip install faiss-cpu`, which is not included in the base install. Memories fall back to an in-memory dict silently, so `find_precedents` and similarity search return empty results. Fixed by changing all quickstart snippets to `VectorStore(backend="inmemory")`.
+
+---
+
+Reported by: chrisguoado — tracked in KaifAhmad1/semantica#433, fixed in pr-432 follow-up.
diff --git a/docs/getting-started.md b/docs/getting-started.md
index dcec03a9..deb69915 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -44,7 +44,7 @@ from semantica.context import AgentContext, ContextGraph
from semantica.vector_store import VectorStore
context = AgentContext(
- vector_store=VectorStore(backend="faiss", dimension=768),
+ vector_store=VectorStore(backend="inmemory"),
knowledge_graph=ContextGraph(advanced_analytics=True),
decision_tracking=True,
)
diff --git a/docs/index.md b/docs/index.md
index 63a0ecf7..42a2255b 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -65,7 +65,7 @@ from semantica.context import AgentContext, ContextGraph
from semantica.vector_store import VectorStore
context = AgentContext(
- vector_store=VectorStore(backend="faiss", dimension=768),
+ vector_store=VectorStore(backend="inmemory"),
knowledge_graph=ContextGraph(advanced_analytics=True),
decision_tracking=True,
)
diff --git a/docs/reference/context.md b/docs/reference/context.md
index a66cc0c7..f0d0fb74 100644
--- a/docs/reference/context.md
+++ b/docs/reference/context.md
@@ -275,7 +275,7 @@ print(f"Python importance score: {importance.get('degree', 0)}")
|--------|-------------|------------|
| `add_node(node_id, node_type, properties)` | Add concepts to remember | Build knowledge base |
| `add_edge(source, target, relation)` | Connect related concepts | Show relationships |
-| `add_decision(category, scenario, reasoning, outcome, confidence, ...)` | Record decisions | Track choices and learn |
+| `add_decision(decision)` or `add_decision(category, scenario, reasoning, outcome, ...)` | Record decisions | Track choices and learn |
| `add_decision_simple(category, scenario, reasoning, outcome, confidence, ...)` | Easy decision recording | Quick decision tracking |
| `find_precedents(decision_id, limit)` | Find precedents by ID | Get connected decisions |
| `find_precedents_by_scenario(scenario, category, ...)` | Find similar decisions | Make consistent choices |
diff --git a/semantica/context/context_graph.py b/semantica/context/context_graph.py
index 28ed4c11..f64db90c 100644
--- a/semantica/context/context_graph.py
+++ b/semantica/context/context_graph.py
@@ -1472,25 +1472,70 @@ class ContextGraph:
}
# Decision Support Methods
- def add_decision(self, decision: "Decision") -> None:
+ def add_decision(
+ self,
+ decision: "Decision" = None,
+ *,
+ category: str = None,
+ scenario: str = None,
+ reasoning: str = None,
+ outcome: str = None,
+ confidence: float = 0.5,
+ entities: Optional[List[str]] = None,
+ decision_maker: Optional[str] = "system",
+ **kwargs,
+ ) -> str:
"""
Add decision node to graph.
-
+
+ Accepts either a Decision object or keyword arguments:
+
+ # From a Decision object
+ graph.add_decision(Decision(category="x", scenario="y", ...))
+
+ # From keyword arguments (convenience form)
+ graph.add_decision(category="x", scenario="y", reasoning="z",
+ outcome="o", confidence=0.9)
+
Args:
- decision: Decision object to add
+ decision: Decision object to add (mutually exclusive with kwargs)
+ category: Decision category
+ scenario: Decision scenario description
+ reasoning: Reasoning behind the decision
+ outcome: Decision outcome
+ confidence: Confidence score (0.0–1.0)
+ entities: Related entity labels
+ decision_maker: Who made the decision
+ **kwargs: Extra metadata stored on the decision node
+
+ Returns:
+ Decision ID
"""
from .decision_models import Decision
-
+
+ if decision is None:
+ # Build from kwargs — delegate to record_decision which handles ID gen
+ return self.record_decision(
+ category=category,
+ scenario=scenario,
+ reasoning=reasoning,
+ outcome=outcome,
+ confidence=confidence,
+ entities=entities,
+ decision_maker=decision_maker,
+ metadata=kwargs,
+ )
+
# Handle empty decision ID by generating UUID for both None and empty string
# This ensures consistent behavior with Decision model's __post_init__ method
node_id = decision.decision_id if decision.decision_id else str(uuid.uuid4())
-
+
# Handle None metadata
metadata = decision.metadata or {}
-
+
# Normalize timestamp to ensure consistent storage format
normalized_timestamp = self._normalize_timestamp(decision.timestamp)
-
+
node = ContextNode(
node_id=node_id,
node_type="Decision",
@@ -1510,6 +1555,7 @@ class ContextGraph:
valid_until=decision.valid_until,
)
self._add_internal_node(node)
+ return node_id
def add_causal_relationship(
self,