Skip to main content

Relationships API

Connect memories with typed relationships to build knowledge graphs.

Overview

Relationships connect memories to each other, creating a traversable knowledge graph. Each relationship has a type, direction, and strength (weight) that indicates confidence.

Relationship Types: Use built-in types like supports, contradicts, references, or define custom types for your domain.

Create Relationship

Endpoint
POST /relationships/:sourceId

Creates a directed relationship from :sourceId to target_id. The relationship's natural key is (source_id, target_id, relationship_type) — the same triple cannot be created twice.

Path Parameters

FieldTypeDescription
sourceIdstring (UUID, required)Source memory UUID — the relationship points FROM this memory.

Body Parameters

FieldTypeDescription
target_idstring (UUID, required)Target memory UUID — the relationship points TO this memory.
relationship_typestring (required)The relationship type. Must be one of the enum values in RELATIONSHIP_TYPES (see Relationship Types below). Custom strings are rejected.
descriptionstringOptional human-readable explanation (max 1000 chars).
weightnumberInitial weight/strength of the relationship. Minimum 0, default 1.0.
decay_ratenumberHow fast this relationship decays over time. Range 0-1, default 0.02.
rulesobjectOptional JSON rules for when this relationship applies.
metadataobjectOptional key-value pairs for additional context.
bidirectionalbooleanOptional. If true, the API records this as a bidirectional edge (two rows). Default: false.

Response (201)

Example Response
{
  "id": "<relationship-uuid>",
  "source_id": "<source-uuid>",
  "target_id": "<target-uuid>",
  "relationship_type": "supports",
  "description": "Both describe research findings",
  "weight": 0.9,
  "usage_count": 0,
  "metadata": {
    "verified": true
  },
  "created_at": "2026-04-15T10:30:00Z",
  "updated_at": "2026-04-15T10:30:00Z"
}

List a Memory's Relationships

Endpoint
GET /relationships/:memoryId

Returns outgoing and/or incoming relationships for the given memory.

Path Parameters

FieldTypeDescription
memoryIdstring (UUID, required)Memory UUID.

Query Parameters

FieldTypeDescription
directionstringoutgoing, incoming, or both (default).
typestringFilter by relationship type (must be in the RELATIONSHIP_TYPES enum).

List related memories (graph walk)

Endpoint
GET /relationships/:memoryId/related

Returns memories reachable from :memoryId across the relationship graph, optionally filtered by type and depth.

Path Parameters

FieldTypeDescription
memoryIdstring (UUID, required)Starting memory UUID.

Update Relationship

Endpoint
PATCH /relationships/:sourceId/:targetId/:type

Updates an existing relationship identified by the (source, target, type) triple.

Path Parameters

FieldTypeDescription
sourceIdstring (UUID, required)Source memory UUID.
targetIdstring (UUID, required)Target memory UUID.
typestring (required)Relationship type — must match the existing row.

Body Parameters

FieldTypeDescription
weightnumberNew weight value (≥ 0).
descriptionstringUpdated description.
metadataobjectUpdated metadata. Merges with existing.

Response (200)

Example Response
{
  "id": "<relationship-uuid>",
  "source_id": "<source-uuid>",
  "target_id": "<target-uuid>",
  "relationship_type": "supports",
  "weight": 0.95,
  "metadata": {
    "verified": true,
    "verified_by": "<user-id>",
    "verified_at": "2026-04-20T10:00:00Z"
  },
  "updated_at": "2026-04-20T10:00:00Z"
}

Weaken Relationship

Endpoint
POST /relationships/:sourceId/:targetId/:type/weaken

Decrease the weight of a relationship (used when memories diverge in usage).

Path Parameters

FieldTypeDescription
sourceIdstring (UUID, required)Source memory UUID.
targetIdstring (UUID, required)Target memory UUID.
typestring (required)Relationship type.

Note: Relationship weights decay naturally over time without reinforcement (see the decay_rate field).

Delete Relationship

Endpoint
DELETE /relationships/:sourceId/:targetId/:type

