Skip to content
Get started

Structured collections

Structured collections keep the same subject–predicate–object graph as flexible collections, but enforce a schema on writes. Use them when agents share records that need stable identifiers, typed values, required fields, and controlled updates.

Flexible collections accept evolving facts without a graph schema. Structured collections accept only the declared entity types, predicates, value shapes, and write policies. Collection access permissions still apply in both modes. The default bucket is flexible.

Create a structured collection

In the dashboard, create a collection, choose Structured, define its entity types and fields, then review the schema and collection instructions before saving. Choose the mode at creation: an existing collection cannot switch between flexible and structured.

For session-authenticated integrations, POST /v1/orgs/:org_id/collections accepts code, name, mode: "structured", and a schema object like the one below. Omitting mode creates a flexible collection. Schema management is separate from ordinary API-key or OAuth agent writes.

Discover before writing

  1. Call MCP get_collection_schema with the collection code, or use REST:
curl 'https://api.gominddb.com/v1/collection-schema?collection=project-work' \
  -H "X-API-Key: $GOMIND_API_KEY"
  1. Read mode, schema_version, index_subject, and schema from the result. REST wraps these fields in the usual { status, result } envelope. Discovery does not spend fact credits. A flexible collection returns schema: null.
  2. Recall the exact returned index_subject and paginate to read all its instructions. Use readme and storage_rules where present. Do not construct a second index from an alias or access address.
  3. In structured mode, the schema is authoritative. Use its exact keys, not display titles, inferred synonyms, or fields suggested by prose. Never request normalization.

MCP discovery arguments:

{ "collection": "project-work" }

Omit collection to use the connection's scope. An explicit "" selects the default bucket. See collection selection for precedence.

A graph schema

This schema declares tasks and people. title, status, and display_name are required. owner is a graph reference; details is a typed JSON value.

{
  "format_version": 1,
  "entities": {
    "task": {
      "id_pattern": "[a-z0-9-]+",
      "title": "Task",
      "predicates": {
        "title": {
          "kind": "value",
          "cardinality": "one",
          "write_policy": "mutable",
          "required": true,
          "value_schema": { "type": "string", "minLength": 1 }
        },
        "status": {
          "kind": "value",
          "cardinality": "one",
          "write_policy": "compare_and_set",
          "required": true,
          "value_schema": { "type": "string", "enum": ["todo", "done"] }
        },
        "owner": {
          "kind": "reference",
          "reference_type": "person",
          "cardinality": "one",
          "write_policy": "mutable"
        },
        "details": {
          "kind": "value",
          "cardinality": "one",
          "write_policy": "mutable",
          "value_schema": {
            "type": "object",
            "properties": {
              "estimate": { "type": "integer", "minimum": 0 },
              "approved": { "type": "boolean" }
            },
            "required": ["estimate", "approved"],
            "additionalProperties": false
          }
        },
        "event": {
          "kind": "value",
          "cardinality": "many",
          "write_policy": "append_only",
          "value_schema": { "type": "string", "minLength": 1 }
        }
      }
    },
    "person": {
      "id_pattern": "[a-z0-9-]+",
      "predicates": {
        "display_name": {
          "kind": "value",
          "cardinality": "one",
          "write_policy": "mutable",
          "required": true,
          "value_schema": { "type": "string", "minLength": 1 }
        }
      }
    }
  }
}

The server adds the common index type for the owning collection code, with readme and storage_rules predicates. Those common predicates are mutable, single, nonempty string values. Schema compilation adds their definitions, not instruction facts.

Identifiers and values

  • Subjects use exact type:id identifiers, at most 70 Unicode code points, with no whitespace or extra colon in the ID. id_pattern is a Go RE2 expression matched against the entire ID, not the type prefix.
  • kind: "value" requires value_schema. A root string stays literal, even if it looks like person:maya or JSON. Strings inside JSON also stay strings.
  • kind: "reference" requires reference_type, not value_schema. Only these predicates create graph links, and the target must match the declared entity type and ID rule in the same collection.
  • Use the exact entity, predicate, and JSON property keys. Optional title and description annotations are labels, not alternate keys.

Supported value schemas

This is a restricted schema format, not arbitrary JSON Schema.

TypeSupported constraints
stringminLength, maxLength, pattern (Go RE2), format (date or date-time), enum
integer, numberminimum, maximum, enum
booleanenum
objectproperties, required, mandatory additionalProperties: false
arraymandatory items, minItems, maxItems

Reuse value definitions through root $defs and local $ref values such as #/$defs/Address. External references and recursive value definitions are not supported. Nested JSON fields may declare a nullable type such as ["string", "null"]; a root fact value cannot be nullable. Unsupported keywords are rejected rather than ignored.

