OriginChainDB
Graph

Graph examples

← All examples

Declare a relationship in the schema before using these requests. Start with direct neighbors, then choose a bounded traversal, path calculation or whole-graph analysis. Several algorithms require a table that relates to itself.

Choose a graph question from real relationshipsEach recipe names its own order, social or cycle sample; load the appropriate one.
  1. Declare the relationDefine how one record links to another.
  2. Load the named sampleUse the records required by the chosen recipe.
  3. Ask a graph questionInspect direct links, paths, groups or relative scores.
  4. Read the result shapeCheck IDs, direction and traversal limits before using the result.

Follow and analyze connections

Prepare the social graph

The community and graph-learning recipes use social.users, a relation named follows, and IDs such as alice and erin. This is different from the following relation used in the profile-writing example. Use a disposable test database: do not replace an existing social.users definition.

Run this Bash setup once using your tenant-scoped connection. It creates five people and their links. The four numbers in feat are deliberately small sample features for the GraphSAGE recipe, not real user attributes.

Create and load the five sample people
curl --fail-with-body -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/schemas" \
  -H "Authorization: Bearer $OC_TOKEN" -H "Content-Type: text/plain" \
  --data-binary @- <<'TOML'
namespace = "social"
table = "users"
primary_key = ["id"]

[[columns]]
name = "id"
ty = "str"
required = true

[[columns]]
name = "follows"
ty = "list"

[[columns]]
name = "feat"
ty = "list"

[[relations]]
name = "follows"
from_col = "follows"
bidirectional = true
target = { namespace = "social", table = "users", pk = "id" }
TOML

curl --fail-with-body -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/rows/social.users/_batch" \
  -H "Authorization: Bearer $OC_TOKEN" -H "Content-Type: application/json" \
  -d '[
    {"id":"alice","follows":["bob","carol"],"feat":[1.0,0.0,0.5,0.2]},
    {"id":"bob","follows":["carol","dave"],"feat":[0.9,0.1,0.4,0.2]},
    {"id":"carol","follows":["alice","dave"],"feat":[0.8,0.2,0.6,0.1]},
    {"id":"dave","follows":["erin"],"feat":[0.1,0.9,0.2,0.8]},
    {"id":"erin","follows":[],"feat":[0.0,1.0,0.1,0.9]}
  ]'

Alice can reach Erin through Bob or Carol, then Dave. Erin has no outgoing links. This small graph helps check direction, endpoints and response shape; it is not a meaningful benchmark or a dataset for judging a trained model's quality. Scores in individual recipes illustrate their format and need not match this sample dataset.

The neighbor, reverse, BFS and path recipes use order o001, product p001, and the relation bought_product. Create this separate sample dataset in a test database. It uses o001 without an underscore; the SQL examples use different IDs.

Create one product and the order that points to it
curl --fail-with-body -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/schemas" \
  -H "Authorization: Bearer $OC_TOKEN" -H "Content-Type: text/plain" \
  --data-binary @- <<'TOML'
namespace = "shop"
table = "products"
primary_key = ["id"]
[[columns]]
name = "id"
ty = "str"
required = true
TOML

curl --fail-with-body -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/schemas" \
  -H "Authorization: Bearer $OC_TOKEN" -H "Content-Type: text/plain" \
  --data-binary @- <<'TOML'
namespace = "shop"
table = "orders"
primary_key = ["id"]
[[columns]]
name = "id"
ty = "str"
required = true
[[columns]]
name = "product_id"
ty = "str"
[[relations]]
name = "bought_product"
from_col = "product_id"
bidirectional = true
target = { namespace = "shop", table = "products", pk = "id" }
TOML

curl --fail-with-body -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/rows/shop.products" \
  -H "Authorization: Bearer $OC_TOKEN" -H "Content-Type: application/json" \
  -d '{"id":"p001"}'
curl --fail-with-body -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/rows/shop.orders" \
  -H "Authorization: Bearer $OC_TOKEN" -H "Content-Type: application/json" \
  -d '{"id":"o001","product_id":"p001"}'

The forward lookup starts at o001 and returns p001. The reverse lookup starts at p001 and returns o001. Larger response examples on the recipe pages require more rows and links.

Before adapting a recipe

Use a test database, load the named sample data, and check the expected result. Read each page’s limits before changing the query. See connection and SDK notes.

© 2026 Silicoyn Technologies Pvt Ltd

On this page