Skip to content

Query Architecture

Source mirrored from seocho/docs/QUERY_ARCHITECTURE.md

This page explains how SEOCHO turns a question into graph-grounded evidence and a supported answer. Read /docs/architecture/ first if you only need the system overview.

The query plane owns four decisions:

DecisionQuestionMain owner
intentwhat does the user need answered?src/seocho/query/intent.py
retrievalwhich graph facts are relevant and answerable?src/seocho/query/
executionwhich query path is allowed and safe?src/seocho/query/cypher_validator.py
answerwhat can be said with the evidence?semantic answer contracts

The query layer should produce evidence, not just a fluent answer.

external data
-> ontology-shaped extraction
-> entity linking and deduplication
-> rule assessment
-> graph write with provenance
-> user question
-> query intent
-> graph evidence
-> supported answer

Query behavior depends on the same ontology context used during indexing. If the query loses that context, the answer can become fluent but no longer auditable.

The default semantic path is built for hard entity disambiguation:

user question
-> semantic layer
- extract candidate entities
- search graph fulltext index
- apply contains-based fallback
- use ontology labels and aliases when available
- deduplicate candidates
-> route to LPG, RDF, or hybrid path
-> answer generation
-> support assessment

This path exists because user wording rarely matches graph labels exactly. Fulltext-first lookup improves recall, while semantic deduplication reduces wrong-node selection before Cypher execution.

LayerOwnsMain files
query engineplanning, execution, answer shapingsrc/seocho/query/*
phase Aintent, support, strategy, Cypher validationintent.py, strategy_chooser.py, validators
phase Bconstraint slices and run metadataconstraints.py, run_registry.py
phase Centity resolution, routing, LPG/RDF specialistssemantic_agents.py
phase Dshared semantic orchestrationsemantic_flow.py
compatibilityruntime injection and legacy aliasesextraction/*

Rule of thumb: add new query behavior under src/seocho/query/. Keep extraction/* focused on compatibility, transport, and runtime injection.

user -> semantic layer -> route -> LPG/RDF specialist -> answer generator

Use this as the default path for graph-grounded questions. It is the clearest path for ontology-aware retrieval, candidate review, and evidence tracking.

user -> debate orchestrator -> graph-specific agents -> shared memory -> synthesis

Use this for explicit multi-graph or multi-database comparison. It is not the first-run default. Runtime payloads should report readiness and degraded state when some graph agents are skipped.

user -> router -> specialist -> supervisor -> answer

This path exists for compatibility. New graph QA behavior should move through the semantic query path unless a compatibility test requires otherwise.

query_mode="graph_cot" keeps the public semantic API surface, but its internal lane is more explicit:

user question
-> semantic layer
-> query supervisor
-> text-to-cypher agent
-> answer generation agent
-> answer guardrail agent
-> final response

Typed artifacts live in src/seocho/query/graph_cot_contracts.py. Per-agent reasoning and tool specs live in src/seocho/query/graph_cot_design.py.

Semantic QA should move toward an explicit intent-to-evidence contract:

FieldPurpose
intent_idstable name for the answer task
required_relationsgraph relations needed to answer
required_entity_typesentity types that must be resolved
focus_slotsvalues the answer must fill
selected_triplesevidence selected from graph context
slot_fillsvalues found in evidence
missing_slotsanswer gaps that remain
provenance and confidencewhy the answer can be trusted

This keeps retrieval accountable to answerability instead of vague local similarity.

See docs/GRAPH_RAG_AGENT_HANDOFF_SPEC.md for the full handoff contract.

Cypher generation and templates must stay validation-first:

  • validate identifiers before execution
  • prefer elementId() over deprecated internal ID assumptions
  • distinguish empty result from connector failure
  • return insufficient evidence when required slots are missing
  • preserve graph/database/workspace scope in trace metadata

Do not treat a syntactically valid query as proof that the answer is supported.

The vocabulary layer reduces brittle keyword matching. It turns labels, aliases, and rule-derived terms into a governed lookup surface.

PlaneResponsibility
control planelifecycle, promotion gates, workspace overrides
data planeterm generation, enrichment, provenance
runtimelightweight query-time term expansion
offline governanceheavier ontology reasoning and OWL inspection

Offline ontology governance should stay out of request-time code.

A supported answer should make these reviewable:

EvidenceWhy it matters
ontology context hashproves the query used the same contract as indexed data
selected graph entitiesshows what the query grounded on
selected relationships or triplesshows answer support
missing slotsprevents false completeness
trace metadataexplains routing and tool calls
run metadatamakes later debugging possible

Performance or production claims require live runs against named services and recorded environment details. Mocks are useful for contract tests, not for scalability claims.