> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hydradb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Inspecting Context Relations

> See and explore relationships that create the brain for your AI. 

export const Field = ({name, type, required, recommended}) => {
  const label = required ? 'required' : recommended ? 'recommended' : null;
  const typeLabel = typeof type === 'string' ? type : null;
  const ariaParts = [name, typeLabel && `${typeLabel}`, label].filter(Boolean);
  return <span aria-label={ariaParts.join(', ')} className={label ? 'field-wrap has-field-tip' : 'field-wrap'} style={{
    position: 'relative',
    cursor: label ? 'default' : undefined
  }} tabIndex={label ? 0 : undefined}>
      <span className="field-name-row">
        <code>{name}</code>
        {required && <span className="field-req"> *</span>}
        {recommended && <span className="field-rec"> ●</span>}
      </span>
      {type && <span className="field-type">{type}</span>}
      {label && <span className="field-tip" role="tooltip">
          {label}
        </span>}
    </span>;
};

This endpoint queries entity-and-relationship triplets extracted from your ingested content.

Pass `id` to scope to a single ingested item, or omit it to return all relations in the collection. Set `type=memory` to inspect a memory's relations. Pagination handles large result sets.

<RequestExample>
  ```python Python SDK theme={"dark"}
  relations = client.context.relations(
      database="acme_corp",
      id="billing_runbook_v3",
      limit=500,
  )
  ```

  ```typescript TypeScript SDK theme={"dark"}
  const relations = await client.context.relations({
    database: "acme_corp",
    id: "billing_runbook_v3",
    limit: 500,
  });
  ```

  ```bash cURL theme={"dark"}
  curl -G 'https://api.hydradb.com/context/relations' \
    -H "Authorization: Bearer <your_api_key>" \
    -H "API-Version: 2" \
    --data-urlencode "database=acme_corp" \
    --data-urlencode "id=billing_runbook_v3" \
    --data-urlencode "limit=500"
  ```
</RequestExample>

## Query parameters

| Name                                                                     | Description                                                                                                                                                        |
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <Field name="database" type="string" required />                         | Owning database. Formerly `tenant_id`; the `tenant_id` alias is still accepted (deprecated).                                                                       |
| <Field name="id" type="string or null" />                                | When provided, returns relations for that specific source. When omitted, returns all relations across the collection. (default=`null`)                             |
| <Field name="type" type="&#x22;knowledge&#x22; or &#x22;memory&#x22;" /> | Bucket selector. Use `"memory"` when `id` belongs to a memory item. (default=`"knowledge"`)                                                                        |
| <Field name="collection" type="string or null" />                        | Collection scope. If omitted, the default collection is used. Formerly `sub_tenant_id`; the `sub_tenant_id` alias is still accepted (deprecated). (default=`null`) |
| <Field name="limit" type="integer" />                                    | Maximum relation groups to return. Range `1–10000`. (default=`5000`)                                                                                               |
| <Field name="cursor" type="number or null" />                            | Opaque pagination cursor from a previous response's `next_cursor`. (default=`null`)                                                                                |