Schemas are limited to 64 KiB after expansion, 32 entity types including the common index, 128 predicates per type, 64 reusable definitions, and 1,024 value-schema nodes. Resolved value depth is limited to 16.

Create complete records atomically

Required predicates must be present for every live item, including newly referenced items. Create a task and its new owner together in one remember_many call:

{
  "collection": "project-work",
  "facts": [
    { "subject": "task:launch", "predicate": "title", "object": "Prepare launch" },
    { "subject": "task:launch", "predicate": "status", "object": "todo" },
    { "subject": "task:launch", "predicate": "owner", "object": "person:maya" },
    { "subject": "person:maya", "predicate": "display_name", "object": "Maya" },
    { "subject": "task:launch", "predicate": "details", "object": "{\"estimate\":0,\"approved\":false}" }
  ]
}

The example uses string-encoded objects, which also work in MCP. For non-string value schemas, send valid JSON text of the declared type, not a quoted JSON string containing a number or boolean. Inside JSON objects and arrays, preserve actual types: false and 0, not "false" and "0".

Predicate-level required: true requires a fact. The required array inside a JSON value schema requires properties within that one fact. Required means present, not truthy: valid false and 0 values satisfy presence requirements.

If creation fails validation, the batch stores no facts. Resubmit the complete corrected batch, not just the missing fields. MCP remember_many returns a background job ID; use get_job to confirm success and retrieve refs before treating the records as saved.

Cardinality and write policies

cardinality: "one" allows at most one fact per subject and predicate; "many" allows multiple. A batch cannot contain the same singleton slot twice. Initializing an occupied singleton returns FACT_CARDINALITY_CONFLICT; use an allowed explicit update or replacement instead.

write_policyAllowed changes
mutableInitialize, update, remove, or explicitly replace with replace: true, while preserving required fields.
append_onlyAdd facts to available slots. No update, removal, or replacement. A singleton can only be initialized once.
compare_and_setSingletons only. Initialize an empty slot; then update with if_object matching the current value. No replacement, removal, or subject/predicate change.

For the example's status, recall its current value and ref, then call update:

{
  "collection": "project-work",
  "subject": "task:launch",
  "predicate": "status",
  "ref": "ABCDE",
  "if_object": "todo",
  "new_object": "done"
}

Replace ABCDE with the ref returned by your own recall. If another writer changed the fact, reread before deciding whether to retry.

Updates and deletions cannot remove an item's last required value. To delete an entire item, use forget_entity; deletion must still respect write policies and cannot break required links on other live items. Bulk deletion is best effort: inspect failed instead of assuming every requested fact was removed.

Collection instructions require a manager

In structured mode, ordinary memory tools cannot mutate the owning index_subject, even if the supplied facts match the schema. An agent's request or textual approval in chat does not authorize an index edit.

A signed-in collection manager must review and confirm the change in Collection settings → Collection instructions. API keys and OAuth agent tokens cannot perform this confirmation. The same restriction applies to updates, deletions, and moves that affect the index.

Publish schema revisions

A signed-in collection manager can review and publish a revised schema in collection settings. The management API is PUT /v1/orgs/:org_id/collections/:id/schema, with schema and the last read if_schema_version. Here :id is the internal collection ID, unlike the collection code used by memory calls.

Read the management view with GET /v1/orgs/:org_id/collections/:id/schema. Publication checks existing facts, their stored representations, cardinality, and required fields. Incompatible changes are rejected without rewriting the data. Schema publication does not switch the collection's mode; metadata PATCH cannot change the mode or publish a schema.

Handle rejected writes

REST returns contract diagnostics in result, with the code in errorMessage. Inspect schema_version, violations, and any required_action; violations can identify a subject, predicate, path, ref, or batch item.

CodeWhat to do
SCHEMA_VALIDATION_FAILEDFix identifiers, undeclared keys, types, or missing required fields. Resubmit complete creation batches.
FACT_CARDINALITY_CONFLICTRecall the occupied slot; use a policy-permitted update or replacement.
WRITE_POLICY_VIOLATIONFollow the predicate's policy instead of forcing replacement or deletion.
NORMALIZATION_NOT_ALLOWEDOmit normalization and send exact schema keys.
INDEX_CONFIRMATION_REQUIREDAsk a manager to review the index change in collection settings.
COLLECTION_STRUCTURE_CHANGED, SCHEMA_VERSION_CONFLICTRediscover the schema and review the operation against the new revision.
SCHEMA_EXISTING_FACTS_INVALIDReview incompatible existing facts before publishing the schema.
COLLECTION_MODE_IMMUTABLE, SCHEMA_ENDPOINT_REQUIREDKeep the existing mode; publish schema changes through the schema endpoint, not metadata PATCH.

Continue with writing memory, remember_many, or updating facts.