Graph API

Knowledge graph operations

Add Entity

Add an entity to the knowledge graph.

POST /v1/graph/entities

Request Body

FieldTypeRequiredDescription
namestringYesEntity name
typestringYesEntity type (person, organization, etc.)
attributesobjectNoAdditional properties
user_idstringNoScope to user

Example

curl -X POST https://api.memoid.dev/v1/graph/entities 
  -H "Authorization: Bearer YOUR_API_KEY" 
  -H "Content-Type: application/json" 
  -d '{
    "name": "John Smith",
    "type": "person",
    "attributes": {"role": "engineer"}
  }'

List Entities

Get entities with optional filters.

GET /v1/graph/entities

Query Parameters

ParameterTypeDescription
typestringFilter by entity type
user_idstringFilter by user
limitintMaximum results

Get Entity

Get a specific entity by name.

GET /v1/graph/entities/:name

Delete Entity

Remove an entity (and its relationships).

DELETE /v1/graph/entities/:name

Add Relationship

Create a relationship between entities.

POST /v1/graph/relationships

Request Body

FieldTypeRequiredDescription
sourcestringYesSource entity name
relationstringYesRelationship type
targetstringYesTarget entity name
attributesobjectNoRelationship properties

Example

curl -X POST https://api.memoid.dev/v1/graph/relationships 
  -H "Authorization: Bearer YOUR_API_KEY" 
  -H "Content-Type: application/json" 
  -d '{
    "source": "John",
    "relation": "works_at",
    "target": "Acme Corp"
  }'

List Relationships

Get relationships with filters.

GET /v1/graph/relationships

Query Parameters

ParameterTypeDescription
sourcestringFilter by source entity
targetstringFilter by target entity
relationstringFilter by relationship type

Query Graph

Traverse the graph from an entity.

POST /v1/graph/query

Request Body

FieldTypeRequiredDefaultDescription
entitystringYes-Starting entity
depthintNo1Traversal depth
user_idstringNo-Scope to user

Example

curl -X POST https://api.memoid.dev/v1/graph/query 
  -H "Authorization: Bearer YOUR_API_KEY" 
  -H "Content-Type: application/json" 
  -d '{
    "entity": "John",
    "depth": 2
  }'

Response

{
  "entities": [
    {"name": "John", "type": "person"},
    {"name": "Acme Corp", "type": "organization"},
    {"name": "San Francisco", "type": "location"}
  ],
  "relationships": [
    {"source": "John", "relation": "works_at", "target": "Acme Corp"},
    {"source": "Acme Corp", "relation": "located_in", "target": "San Francisco"}
  ]
}

Search Graph

Semantic search over the knowledge graph.

POST /v1/graph/search

Request Body

FieldTypeDescription
querystringNatural language query
limitintMaximum results

Extract Knowledge

Extract entities and relationships from text.

POST /v1/graph/extract

Request Body

FieldTypeRequiredDescription
textstringYesText to extract from
storebooleanNoSave to graph (default: false)

Example

curl -X POST https://api.memoid.dev/v1/graph/extract 
  -H "Authorization: Bearer YOUR_API_KEY" 
  -H "Content-Type: application/json" 
  -d '{
    "text": "Sarah is the CEO of TechCorp. She founded it with Mike in 2020.",
    "store": true
  }'

Response

{
  "entities": [
    {"name": "Sarah", "type": "person"},
    {"name": "TechCorp", "type": "organization"},
    {"name": "Mike", "type": "person"},
    {"name": "CEO", "type": "role"}
  ],
  "relationships": [
    {"source": "Sarah", "relation": "is", "target": "CEO"},
    {"source": "Sarah", "relation": "founded", "target": "TechCorp"},
    {"source": "Mike", "relation": "co-founded", "target": "TechCorp"}
  ]
}