Skip to main content

Ontology API

Retrieve and save persona ontologies and world state data in a format compatible with the frontend.

Get Ontology

Retrieve all personas, their ontologies, and world state.

Request

GET /api/ontology

Response

Status: 200 OK

{
"personas": [
{
"id": "660e8400-e29b-41d4-a716-446655440001",
"name": "Sports Scout",
"role": "Professional Baseball Scout",
"informationNeed": "Evaluate player performance and technique",
"details": "Focus on batting mechanics and pitch recognition",
"createdAt": "2025-10-06T14:30:00.000Z",
"updatedAt": "2025-10-06T14:30:00.000Z"
}
],
"personaOntologies": [
{
"id": "770e8400-e29b-41d4-a716-446655440002",
"personaId": "660e8400-e29b-41d4-a716-446655440001",
"entities": [
{
"id": "entity-001",
"name": "Pitcher",
"definition": "Player who throws the ball to the batter",
"wikidataId": "Q1196129"
}
],
"roles": [
{
"id": "role-001",
"name": "Starting Pitcher",
"definition": "Pitcher who begins the game"
}
],
"events": [
{
"id": "event-001",
"name": "Pitch",
"definition": "Act of throwing the ball toward home plate"
}
],
"relationTypes": [
{
"id": "relation-001",
"name": "Throws",
"definition": "Pitcher throws ball to batter",
"sourceType": "entity",
"targetType": "entity"
}
],
"relations": [],
"createdAt": "2025-10-06T14:30:00.000Z",
"updatedAt": "2025-10-06T14:30:00.000Z"
}
],
"world": {
"entities": [
{
"id": "world-entity-001",
"name": "Player 23",
"type": "person",
"description": "Team's starting pitcher",
"wikidataId": null,
"typeAssignments": [
{
"personaId": "660e8400-e29b-41d4-a716-446655440001",
"typeId": "entity-001",
"typeName": "Pitcher"
}
]
}
],
"events": [],
"times": [],
"entityCollections": [],
"eventCollections": [],
"timeCollections": [],
"relations": []
}
}

Response Schema

Persona Objects

FieldTypeDescription
idUUIDPersona identifier
namestringDisplay name
rolestringProfessional role
informationNeedstringWhat persona wants to learn
detailsstring|nullAdditional context
createdAtstringISO 8601 timestamp
updatedAtstringISO 8601 timestamp

Persona Ontology Objects

FieldTypeDescription
idUUIDOntology identifier
personaIdUUIDAssociated persona
entitiesarrayEntity type definitions
rolesarrayRole type definitions
eventsarrayEvent type definitions
relationTypesarrayRelation type definitions
relationsarrayRelation instances (deprecated)
createdAtstringISO 8601 timestamp
updatedAtstringISO 8601 timestamp

World State Object

FieldTypeDescription
entitiesarrayEntity instances
eventsarrayEvent instances
timesarrayTime instances
entityCollectionsarrayEntity collection instances
eventCollectionsarrayEvent collection instances
timeCollectionsarrayTime collection instances
relationsarrayRelation instances

Example

curl http://localhost:3001/api/ontology

Save Ontology

Save ontology data including personas, their ontologies, and world state. Uses upsert operations for atomic updates.

Request

PUT /api/ontology

Content-Type: application/json

{
"personas": [
{
"id": "660e8400-e29b-41d4-a716-446655440001",
"name": "Sports Scout",
"role": "Professional Baseball Scout",
"informationNeed": "Evaluate player performance and technique",
"details": "Focus on batting mechanics and pitch recognition"
}
],
"personaOntologies": [
{
"personaId": "660e8400-e29b-41d4-a716-446655440001",
"entities": [
{
"id": "entity-001",
"name": "Pitcher",
"definition": "Player who throws the ball to the batter",
"wikidataId": "Q1196129"
}
],
"roles": [],
"events": [],
"relationTypes": []
}
],
"world": {
"entities": [
{
"id": "world-entity-001",
"name": "Player 23",
"type": "person",
"description": "Team's starting pitcher",
"typeAssignments": [
{
"personaId": "660e8400-e29b-41d4-a716-446655440001",
"typeId": "entity-001",
"typeName": "Pitcher"
}
]
}
],
"events": [],
"times": [],
"entityCollections": [],
"eventCollections": [],
"timeCollections": [],
"relations": []
}
}

