Ontology
The Ontology resource manages domain-specific schemas. Define concepts, relationships, and hierarchies to structure how facts are extracted and organized in your knowledge graph.
client.ontology.load()POST /v1/ontologyLoad or update an ontology domain with concepts and relationships.
Parameters
domainstrRequiredUnique identifier for the ontology domain (e.g., "software_engineering").
namestrRequiredHuman-readable name for the ontology.
conceptslist[OntologyConceptRequest | dict]RequiredList of concepts to define in the ontology.
descriptionstrOptionalDescription of the ontology domain.
relationshipslist[OntologyRelationshipRequest | dict]OptionalRelationships between concepts.
Concept Structure
Concept Fields
concept_idstrRequiredUnique identifier for the concept.
namestrRequiredHuman-readable name.
descriptionstrOptionalDescription of the concept.
aliaseslist[str]OptionalAlternative names for the concept.
Relationship Structure
Relationship Fields
source_concept_idstrRequiredID of the source concept.
target_concept_idstrRequiredID of the target concept.
relationship_typestrRequiredType of relationship (e.g., "built_with", "is_a", "has_a").
Example
1from memoair import MemoAir23client = MemoAir()45# Define a software engineering ontology6client.ontology.load(7 domain="software_engineering",8 name="Software Engineering Concepts",9 description="Common concepts in software development",10 concepts=[11 {12 "concept_id": "python",13 "name": "Python",14 "description": "A high-level programming language",15 "aliases": ["py", "python3"],16 },17 {18 "concept_id": "fastapi",19 "name": "FastAPI",20 "description": "Modern Python web framework",21 },22 {23 "concept_id": "pytorch",24 "name": "PyTorch",25 "description": "Machine learning framework",26 },27 {28 "concept_id": "web_framework",29 "name": "Web Framework",30 "description": "Framework for building web applications",31 },32 {33 "concept_id": "ml_framework",34 "name": "ML Framework",35 "description": "Framework for machine learning",36 },37 ],38 relationships=[39 {40 "source_concept_id": "fastapi",41 "target_concept_id": "python",42 "relationship_type": "built_with",43 },44 {45 "source_concept_id": "pytorch",46 "target_concept_id": "python",47 "relationship_type": "built_with",48 },49 {50 "source_concept_id": "fastapi",51 "target_concept_id": "web_framework",52 "relationship_type": "is_a",53 },54 {55 "source_concept_id": "pytorch",56 "target_concept_id": "ml_framework",57 "relationship_type": "is_a",58 },59 ],60)client.ontology.get()GET /v1/ontology/{domain}Retrieve a loaded ontology by domain.
1# Get ontology details2ontology = client.ontology.get(domain="software_engineering")34print(f"Name: {ontology.name}")5print(f"Concepts: {len(ontology.concepts)}")6print(f"Relationships: {len(ontology.relationships)}")client.ontology.list()GET /v1/ontologyList all loaded ontology domains.
1# List all ontologies2ontologies = client.ontology.list()34for ont in ontologies:5 print(f"- {ont.domain}: {ont.name} ({ont.concept_count} concepts)")client.ontology.stats()GET /v1/ontology/{domain}/statsGet statistics for a specific ontology.
1stats = client.ontology.stats(domain="software_engineering")23print(f"Domain: {stats.domain}")4print(f"Concepts: {stats.concept_count}")5print(f"Relationships: {stats.relationship_count}")client.ontology.delete()DELETE /v1/ontology/{domain}Delete an ontology domain and all its concepts.
1# Delete an ontology2client.ontology.delete(domain="software_engineering")Using Ontologies with Memory
Once an ontology is loaded, you can map extracted facts to ontology concepts during memory ingestion:
1from memoair import MemoAir, Message23client = MemoAir()45# Add memory with ontology mapping6client.memories.add(7 group_id="user:john",8 messages=[9 Message(10 content="I've been learning FastAPI for building APIs",11 role_type="user"12 ),13 ],14 map_to_ontology=True,15 ontology_domain="software_engineering",16 ontology_confidence_threshold=0.7,17)1819# The extracted fact "John uses FastAPI" will be linked to:20# - The "fastapi" concept in the ontology21# - Which is related to "python" and "web_framework"Ontology in Tripartite Search
When you enable search_ontology=True in tripartite search, MemoAir includes ontology concepts in the results:
1results = client.search.tripartite(2 query="What Python frameworks does John know?",3 user_id="user:john",4 search_ontology=True, # Include ontology in search5)67# Results might include:8# [user] John uses FastAPI9# [ontology] FastAPI is a web framework built with Python10# [ontology] Python is a high-level programming languageTip: Ontologies help your AI understand domain-specific terminology and relationships, improving search relevance and enabling more accurate fact extraction.