Skip to content

Getting Started

Upgrading from 0.3.0

The engine now takes an explicit backend. See the migration guide when updating existing code.

This guide takes you from a fresh Python environment to your first scored retrieval, and then to the two other things you will do most often: scoring a single edge and finding the important nodes.


Requirements

Odin needs Python 3.9+ and a graph backend. This guide uses ArangoDB 3.10 or later. NPLL training runs in your Python process; ArangoBackend reads the graph and persists the resulting model artifact in ArangoDB.

Dependency Why
Python ≥ 3.9 Runtime
ArangoDB ≥ 3.10 Stores your knowledge graph and Odin's learned NPLL weights
PyTorch ≥ 2.0 Powers the NPLL edge-plausibility model

The core package includes PyTorch, NumPy, scikit-learn, and the retrieval dependencies. Install the arango extra to use the reference backend.


Installation

pip install "odin-engine[arango]"
pip install -e ".[arango]"
pip install -e ".[dev]"   # pytest, flake8, bandit

Import name

The package is published as odin-engine, but you import it as odin:

from odin import OdinEngine, inspect_schema

Start ArangoDB

If you do not already have a graph database, the fastest way to get one locally is Docker:

docker run -d --name arango -p 8529:8529 \
  -e ARANGO_NO_AUTH=1 arangodb:3.12

This exposes ArangoDB on http://localhost:8529 with authentication disabled, which is fine for local development but never for production. See Connecting ArangoDB for authenticated setups.


Load a small sample graph

Odin reads a graph you already have; it does not create one. If you have none, this creates the CaseRecords / EvidenceLinks graph used in the rest of this guide:

from arango import ArangoClient

client = ArangoClient(hosts="http://localhost:8529")
sys_db = client.db("_system", username="root", password="")
if not sys_db.has_database("my_graph"):
    sys_db.create_database("my_graph")
db = client.db("my_graph", username="root", password="")

nodes = db.create_collection("CaseRecords")
edges = db.create_collection("EvidenceLinks", edge=True)

nodes.import_bulk([
    {"_key": "claim_123", "record_type": "claim"},
    {"_key": "patient_001", "record_type": "person"},
    {"_key": "doctor_smith", "record_type": "person"},
    {"_key": "provider_456", "record_type": "provider"},
])
edges.import_bulk([
    {"_from": "CaseRecords/claim_123", "_to": "CaseRecords/patient_001", "predicate": "submitted_by"},
    {"_from": "CaseRecords/claim_123", "_to": "CaseRecords/provider_456", "predicate": "billed_by"},
    {"_from": "CaseRecords/patient_001", "_to": "CaseRecords/doctor_smith", "predicate": "treated_by"},
])

This graph only illustrates the shape Odin expects and is too small to judge scores. Training can still fail or produce uninformative scores on a graph this size; use OdinEngine(backend, auto_train=False) for a quick structural check, or your own graph for real results. Only the mapping in the next section changes.


Connect and initialize

from arango import ArangoClient
from odin import OdinEngine
from odin.backends.arango import ArangoBackend, ArangoGraphConfig

client = ArangoClient(hosts="http://localhost:8529")
db = client.db("my_graph", username="root", password="")

graph = ArangoGraphConfig(
    node_collection="CaseRecords",
    edge_collection="EvidenceLinks",
    relation_field="predicate",
    entity_type_field="record_type",
)
backend = ArangoBackend(db, graph)
engine = OdinEngine(backend, community_id="global")

On the first initialization against a graph, Odin extracts edge patterns and trains its NPLL model (cost depends on graph size and hardware). It then stores the learned weights in an ArangoDB collection, so subsequent runs load learned state without training. See Model Lifecycle.

Explicit retrieval-only operation

Use OdinEngine(backend, auto_train=False) to retrieve with constant confidence without training. Requested training that fails, including on an empty graph, raises an error instead of changing scoring modes.


Run your first retrieval

result = engine.retrieve(
    seeds=["CaseRecords/claim_123"],
    max_paths=50,
    hop_limit=3,
)

print(f"Triage score: {result['triage']['score']}/100")
print(f"Paths found:  {len(result['paths'])}")

for p in result["paths"][:5]:
    edges = p["edges"]
    nodes = [edges[0]["u"], *(e["v"] for e in edges)] if edges else []
    print(f"  [{p['score']:.2f}]", " -> ".join(str(n) for n in nodes))

retrieve() runs the full pipeline (PPR → Beam Search → NPLL scoring → aggregation) and returns a dictionary of ranked paths, motifs, and scores. The full shape is documented in the Result Schema.

Whole-path retrieval is the main event, but the same engine gives you two more focused tools that are worth knowing from day one.


Score a single edge

Sometimes you do not want a path, just a plausibility score for one relationship. score_edge() answers exactly that:

score = engine.score_edge("CaseRecords/patient_001", "treated_by", "CaseRecords/doctor_smith")
print(score)   # 0.0 … 1.0: learned plausibility, not a calibrated probability

It is the same NPLL signal Odin uses internally, exposed so you can drop it straight into an agent's decision logic. See Scoring Edges.


Find the important nodes

And when you are not sure where to start, ask which nodes matter most around a seed:

anchors = engine.find_anchors(seeds=["CaseRecords/claim_123"], topn=20)
for node_id, ppr_score in anchors[:10]:
    print(f"{ppr_score:.4f}  {node_id}")

find_anchors() returns the top nodes by Personalized PageRank relative to your seeds, a fast way to orient before you retrieve. See Finding Anchors.


Next steps

  • Connecting ArangoDB

    Authenticated connections, communities, and data layout.

    Read more →

  • Architecture

    How the retrieval pipeline is assembled.

    Read more →

  • AI Agent Integration

    Put Odin inside an agent's reasoning loop.

    Read more →

  • Tuning Retrieval

    Beam width, hop limits, and path budgets.

    Read more →