query-pattern
Choose how code reads the graph: graph-query's, graph-ingest's and graph-index's declared request verbs, the typed exact-entity reader, or an owner's bucket access. Use when a component or a consumer needs to read entities or relationships.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- query-pattern
- description
- Choose how code reads the graph: graph-query's, graph-ingest's and graph-index's declared request verbs, the typed exact-entity reader, or an owner's bucket access. Use when a component or a consumer needs to read entities or relationships.
03 SKILL.md 正文
How to read the graph
Start from the reader the user names. In this tree the graph is read seven ways, and only these.
What exists
| Way | For | What you get |
|---|---|---|
| graph-gateway's GraphQL route | Remote apps and web front ends, over HTTP: an entity, a prefix page, the entities with a predicate, the entities within reach of one | Exactly the fields the request selected, checked against the schema (gateway/graph-gateway/schema.graphql) |
output/websocket with its default applied-state input |
An application kept current as entities change, over a WebSocket on the component's own port (ADR-115); never the message logger's debug SSE watch | A put per current entity, synced, then put, delete and poisoned frames converging to each key's latest value, not every revision (output/websocket/README.md) |
graph.NewExactEntityReader |
One entity by ID, from embedded code | The validated entity and its ENTITY_STATES revision (graph.ExactEntity) |
graph-ingest's batch and prefix verbs |
Several entities by ID, or a page of entities under an ID prefix | graph.EntityBatchResponse, graph.PrefixQueryResponse |
| graph-query's verbs | One front door for application code: an entity, a batch, a prefix page, a name, the entities with a predicate, an alias, the links of an entity, the entities within reach of one, counts of a group, a summary of the graph, a keyword search inside one community | The answer of the component behind the verb; every verb but entity, batch, prefix and hierarchyStats is a graph.QueryResponse |
| graph-index's eight verbs | Relationships in or out of an entity, an alias, the entities with a predicate or a name | A graph.QueryResponse: the result in data, the revision it reflects in indexed_revision, and producer |
| Direct bucket access | The bucket's declared owner, and operator diagnostics | Raw entries; no query contract |
Every verb graph-query, graph-ingest and graph-index serve is declared once, in graph.QueryVerbs() (graph/query_verbs.go),
with its subject and its responder; the function's doc comment names each verb's request and reply types. Each
component serves exactly its own verbs. graph-index's are outgoing, incoming, alias, predicate,
predicateList, predicateStats, predicateCompound and byName, on graph.index.query.*. graph-query's, on
graph.query.*, are entity, batch, prefix, byName, predicate, entityByAlias, relationships,
pathSearch, hierarchyStats, summary, localSearch, globalSearch, searchGraph, semantic, similar, spatial
and temporal; the first five forward to
the verb of the same name behind them, and semantic, similar, spatial and temporal forward to the embedding,
spatial and
temporal verbs. spatial and temporal have no responder in the tree yet and are refused transient internal until
change 7; semantic and similar are answered by graph-embedding, or refused invalid not_enabled when graph-query's
embedding_enabled is false.
graph-query lands in steps (processor/graph-query/README.md lists what it
serves now), so a verb not in the table has no responder yet.
Choosing
- A web front end or other HTTP caller: POST a GraphQL query to graph-gateway at
/<instance>/graphql. It answersentity,entitiesByPrefix,entitiesByPredicateandpathSearchand nothing else; a field the schema does not declare is refused with HTTP 400, naming it. Its answers and errors are ingateway/graph-gateway/README.md. - A lookup an application makes: send a classified request on the matching
graph.query.*verb, read fromgraph.QueryVerbs(). Pick the verb by the table's row, not by a verb's name:entityByAliastakes{"alias": ...}and answers the entity whose alias it is, or reads the input as an entity ID;relationshipstakes{"entity_id": ..., "direction": "outgoing" or "incoming"}and the direction is required. - One entity by ID, from embedded code: use
graph.NewExactEntityReader. It is the only typed adapter so far. - Several entities, or a prefix, straight from graph-ingest: send a classified request (
RequestClassified, developer contract § NATS RPC) on the verb's subject, read fromgraph.QueryVerbs(). Never spell the subject as a literal;TestReservedSubjectsDeclaredOncefails on one outside its declaration. - Relationships, aliases, predicates or names, straight from graph-index: send a classified request on the
matching
graph.index.query.*verb, read fromgraph.QueryVerbs(). Every one of the eight refuses with transientindex_not_readyduring the index's startup rebuild and while it has lost its feed, so retry it; it refuses with fatalgraph_state_reset_requiredafter a stored entity could not be decoded, so do not retry. Compare a write'skv_revisionwith the reply'sindexed_revisionto know whether the answer includes that write, thealiasverb included. Thealiasverb also refuses with class invalid and codealias_ambiguouswhen two or more entities carry the alias; do not retry it until a holder drops the alias. - Anything else: there is no admitted read. Raw KV access and subjects are not a fallback for an application;
direct bucket access is for the declared owner (
natsclient.OpenFrameworkBucketwith the descriptor fromgraph/kvcatalog) and for operator diagnostics.
The path and count verbs
pathSearchtakesstart_entity,direction(outgoing,incomingorboth) andmax_depth(1 to 10), all required, and optionallymax_nodes(1 to 500, default 100) andpredicates. A value outside a limit is refused before any request. Its cost is requests, at most one plusmax_nodes, twice that forboth; nothing bounds elapsed time (ADR-112, "Time").truncatedis exact: true means an entity was left out. A hub whose edge list does not fit one reply refuses the whole walk withresponse_too_large, naming the entity. Narrowingpredicatescannot shrink that reply, since a hop sends onlyentity_idandmin_revisionandpredicatesfilters after it; narrowing can only avoid reaching the hub, and changingdirectionhelps only if it avoids the oversized direction.hierarchyStatsandsummaryeach read one prefix page, so each request costs one key scan of the group, and a count covers that page and no more.total_entitiesis the whole group as listed, live and not a snapshot (#512).truncatedfalse says only that this is the last page. On a first page withtruncatedtrue, the counts and examples are of the lexically smallest IDs: a sample. Sendnext_cursorascursorfor the next page.hierarchyStatsis bare.summaryrefuses when the predicate index cannot answer;exclude_predicatesasks without it, andprefixneeds it.localSearchsearches one community: the group of entities that share the first 4, 3 or 2 parts of an ID (level0, 1 or 2, default 0). It takesentity_id(a full ID in the group),query(1 to 32 distinct words) and optionallylevel. It reads the group's record fromCOMMUNITY_INDEX, then one page of the group's entities, and ranks that page by how well the words match. The page is at most 1,000 entities in ID order, so on a larger group the sample is the lexically smallest IDs,entities_truncatedis true, and a match later in the order is missed. Untilprocessor/graph-clusteringhas published its first records toCOMMUNITY_INDEXit refuses transientindex_not_ready; retry it. Itsindexed_revisionis the group record's latest entity write, so to read your own write send thekv_revisionof a write to an entity in the group you search. A revision from a write to another group can stay above the record, and the request is then refusedrevision_not_reacheduntil the searched group next changes.globalSearchtakes a free-textqueryand picks one strategy from the question's words, with no language model.searchGraphis the same handler under a second name, with the same request anddata. It answers the questions that have an exact answer, searches the rest as text overCOMMUNITY_INDEX, and refuses a question it cannot answer whole:- A question of one word is an entity reference (an alias, else a full six-part ID):
strategyentity. - "What is connected to pump-42": a path from
pump-42, both directions, 3 hops, 100 entities:path, IDs and edges only (callbatchfor states). - "What changed in the last 2 hours":
temporal. "What is within 5km of 40.7,-74.0":spatial. Until change 7 both are refused transientinternal, since their responders are not in the tree. - Two of path, time and area, an entity beside a zone or area, or an impossible number is
invalid_request. A count or other aggregation ("how many", "max retries"), and path words, a similarity or a ranking beside a start, time range or area, areinvalid_requestnaming what it cannot do. A named path start that names no entity isentity_not_found. - Everything else is the
textstrategy: a question with no hint, path words with no start ("http connection pool"), a similarity or ranking alone, a one-word name that names no entity. It reads up to five groups' records atlevel(0 to 2, default 0) that score above 0 for the words, one page of each, and replies withmatches(id,label,score,entity), thegroupsread,entities_truncatedandanswer. Matches are a sample of at most one page per group. Hints it could not apply are named inunhonoured_hints. Untilprocessor/graph-clusteringhas published its first records toCOMMUNITY_INDEXit is refused transientindex_not_ready; retry it. - Known limits of the keyword classifier (owner-accepted, #535): "from A to B" walks from A and drops B with no signal, so a successful reply does not mean both ends were honoured; "in real-time" beside a place can be refused as a second place, a loud refusal of an answerable question.
- To read a known entity, prefer
entityorentityByAlias;globalSearchis for a question you cannot route yourself.
- A question of one word is an entity reference (an alias, else a full six-part ID):
indexed_revisionof 0 on asummarywith predicates excluded claims nothing. Do not compare it with a write'skv_revisionor retry on it.
Reading a reply
Decode by the verb's row in graph.QueryVerbs(), never by looking at the bytes. QueryVerb.Enveloped says whether
the reply is a graph.QueryResponse; QueryVerb.Reply is the type of the reply, or of its data when enveloped.
Do not guess the shape from the reply's content.
graph-query's entityByAlias and relationships replies are enveloped and were bare lists or entities at the pin, and
the keys of pathSearch, hierarchyStats and summary changed, so code written against the pin must change (processor/graph-query/MIGRATION.md).
Reading your own write
Every enveloped verb takes an optional min_revision, the kv_revision of your write (graph.MinRevisionField). If
the index has not reached it, the verb refuses with transient revision_not_reached, the revision reached in the
detail, and never waits; retry it. A bare verb (entity, batch, prefix, and hierarchyStats on graph.query.*)
ignores the field: graph-ingest, which answers it, is the authority. On graph.query.*, byName, predicate,
entityByAlias, relationships, pathSearch, localSearch, globalSearch, searchGraph and summary (unless it
excludes predicates) honour it. localSearch compares it with the searched group's record, not the whole index (see above);
the text strategy of globalSearch compares it with the highest revision among the records at its level, which a
write anywhere reaches once clustering has published it.
Points that hold
- Which front door, and where its answer comes from, are separate decisions.
- The
prefixverb sorts before it pages and clamps its limit tograph.MaxPrefixQueryLimit; a caller pages with the cursor it returns. - graph-index's replies are enveloped (
graph.QueryResponse); graph-ingest's replies are not; graph-query's follow the table row for each verb. - A refusal is a classified error and carries no envelope.
graph-querypasses a refusal from the verb behind it on with its class, code and detail; a request that gets no answer is transientinternal. - The HTTP gateway (graph-gateway) answers four operations through a declared schema, never by searching the query
text; it serves no
trajectory,globalSearchor introspection (gateway/graph-gateway/MIGRATION.md). An MCP surface is not in this tree. Until a verb is in the table, do not design against it.
04 同仓库更多 Skills
semengine-status
Report SemEngine Slice 04A package port progress, active PR claims, known flakes, and GitHub milestone/issue queue hygiene, and sync the GitHub Project v2 tracker. Use when asked for port status, auditing the issue queue, or updating the project board.
review-pr
Adapter for review-pr.
query-pattern
Choose how code reads the graph: graph-ingest's declared request verbs, the typed exact-entity reader, or an owner's bucket access. Use when a component or a consumer needs to read entities.
preflight
Select and run the existing SemEngine verification gates for a concrete diff before an implementation push or local-readiness assessment.
ponytail
Adapter for ponytail.
pickup
Adapter for pickup.