Skip to main content
A context graph records how the things in your context relate: which team owns which service, which policy governs which process, which decision replaced which. POST /query returns the relevant part of it next to the matching passages, so your model can answer “What team owns the service that failed?” when no single passage says so. HydraDB builds the graph while it indexes your context. The named things are entities. One relationship between two of them is a triplet of source, relation, and target, such as Payments team, owns, billing service. Following relationships from one entity to the next is traversal; each step is a hop, and a question that needs two or more is multi-hop. In this guide:
  1. Get relationships with your results: the graph_context field, using a billing question as the example.
  2. Turn the graph off: when you only need chunks.
  3. Where the relationships come from: extraction, declared links, and your own graph.
  4. Walk the items around one result: the Connected Subgraph endpoint.
  5. Put graph context in your prompt.

1. Get relationships with your results

graph_context is on by default, so this is an ordinary knowledge query. It sets mode: "thinking" because thinking mode does the most graph work; in "fast" mode the graph slice is shallower.
The data payload of a response with graph context looks like this (chunks trimmed):
The full schema is on the Query API reference.

What each field in graph_context means

Empty arrays mean no relationships were found for that query. That is not an error; there is no structure to show.

2. Turn the graph off

Set graph_context: false when your code only reads chunks; the response gets smaller and the traversal is skipped. This takes effect only in "fast" mode (explicit, or "auto" routed to fast). "thinking" always includes the graph. Direct factual lookups rarely need the graph. Questions about ownership, cause and effect, sequence, or dependencies usually do, and so does anything that needs to combine information across several chunks.

3. Where the relationships come from

  • Extracted at ingestion: HydraDB reads each source, finds the entities and the relationships between them, and stores the triplets. A source is searchable at the graph_creation status; completed means its graph work is done too, which is what full traversal needs. See Knowledge.
  • Declared by you: links between whole sources that belong together but whose text does not say so, set with relations.ids at ingest. A query in thinking mode returns the linked text in additional_context. Knowledge shows how. App sources also connect through fields such as thread_id and parent_id; see App Sources.
  • Supplied by you: Bring Your Own Graph replaces extraction for a source with the entities and relations you send. They appear in graph_context alongside extracted ones, tagged origin: "byog".

4. Walk the items around one result

The graph also holds relations between items rather than between entities: a Slack reply and the message it answers, a page and the pages it links to, a comment and its ticket. Given one item’s id, Connected Subgraph follows those links, nearest items first, and returns the connected items up to the requested depth and result limit, with the relations among them: the rest of the thread, the hierarchy above and below, the items it references. Use it when one query result is not enough and you need what surrounds it. The dashboard’s Subgraph button opens the same view.

5. Put graph context in your prompt

Pass the whole query result to build_string (Python) or buildString (TypeScript). After the chunks, the helper renders each path as one line per triplet: the source entity, the predicate, the target entity, and the relation’s context sentence. It reads query_paths, chunk_relations, and chunk_id_to_group_ids for you. How to Use API Results shows the full flow.