Adapters¶
Everything above the graph, PPR, beam search, aggregation, works against an abstract view of your data called a graph accessor. An adapter is a concrete implementation of that view for a particular backend. ArangoDB is the reference adapter, supplied to OdinEngine through ArangoBackend, but the interface is deliberately backend-agnostic, so the community can connect Odin to other knowledge graphs.
The accessor interface¶
An adapter implements the GraphAccessor protocol from retrieval.adapters. It is only a handful of methods:
from typing import Dict, Iterable, Optional, Tuple, List
from retrieval.adapters import GraphAccessor, NodeId, RelId
class MyAccessor(GraphAccessor):
def iter_out(self, node: NodeId) -> Iterable[Tuple[NodeId, RelId, float]]:
"""Yield (neighbor, relation, weight) for each outgoing edge."""
...
def iter_in(self, node: NodeId) -> Iterable[Tuple[NodeId, RelId, float]]:
"""Yield (neighbor, relation, weight) for each incoming edge."""
...
def iter_out_edges(self, node: NodeId) -> Iterable[Dict[str, object]]:
"""Yield one edge record per outgoing edge (see below)."""
...
def nodes(self, community_id: str) -> Iterable[NodeId]:
"""All node IDs in this community."""
...
def degree(self, node: NodeId) -> int:
"""Out-degree of a node."""
...
def community_seed_norm(self, community_id: str, seeds: List[NodeId]) -> List[NodeId]:
"""Implement explicitly; return seeds unchanged if IDs need no mapping."""
return seeds
def get_node(self, node_id: NodeId, fields: Optional[List[str]] = None) -> Dict[str, object]:
"""Return node properties, or an empty dict when the node is absent."""
...
If your backend can traverse both directions, enumerate nodes, and read node properties, it can drive Odin. The engine validates all seven methods at construction and raises BackendConfigurationError if one is missing.
Edge records¶
iter_out_edges(node) yields one dictionary per outgoing edge, with the exact stored assertion. These keys are required:
| Key | Meaning |
|---|---|
_id |
Stable, unique identity of the edge |
u |
Source node ID (the node argument) |
rel |
Exact relation label |
v |
Target node ID |
weight |
Numeric structural weight (1.0 if your backend has none) |
These keys are optional metadata, and may be None or omitted when your backend does not have them: created_at, valid_from, valid_to, status, and provenance. ArangoCommunityAccessor also returns source_confidence, npll_posterior, and calibration, and puts the raw stored document under provenance["assertion"]. iter_out and iter_out_edges must describe the same edges. Everything the engine needs, PPR, beam search, aggregation, and neighbor inspection, is expressed in terms of these methods.
Adapters that ship with Odin¶
| Adapter | Backend | Notes |
|---|---|---|
ArangoCommunityAccessor |
ArangoDB | The reference adapter. Rich edges (weights, timestamps, provenance), community mapping, and the backend OdinEngine uses. |
JanusGraphAccessor |
JanusGraph | Retrieval only: no engine backend, training, or schema inspection. Runs over a Gremlin traversal source; validated against JanusGraph 1.x with the GraphSON v3 serializer. |
KGCommunityAccessor |
In-memory KnowledgeGraph |
For a pre-sliced community held in memory. |
OverlayAccessor |
Any accessor | Wraps a base accessor and adds soft overlay edges on top. |
Because JanusGraph speaks Gremlin, JanusGraphAccessor is also a starting point for other Gremlin-compatible stores such as Amazon Neptune — those targets are untested, so validate before relying on them.
Using a non-Arango adapter¶
An accessor handles graph reads; a backend supplies that accessor to the engine. Here is a complete retrieval-only example requiring no database driver:
from odin import OdinEngine
from npll.core.knowledge_graph import KnowledgeGraph
from retrieval.adapters import KGCommunityAccessor
graph = KnowledgeGraph()
graph.add_known_fact("A", "linked_to", "B")
class InMemoryBackend:
def accessor(self, community_id, community_mode):
if community_mode != "none":
raise ValueError("This example supports global retrieval only")
return KGCommunityAccessor(graph, community_id)
engine = OdinEngine(InMemoryBackend(), auto_train=False)
print(engine.get_neighbors("A"))
OdinEngine accepts a backend instead of a raw database handle. To drive Odin with a retrieval-only backend, either pass it with auto_train=False or compose the retrieval orchestrator directly with your accessor:
Install the Gremlin driver before importing its backend module:
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.driver.serializer import GraphSONSerializersV3d0
from gremlin_python.process.anonymous_traversal import traversal
from retrieval.orchestrator import RetrievalOrchestrator, OrchestratorParams
from retrieval.confidence import ConstantConfidence
from retrieval.adapters_janus import JanusGraphAccessor
# GraphSON v3 serializer: newer gremlinpython clients default to GraphBinary,
# which JanusGraph 1.x (TinkerPop 3.7) servers reject.
conn = DriverRemoteConnection(
"ws://localhost:8182/gremlin", "g",
message_serializer=GraphSONSerializersV3d0(),
)
g = traversal().with_remote(conn)
accessor = JanusGraphAccessor(g)
orchestrator = RetrievalOrchestrator(
accessor=accessor,
edge_confidence=ConstantConfidence(0.8), # see note on NPLL below
)
result = orchestrator.retrieve(
seeds=["v_123"],
params=OrchestratorParams(
community_id="global",
max_paths=50,
hop_limit=3,
beam_width=64,
),
)
The result has the same shape documented in the Result Schema.
NPLL and non-Arango backends
The training lifecycle is backend-neutral. ArangoBackend is currently the
supplied implementation of both TripleSource and ModelStore. A custom
backend can supply those capabilities to enable engine-managed training.
Without them, use auto_train=False, or compose the orchestrator with your
own confidence provider. See the backend contracts.
Caching your adapter¶
Wrap any accessor in CachedGraphAccessor to get the same LRU caching OdinEngine uses (see Caching):
from retrieval.cache import CachedGraphAccessor
accessor = CachedGraphAccessor(JanusGraphAccessor(g), cache_size=5000)
Writing your own¶
To add a backend, implement all seven GraphAccessor methods. iter_out and iter_out_edges are the workhorses: given a node, return its outgoing edges as (neighbor, relation, weight) tuples and as full edge records. The shipped JanusGraphAccessor and ArangoCommunityAccessor are the best worked references. New adapters, Neo4j, Neptune, or anything else, are welcome as contributions.
Next¶
- Data Model covers what Odin expects from the graph itself.
- Connecting ArangoDB is the practical setup for the reference backend.