<ResponseExample>
  ```json Success theme={"dark"}
  {
    "success": true,
    "data": {
      "relations": [
        {
          "source": {
            "name": "PaymentsWorker",
            "type": "Service",
            "namespace": "default",
            "entity_id": "entity_payments_worker",
            "identifier": null
          },
          "target": {
            "name": "OrdersDB",
            "type": "Database",
            "namespace": "default",
            "entity_id": "entity_orders_db",
            "identifier": null
          },
          "relations": [
            {
              "canonical_predicate": "DEPENDS_ON",
              "raw_predicate": "depends on",
              "context": "PaymentsWorker fetches transactions from OrdersDB during sync.",
              "confidence": 0.93,
              "temporal_details": "2026-02",
              "timestamp": "2026-05-12T08:14:00Z",
              "relationship_id": "rel_payments_orders",
              "chunk_id": "policy_main_chunk_3",
              "source_entity_id": "entity_payments_worker",
              "target_entity_id": "entity_orders_db"
            }
          ],
          "chunk_id": "policy_main_chunk_3"
        }
      ],
      "is_truncated": false,
      "next_cursor": null,
      "success": true,
      "message": "Relations retrieved successfully"
    },
    "error": null,
    "meta": {
      "request_id": "9d13aef4-02f4-4e73-8c62-4c2601d04f9d",
      "latency_ms": 12.3
    }
  }
  ```

  ```json Truncated response theme={"dark"}
  {
    "success": true,
    "data": {
      "relations": [
        {
          "source": {
            "name": "PaymentsWorker",
            "type": "Service",
            "namespace": "default",
            "entity_id": "entity_payments_worker"
          },
          "target": {
            "name": "OrdersDB",
            "type": "Database",
            "namespace": "default",
            "entity_id": "entity_orders_db"
          },
          "relations": [
            {
              "canonical_predicate": "DEPENDS_ON",
              "raw_predicate": "depends on",
              "context": "PaymentsWorker depends on OrdersDB for transaction sync.",
              "relationship_id": "rel_payments_orders",
              "confidence": 0.88
            }
          ],
          "chunk_id": "policy_main_chunk_4"
        }
      ],
      "is_truncated": true,
      "next_cursor": 0.88,
      "success": true,
      "message": "Relations retrieved successfully"
    },
    "error": null,
    "meta": {
      "request_id": "9d13aef4-02f4-4e73-8c62-4c2601d04f9d",
      "latency_ms": 12.3
    }
  }
  ```

  ```json Failure theme={"dark"}
  {
    "success": false,
    "data": null,
    "error": {
      "code": "SOURCE_NOT_FOUND",
      "message": "Source not found"
    },
    "meta": {
      "request_id": "9d13aef4-02f4-4e73-8c62-4c2601d04f9d",
      "latency_ms": 4.8
    }
  }
  ```
</ResponseExample>

## Pagination pattern

```python theme={"dark"}
all_relations = []
cursor = None

while True:
    page = client.context.relations(
        database="acme_corp",
        id="billing_runbook_v3",
        limit=1000,
        cursor=cursor,
    )
    all_relations.extend(page.relations)
    if page.next_cursor is None:
        break
    cursor = page.next_cursor
```

## Some additional notes

<Info>
  **Cursor opacity.** `next_cursor` is opaque (currently a numeric score). Don't construct it client-side or assume meaning  -  pass back exactly what the server returned.
</Info>

* **Collection-wide queries:** Omitting `id` returns relations across the entire collection. This is useful for full-graph exports; pair with a small `limit` and paginate.
* **Knowledge vs memory:** If the `id` belongs to a memory, set `type=memory`; otherwise the endpoint searches the Knowledge graph. The two graphs are completely separate.
* **Ordering:** Treat `data.relations[]` as ranked by relevance within the response. Preserve order for display or LLM context, but do not compare ordering across unrelated queries as an absolute signal.
* **Graph completeness:** Source relations only fully populate once the source's `indexing_status` reaches `completed`. Items in `graph_creation` are searchable but their relations may still be in flight.
* **`timestamp` format differs by endpoint.** On this endpoint each relation's `timestamp` is an ISO-8601 string (e.g. `2026-05-12T08:14:00Z`). The same relations surfaced as passthrough on [Query](/api-reference/v2/endpoint/query) (in `graph_context`) and [List Documents](/api-reference/v2/endpoint/list-documents) carry `timestamp` as a Unix epoch float (seconds) instead. Normalize before comparing relation timestamps across endpoints.

<div className="api-before-related-resources" />

<Tip>
  **Related Resources**

  * **Indexing status:** [Ingestion Status](/api-reference/v2/endpoint/source-status) - confirm the graph is complete
  * **Query with graph context:** [Query](/api-reference/v2/endpoint/query) with `graph_context: true`
  * **Concepts:** [Concepts → Context Graphs](/essentials/v2/context-graphs)
