CerebeCerebe Docs

Query Knowledge

Search and traverse the knowledge graph for entities and relationships.

Query Knowledge

Query Cerebe's Knowledge Graph to find entities, relationships, and facts. Supports natural language queries with configurable traversal depth and filtering.

Endpoint

POST /api/v1/knowledge/query

Request Body

ParameterTypeRequiredDescription
querystringYesNatural language or structured query
entity_idstringNoStarting entity for graph traversal
entity_typestringNoFilter results by entity type
relationship_typesstring[]NoFilter by specific relationship types
depthintegerNoMaximum traversal depth, 1-5 (default: 2)
limitintegerNoMaximum results, 1-100 (default: 20)

Examples

from cerebe import AsyncCerebe

client = AsyncCerebe(api_key="ck_live_...")

results = await client.knowledge.query(
    query="Who does Alice mentor?",
    depth=2,
    limit=10,
)

for entity in results.entities:
    print(f"{entity.name} ({entity.entity_type})")

for rel in results.relationships:
    print(f"{rel.source_id} --[{rel.relationship_type}]--> {rel.target_id}")
import Cerebe from '@cerebe/sdk'

const client = new Cerebe({ apiKey: 'ck_live_...' })

const results = await client.knowledge.query({
  query: 'Who does Alice mentor?',
  depth: 2,
  limit: 10,
})

for (const entity of results.entities) {
  console.log(`${entity.name} (${entity.entityType})`)
}

for (const rel of results.relationships) {
  console.log(`${rel.sourceId} --[${rel.relationshipType}]--> ${rel.targetId}`)
}
curl -X POST https://api.cerebe.ai/api/v1/knowledge/query \
  -H "X-API-Key: ck_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Who does Alice mentor?",
    "depth": 2,
    "limit": 10
  }'

Response

{
  "entities": [
    {
      "id": "ent_abc123",
      "name": "Alice mentors Bob",
      "entity_type": "fact",
      "properties": null,
      "created_at": "2025-03-07T14:30:00Z"
    }
  ],
  "relationships": [],
  "total": 1
}

Entity Object

FieldTypeDescription
idstringUnique entity identifier
namestringEntity name or fact description
entity_typestringType classification (e.g., person, organization, fact)
propertiesobjectAdditional entity properties
created_atstringISO-8601 creation timestamp

Relationship Object

FieldTypeDescription
source_idstringSource entity ID
target_idstringTarget entity ID
relationship_typestringType of relationship
propertiesobjectRelationship properties
valid_fromstringWhen this relationship became true
valid_tostringWhen this relationship ended (null if still active)

Temporal Queries

The knowledge graph is temporal --- relationships have valid_from and valid_to fields. This enables point-in-time queries:

# Who was on the team in January?
results = await client.knowledge.query(
    query="team members",
    entity_id="team_alpha",
    depth=1,
)

Error Responses

StatusDescription
401Missing or invalid API key
503Knowledge graph service unavailable

Next Steps

On this page