This document defines the v1 query request and query response contracts for ANDB.
Its purpose is to give all collaborators a shared interface for:
- query input
- retrieval planning assumptions
- graph expansion seed format
- structured evidence return
- proof trace packaging
The current implementation structs live in src/internal/schemas/query.go. This document describes both the current field names and the intended semantic contract for v1.
ANDB query should not be treated as a plain search endpoint that returns only ranked chunks.
The contract should reflect the real goal:
return structured evidence over canonical objects.
That means the query interface must carry enough context for:
- retrieval planning
- filtering
- scope restriction
- relation expansion
- provenance return
- proof trace generation
Current QueryRequest fields:
query_textquery_scopesession_idagent_idtenant_id(optional)workspace_id(optional)top_ktime_windowobject_types(optional)memory_types(optional)relation_constraintsresponse_modeinclude_cold(optional bool) — when true, retrieval merges cold-tierColdSearchresults (archived memories) into the tiered search path.
Current TimeWindow fields:
fromto
These names are the implementation contract today.
A practical v1 request should contain at least:
query_textagent_idsession_idtop_kresponse_mode
Current example compatible with the running server:
{
"query_text": "What evidence suggests the current plan is blocked by a failed tool call?",
"query_scope": "workspace",
"session_id": "sess_a",
"agent_id": "agent_a",
"tenant_id": "t_demo",
"workspace_id": "w_demo",
"top_k": 5,
"time_window": {
"from": "2026-03-16T00:00:00Z",
"to": "2026-03-16T23:59:59Z"
},
"object_types": ["memory", "state", "artifact"],
"memory_types": ["semantic", "episodic"],
"relation_constraints": [],
"response_mode": "structured_evidence"
}The current implementation is intentionally narrow, but v1 semantics should be read as follows.
Type: string
Meaning:
- semantic retrieval anchor
- input to dense and sparse retrieval paths
Type: string
Meaning:
- identifies the querying agent
- supports scope and visibility restriction
Type: string
Meaning:
- identifies the current execution context
- supports local-context and state-aware retrieval
Type: string
Examples:
privatesessionworkspaceshared
Meaning:
- controls which namespace or visibility domain is searched
Type: string
Meaning:
- narrows retrieval to a tenant boundary when provided
- supports multi-tenant deployment patterns
Type: string
Meaning:
- narrows retrieval to a workspace boundary when provided
- improves routing and policy filtering precision
Type: integer
Meaning:
- initial retrieval candidate target
- applied before relation expansion
Type: object
Current fields:
fromto
Meaning:
- restricts the temporal range of query candidates
Type: list[string]
Meaning:
- restricts candidate search to selected canonical object families
- typical values include
memory,state,artifact,event
Type: list[string]
Meaning:
- applies a memory-level semantic filter when
memoryis included in object search - typical values include
episodic,semantic,procedural,social,reflective
Type: list[string] in the current Go schema
Current implementation note:
- this is lighter than the richer semantic model originally proposed
Intended meaning:
- edge-type restrictions
- expansion hints
- graph-stage control parameters
If the project evolves this into a richer object later, that change should be reviewed carefully because it is a shared contract.
Type: string
Recommended v1 values:
structured_evidenceobjects_only
Current runtime note:
- demo scripts may still send
evidence - the server does not yet strongly validate mode values
The docs standardize on structured_evidence as the preferred target mode.
These are still semantically useful but are not yet present in the current Go request struct:
- richer
relation_constraintsobject model debug
They should be treated as planned contract directions, not as implemented requirements today.
The default v1 response should be a structured evidence package rather than a bare ranking list.
It should ultimately contain:
- evidence objects
- relation edges
- provenance information
- version information
- applied filters
- proof trace
This is the contract that differentiates ANDB.
Current QueryResponse fields:
objectsas[]stringnodesas[]GraphNode(optional; populated afterQueryChainsubgraph work when applicable)edgesas[]Edgeprovenanceas[]stringversionsas[]ObjectVersionapplied_filtersas[]stringproof_traceas[]stringchain_tracesas{ "main", "memory_pipeline", "query", "collaboration" }each[]string— on query,main/memory_pipeline/collaborationhold read-path summaries (write chains are not re-run);queryis filled fromQueryChain(proof/subgraph merge metadata)evidence_cacheas optional{ "looked_up", "hits", "misses" }— counts for pre-computedEvidenceFragmentlookups over returned object IDs (omitted when no cache or no IDs)
Current implementation note:
- this is a bootstrap response shape
- object payloads are still object IDs rather than full evidence objects
For the richer v1 contract, the response should include at least:
query_idstatusobjectsedgesprovenanceversionsapplied_filtersproof_trace
Illustrative target example:
{
"query_id": "q_001",
"status": "success",
"objects": [
{
"object_id": "mem_001",
"object_type": "memory",
"summary": "Tool X failed due to token expiry.",
"score": 0.91,
"scope": "session",
"version": 1,
"source_refs": ["evt_008"]
}
],
"edges": [
{
"edge_id": "edge_013",
"src_object_id": "mem_001",
"dst_object_id": "evt_008",
"edge_type": "derived_from",
"weight": 1.0
}
],
"provenance": [
{
"object_id": "mem_001",
"source_event_ids": ["evt_008"],
"notes": "Derived from failed tool result."
}
],
"versions": [
{
"object_id": "mem_001",
"object_type": "memory",
"version": 1,
"mutation_event_id": "evt_008"
}
],
"applied_filters": {
"scope": "session",
"time_window": {
"from": "2026-03-16T00:00:00Z",
"to": "2026-03-16T23:59:59Z"
}
},
"proof_trace": {
"retrieval_paths_used": ["dense", "filter"],
"seed_object_ids": ["mem_001"],
"expanded_edge_types": ["derived_from"],
"assembly_steps": [
"dense retrieval produced 8 candidates",
"merged to 5 unique objects",
"expanded 1 hop over derived_from edges"
]
}
}This richer response is the semantic target even though current code still uses simplified arrays.
ANDB may support a lighter debugging mode:
response_mode = objects_only
In that mode:
objectsremains required- other fields may be empty or simplified
- this mode is for internal debugging or experiments, not the primary product contract
Recommended error fields:
query_idstatuserror_codemessage
Example:
{
"query_id": "q_009",
"status": "failed",
"error_code": "INVALID_RELATION_CONSTRAINT",
"message": "max_hops must be >= 1"
}The current server still relies mostly on HTTP error responses rather than a fully standardized error envelope.
Request-side rules:
query_textmust not be emptyagent_idmust not be emptysession_idmust not be emptytop_kmust be positiveresponse_modeshould be recognized- if provided,
object_typesandmemory_typesvalues should be recognized by the runtime - unsupported relation filters should be rejected or explicitly ignored
Response-side rules:
objectsmust always exist on successful responsesedges,provenance,versions,applied_filters, andproof_traceshould remain present as categories even if empty- once
structured_evidenceis fully enforced, evidence mode should not collapse to a plain list without explanation
The following are allowed in v1:
- rough scoring
- shallow provenance
- current-version-only metadata
- proof trace as execution notes
- 1-hop or 2-hop graph expansion only
- simplified request fields while the main flow is still being stabilized
These simplifications are acceptable only if the response still points toward the structured-evidence contract.
The ANDB query schema is not merely a search API contract. It is the semantic interface through which the database exposes reasoning-ready evidence.
For v1, the key requirement is:
even if the implementation is lightweight, the contract should already reflect the structured-evidence philosophy.