</Tip>


## OpenAPI

````yaml api-reference/v2/openapi.json GET /context/relations
openapi: 3.1.0
info:
  contact:
    email: support@hydradb.com
    name: HydraDB Support
  description: >-
    HydraDB Application API — knowledge ingestion, search, and memory
    management.
  license:
    name: Proprietary
  title: HydraDB Application API
  version: 0.1.0
servers:
  - description: Production server
    url: https://api.hydradb.com
security: []
externalDocs:
  description: ''
  url: ''
paths:
  /context/relations:
    get:
      tags:
        - context
      summary: Get graph relations
      description: Return knowledge-graph relations for a tenant or a single source.
      parameters:
        - description: Database (canonical name for the tenant scope)
          in: query
          name: database
          required: true
          schema:
            example: acme_corp
            type: string
        - description: Collection (canonical name for the sub-tenant scope)
          in: query
          name: collection
          schema:
            example: team_docs
            type: string
        - description: Deprecated alias for database
          in: query
          name: tenant_id
          schema:
            deprecated: true
            example: tenant_1234
            type: string
            x-deprecated: 'true'
        - description: Deprecated alias for collection
          in: query
          name: sub_tenant_id
          schema:
            deprecated: true
            example: sub_tenant_4567
            type: string
            x-deprecated: 'true'
        - description: Source ID (omit for database-wide relations)
          in: query
          name: id
          schema:
            example: HydraDoc1234
            type: string
        - description: 'Corpus type: ''knowledge'' or ''memory'''
          in: query
          name: type
          schema:
            enum:
              - knowledge
              - memory
            type: string
        - description: Max relations to return
          in: query
          name: limit
          schema:
            default: 5000
            type: integer
        - description: Pagination cursor
          in: query
          name: cursor
          schema:
            type: number
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/handler.Envelope-graph_GraphRelationsResponse
          description: OK
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/handler.ErrorResponse'
          description: Bad Request
      security:
        - BearerAuth: []
