Base API Reference¶
Abstract base classes defining the knowledge provider interface.
KnowledgeProvider¶
KnowledgeProvider
¶
Abstract interface for all knowledge sources.
This is the base class that all knowledge providers must implement. Knowledge providers can be LLM-based, rule-based, human-input based, or any other source of causal knowledge.
The primary method is query_edge() which asks about the causal
relationship between two variables.
Example
class MyKnowledgeProvider(KnowledgeProvider): ... def query_edge(self, node_a, node_b, context=None): ... # Implementation here ... return EdgeKnowledge(exists=True, confidence=0.8, ...) ... provider = MyKnowledgeProvider() result = provider.query_edge("smoking", "cancer")
Methods:
-
query_edge–Query whether a causal edge exists between two nodes.
-
query_edges–Query multiple edges at once.
Attributes:
-
name(str) –Return the name of this knowledge provider.
name
property
¶
Return the name of this knowledge provider.
Returns:
-
str–Class name by default. Subclasses may override.
query_edge
abstractmethod
¶
query_edge(node_a: str, node_b: str, context: Optional[dict] = None) -> EdgeKnowledge
Query whether a causal edge exists between two nodes.
Parameters:
-
(node_a¶str) –Name of the first variable.
-
(node_b¶str) –Name of the second variable.
-
(context¶Optional[dict], default:None) –Optional context dictionary that may include: - domain: The domain (e.g., "medicine", "economics") - descriptions: Dict mapping variable names to descriptions - additional_info: Any other relevant context
Returns:
-
EdgeKnowledge–EdgeKnowledge with: - exists: True, False, or None (uncertain) - direction: "a_to_b", "b_to_a", "undirected", or None - confidence: 0.0 to 1.0 - reasoning: Human-readable explanation - model: Source identifier (optional)
Raises:
-
NotImplementedError–If not implemented by subclass.
query_edges
¶
query_edges(
edges: list[tuple[str, str]], context: Optional[dict] = None
) -> list[EdgeKnowledge]
Query multiple edges at once.
Default implementation calls query_edge for each pair. Subclasses may override for batch optimization.
Parameters:
-
(edges¶list[tuple[str, str]]) –List of (node_a, node_b) tuples to query.
-
(context¶Optional[dict], default:None) –Optional context dictionary (shared across all queries).
Returns:
-
list[EdgeKnowledge]–List of EdgeKnowledge results, one per edge pair.