Removes a relationship identified by the (source, target, type) triple.

Path Parameters

FieldTypeDescription
sourceIdstring (UUID, required)Source memory UUID.
targetIdstring (UUID, required)Target memory UUID.
typestring (required)Relationship type.

Response (204)

Returns no content on successful deletion.

Reinforce Relationship

Endpoint
POST /relationships/:sourceId/:targetId/:type/reinforce

Increase the weight of a relationship when both memories are used together successfully.

Path Parameters

FieldTypeDescription
sourceIdstring (UUID, required)Source memory UUID.
targetIdstring (UUID, required)Target memory UUID.
typestring (required)Relationship type.

Batch Create Relationships

Endpoint
POST /relationships/batch

Creates multiple relationships in a single request. Useful for importing knowledge graphs.

Body Parameters

FieldTypeDescription
relationshipsarray (required)Array of relationship objects. Each must include source_id, target_id, relationship_type, and may include weight, description, metadata, bidirectional.

Response (201)

Example Response
{
  "succeeded": [
    { "id": "<relationship-uuid>", "source_id": "<source-uuid>", "target_id": "<target-uuid>", "relationship_type": "supports", "weight": 0.9 },
    { "id": "<relationship-uuid>", "source_id": "<source-uuid>", "target_id": "<target2-uuid>", "relationship_type": "references", "weight": 0.7 }
  ],
  "failed": []
}

Relationship Types

Built-in relationship types and their semantics:

TypeDescriptionDirection
related_toGeneric relationship between related conceptsBidirectional
parent_ofHierarchical parent-child relationshipParent → Child
child_ofInverse of parent_ofChild → Parent
supersedesSource replaces or updates targetNew → Old
referencesSource mentions or cites targetCiting → Cited
derived_fromSource was created based on targetDerived → Original
contradictsSource conflicts with targetBidirectional
supportsSource provides evidence for targetEvidence → Claim
similar_toSemantic similarity (often auto-generated)Bidirectional
depends_onSource requires target to be validDependent → Dependency
caused_bySource is an effect of targetEffect → Cause
leads_toSource causes target (inverse of caused_by)Cause → Effect

Custom Types: You can use any string as a relationship type. Custom types are treated as directional by default.

Inverse Type Mappings

When creating bidirectional relationships, the API automatically creates an inverse relationship with the appropriate type:

TypeInverse Type
parent_ofchild_of
child_ofparent_of
supersedessuperseded_by
superseded_bysupersedes
referencesreferenced_by
referenced_byreferences
derived_fromsource_of
source_ofderived_from
depends_ondependency_of
dependency_ofdepends_on
caused_byleads_to
leads_tocaused_by
supportssupported_by
supported_bysupports
related_torelated_to (symmetric)
contradictscontradicts (symmetric)
similar_tosimilar_to (symmetric)
Bidirectional Example Response
{
  "id": "rel_x1y2z3w4v5u6",
  "source_id": "mem_abc123",
  "target_id": "mem_def456",
  "type": "supports",
  "strength": 0.9,
  "created_at": "2024-01-15T10:30:00Z",
  "inverse_relationship": {
    "id": "rel_a1b2c3d4e5f6",
    "source_id": "mem_def456",
    "target_id": "mem_abc123",
    "type": "supported_by",
    "strength": 0.9
  }
}

Relationship Object

The relationship object contains the following fields:

FieldTypeDescription
idstringUnique identifier for the relationship. Prefixed with rel_.
source_idstringThe source memory ID.
target_idstringThe target memory ID.
typestringThe relationship type.
strengthnumberConfidence/weight of the relationship (0.0 to 1.0).
metadataobjectCustom key-value pairs.
reinforcement_countintegerNumber of times this relationship has been reinforced.
created_atstringISO 8601 timestamp of when the relationship was created.
updated_atstringISO 8601 timestamp of when the relationship was last updated.
last_reinforced_atstring | nullISO 8601 timestamp of last reinforcement.