Graph API
Knowledge graph operations
Add Entity
Add an entity to the knowledge graph.
POST /v1/graph/entities Request Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Entity name |
type | string | Yes | Entity type (person, organization, etc.) |
attributes | object | No | Additional properties |
user_id | string | No | Scope 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
| Parameter | Type | Description |
|---|---|---|
type | string | Filter by entity type |
user_id | string | Filter by user |
limit | int | Maximum 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
| Field | Type | Required | Description |
|---|---|---|---|
source | string | Yes | Source entity name |
relation | string | Yes | Relationship type |
target | string | Yes | Target entity name |
attributes | object | No | Relationship 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
| Parameter | Type | Description |
|---|---|---|
source | string | Filter by source entity |
target | string | Filter by target entity |
relation | string | Filter by relationship type |
Query Graph
Traverse the graph from an entity.
POST /v1/graph/query Request Body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
entity | string | Yes | - | Starting entity |
depth | int | No | 1 | Traversal depth |
user_id | string | No | - | 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
| Field | Type | Description |
|---|---|---|
query | string | Natural language query |
limit | int | Maximum results |
Extract Knowledge
Extract entities and relationships from text.
POST /v1/graph/extract Request Body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to extract from |
store | boolean | No | Save 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"}
]
}