components:
  schemas:
    handler.Envelope-graph_GraphRelationsResponse:
      properties:
        data:
          $ref: '#/components/schemas/graph.GraphRelationsResponse'
          example:
            is_truncated: false
            message: Success
            next_cursor: 0.5
            relations:
              - chunk_id: HydraEmbeddings123_0
                relations:
                  - canonical_predicate: works_at
                    chunk_id: HydraEmbeddings123_0
                    confidence: 0.92
                    context: Ada joined Acme Corp in 2024 as a staff engineer.
                    raw_predicate: is employed by
                    relationship_id: rel_1234
                    source_entity_id: entity_1a2b
                    target_entity_id: entity_3c4d
                    temporal_details: since 2024
                    timestamp: '2026-07-02T10:00:00Z'
                source:
                  entity_id: entity_1a2b
                  identifier: Acme Corp
                  name: general
                  namespace: organization
                  provider: slack
                  type: knowledge
                target:
                  entity_id: entity_1a2b
                  identifier: Acme Corp
                  name: general
                  namespace: organization
                  provider: slack
                  type: knowledge
            success: true
        error:
          $ref: '#/components/schemas/handler.apiError'
          description: Error message, empty string on success.
          example:
            code: DATABASE_NOT_FOUND
            message: Database not found
        meta:
          $ref: '#/components/schemas/handler.responseMeta'
          example:
            collection: team_docs
            database: acme_corp
            latency_ms: 12.3
            request_id: 9d13aef4-02f4-4e73-8c62-4c2601d04f9d
            source_type: file
            sub_tenant_id: sub_tenant_4567
            tenant_id: tenant_1234
        success:
          description: Whether the request succeeded.
          example: true
          type: boolean
      type: object
    handler.ErrorResponse:
      properties:
        detail:
          $ref: '#/components/schemas/handler.ErrorDetail'
          description: Structured error detail with code, message, and deprecation hints.
          example:
            deprecated: true
            deprecated_field: tenant_id
            error_code: VALIDATION_ERROR
            message: Request validation failed
            preferred_field: database
            success: true
      type: object
    graph.GraphRelationsResponse:
      properties:
        is_truncated:
          description: Whether the response was truncated due to the result limit.
          example: false
          type: boolean
        message:
          description: Human-readable result message.
          example: Success
          type: string
        next_cursor:
          description: NO omitempty
          example: 0.5
          type: number
        relations:
          description: Array of triplet groups with evidence for each relationship.
          example:
            - chunk_id: HydraEmbeddings123_0
              relations:
                - canonical_predicate: works_at
                  chunk_id: HydraEmbeddings123_0
                  confidence: 0.92
                  context: Ada joined Acme Corp in 2024 as a staff engineer.
                  raw_predicate: is employed by
                  relationship_id: rel_1234
                  source_entity_id: entity_1a2b
                  target_entity_id: entity_3c4d
                  temporal_details: since 2024
                  timestamp: '2026-07-02T10:00:00Z'
              source:
                entity_id: entity_1a2b
                identifier: Acme Corp
                name: general
                namespace: organization
                provider: slack
                type: knowledge
              target:
                entity_id: entity_1a2b
                identifier: Acme Corp
                name: general
                namespace: organization
                provider: slack
                type: knowledge
          items:
            $ref: '#/components/schemas/graph.TripletWithEvidence'
          type: array
          uniqueItems: false
        success:
          description: Whether the request succeeded.
          example: true
          type: boolean
      type: object
    handler.apiError:
      properties:
        code:
          description: Machine-readable error code (e.g. `DATABASE_NOT_FOUND`).
          example: DATABASE_NOT_FOUND
          type: string
        message:
          description: Human-readable description of the error.
          example: Database not found
          type: string
      type: object
    handler.responseMeta:
      properties:
        collection:
          description: >-
            Collection scope. Defaults to the default collection when omitted.
            Formerly `sub_tenant_id`; the `sub_tenant_id` alias is still
            accepted (deprecated).
          example: team_docs
          type: string
        database:
          description: >-
            Owning database. Formerly `tenant_id`; the `tenant_id` alias is
            still accepted (deprecated).
          example: acme_corp
          type: string
        deprecation:
          description: >-
            Deprecation lists any migration nudges that apply to this request —
            the

            caller used a legacy /tenants route, a legacy
            tenant_id/sub_tenant_id field,

            or the deprecated sub_tenant_ids selector. It is a non-breaking
            signal (the

            status code is unchanged); omitempty keeps it absent for
            fully-migrated

            requests. A list so independent deprecations coexist without
            clobbering.
          items:
            $ref: '#/components/schemas/handler.deprecationNotice'
          type: array
          uniqueItems: false
        latency_ms:
          description: Server-side processing time in milliseconds.
          example: 12.3
          type: number
        request_id:
          description: Unique identifier for this request, useful for support and tracing.
          example: 9d13aef4-02f4-4e73-8c62-4c2601d04f9d
          type: string
        source_type:
          description: Type of the parent source (e.g. `file`, `slack`, `notion`).
          example: file
          type: string
        sub_tenant_id:
          deprecated: true
          example: sub_tenant_4567
          type: string
          x-deprecated: 'true'
        tenant_id:
          deprecated: true
          example: tenant_1234
          type: string
          x-deprecated: 'true'
      type: object
    handler.ErrorDetail:
      properties:
        deprecated:
          description: Whether this response concerns a deprecated field or route.
          example: true
          type: boolean
        deprecated_field:
          description: The deprecated field name.
          example: tenant_id
          type: string
        error_code:
          description: Machine-readable error classification code.
          example: VALIDATION_ERROR
          type: string
        message:
          description: Human-readable description of the error.
          example: Request validation failed
          type: string
        preferred_field:
          description: The canonical replacement for the deprecated field.
          example: database
          type: string
        success:
          description: Always false for error responses.
          example: true
          type: boolean
      type: object
    graph.TripletWithEvidence:
      properties:
        chunk_id:
          description: Chunk that provides evidence for this relation.
          example: HydraEmbeddings123_0
          type: string
        relations:
          description: Evidence entries for this relationship triplet.
          example:
            - canonical_predicate: works_at
              chunk_id: HydraEmbeddings123_0
              confidence: 0.92
              context: Ada joined Acme Corp in 2024 as a staff engineer.
              raw_predicate: is employed by
              relationship_id: rel_1234
              source_entity_id: entity_1a2b
              target_entity_id: entity_3c4d
              temporal_details: since 2024
              timestamp: '2026-07-02T10:00:00Z'
          items:
            $ref: '#/components/schemas/graph.RelationEvidence'
          type: array
          uniqueItems: false
        source:
          $ref: '#/components/schemas/graph.Entity'
          example:
            entity_id: entity_1a2b
            identifier: Acme Corp
            name: general
            namespace: organization
            provider: slack
            type: knowledge
        target:
          $ref: '#/components/schemas/graph.Entity'
          example:
            entity_id: entity_1a2b
            identifier: Acme Corp
            name: general
            namespace: organization
            provider: slack
            type: knowledge
      type: object
    handler.deprecationNotice:
      properties:
        deprecated:
          description: Whether this response concerns a deprecated field or route.
          example: true
          type: boolean
        deprecated_field:
          description: The deprecated field name.
          example: tenant_id
          type: string
        deprecated_since:
          description: API version when the field was deprecated.
          example: 2.0.1
          type: string
        message:
          description: Migration guidance message.
          example: tenant_id is deprecated; use database instead.
          type: string
        preferred_field:
          description: The canonical replacement for the deprecated field.
          example: database
          type: string
      type: object
    graph.RelationEvidence:
      properties:
        canonical_predicate:
          description: >-
            Normalized predicate for the relationship (e.g. `works_at`,
            `depends_on`).
          example: works_at
          type: string
        chunk_id:
          description: NO omitempty
          example: HydraEmbeddings123_0
          type: string
        confidence:
          description: Confidence score, from 0 to 1.
          example: 0.92
          type: number
        context:
          description: Verbatim passage from the source that evidences the relationship.
          example: Ada joined Acme Corp in 2024 as a staff engineer.
          type: string
        raw_predicate:
          description: As-extracted predicate before normalization.
          example: is employed by
          type: string
        relationship_id:
          description: Unique identifier for this relationship instance.
          example: rel_1234
          type: string
        source_entity_id:
          description: NO omitempty
          example: entity_1a2b
          type: string
        target_entity_id:
          description: NO omitempty
          example: entity_3c4d
          type: string
        temporal_details:
          description: NO omitempty
          example: since 2024
          type: string
        timestamp:
          description: RFC3339 timestamp associated with this item.
          example: '2026-07-02T10:00:00Z'
          type: string
      type: object
    graph.Entity:
      properties:
        entity_id:
          description: Unique identifier for this entity in the graph.
          example: entity_1a2b
          type: string
        identifier:
          description: NO omitempty — serialize as null
          example: Acme Corp
          type: string
        name:
          description: Human-readable label for this resource.
          example: general
          type: string
        namespace:
          description: Namespace grouping for the entity (e.g. `organization`, `person`).
          example: organization
          type: string
        provider:
          description: >-
            Provider is the source app the entity's evidence chunk came from
            (e.g.

            "slack", "google", "intercom"), read from the owning Source node's

            app_provider. Empty string when the evidence has no app source
            (plain

            document / web ingest). Consumed by the dashboard to render a
            connector

            logo inside the graph node.
          example: slack
          type: string
        type:
          description: Entity type label (e.g. `knowledge`, `person`, `organization`).
          example: knowledge
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: API key
      description: 'API key sent as a Bearer token: "Bearer prefix.secret"'
      scheme: bearer
      type: http

````