Request Body Schema

Required Fields

FieldTypeRequiredDescription
personasarrayYesArray of persona objects
personaOntologiesarrayYesArray of ontology objects
worldobjectNoWorld state object

Persona Object Schema

FieldTypeRequiredDescription
idUUIDYesPersona UUID (for upsert)
namestringYesDisplay name
rolestringYesProfessional role
informationNeedstringYesInformation need
detailsstringNoAdditional details

Persona Ontology Object Schema

FieldTypeRequiredDescription
personaIdUUIDYesAssociated persona UUID
entitiesarrayYesEntity type array (can be empty)
rolesarrayYesRole type array (can be empty)
eventsarrayYesEvent type array (can be empty)
relationTypesarrayYesRelation type array (can be empty)

World State Object Schema

FieldTypeRequiredDescription
entitiesarrayYesEntity instance array
eventsarrayYesEvent instance array
timesarrayYesTime instance array
entityCollectionsarrayYesEntity collection array
eventCollectionsarrayYesEvent collection array
timeCollectionsarrayYesTime collection array
relationsarrayYesRelation instance array

Response

Status: 200 OK

Returns the saved data in the same format as GET /api/ontology:

{
"personas": [...],
"personaOntologies": [...],
"world": {...}
}

Example

curl -X PUT http://localhost:3001/api/ontology \
-H "Content-Type: application/json" \
-d '{
"personas": [{
"id": "660e8400-e29b-41d4-a716-446655440001",
"name": "Sports Scout",
"role": "Professional Baseball Scout",
"informationNeed": "Evaluate player performance"
}],
"personaOntologies": [{
"personaId": "660e8400-e29b-41d4-a716-446655440001",
"entities": [],
"roles": [],
"events": [],
"relationTypes": []
}]
}'

Notes

Transaction Atomicity

All save operations execute within a database transaction. If any persona, ontology, or world state update fails, the entire operation is rolled back.

Upsert Behavior

The endpoint uses upsert operations:

  • If a persona with the given ID exists, it is updated
  • If a persona does not exist, it is created
  • Same behavior applies to ontologies and world state

World State Singleton

There is only one WorldState record in the database. If world data is provided:

  • Existing world state is updated
  • If no world state exists, it is created
  • World state is shared across all personas

Ontology Structure

Each persona has exactly one ontology. The ontology contains:

  • Entity Types: Categories of objects (person, car, building)
  • Role Types: Roles objects can play (pitcher, driver)
  • Event Types: Types of actions (pitch, drive, collision)
  • Relation Types: Relationships between entities (contains, adjacent-to)

Type Assignments

World entities can have type assignments from multiple personas:

{
"id": "world-entity-001",
"name": "Person 1",
"typeAssignments": [
{
"personaId": "persona-1",
"typeId": "entity-001",
"typeName": "Pitcher"
},
{
"personaId": "persona-2",
"typeId": "entity-042",
"typeName": "Athlete"
}
]
}

This allows different personas to interpret the same real-world object differently.

Frontend Integration

This endpoint is designed to work with Redux state management:

  • Frontend fetches all ontology data on application load
  • Frontend sends complete state on save (not delta updates)
  • Transaction ensures consistency between personas, ontologies, and world state

Empty Arrays

Empty arrays are valid and indicate no types or instances of that category:

{
"entities": [],
"roles": [],
"events": [],
"relationTypes": []
}

This creates a persona with an empty ontology, which can be populated later.