praval.memory.semantic_memory

Semantic memory for Praval agents - knowledge, facts, and concepts

This manages: - Factual knowledge storage - Concept relationships - Domain expertise - Learned information persistence

Classes

SemanticMemory(long_term_memory)

Manages semantic memories - facts, concepts, and knowledge

class praval.memory.semantic_memory.SemanticMemory(long_term_memory)[source]

Bases: object

Manages semantic memories - facts, concepts, and knowledge

Features: - Factual knowledge storage - Concept relationship tracking - Knowledge validation and updating - Domain expertise building

Parameters:

long_term_memory (LongTermMemory)

__init__(long_term_memory)[source]

Initialize semantic memory

Parameters:

long_term_memory (LongTermMemory) – Long-term memory backend for persistence

store_fact(agent_id, fact, domain, confidence=1.0, source=None, related_concepts=None)[source]

Store a factual piece of knowledge

Parameters:
  • agent_id (str) – The agent learning this fact

  • fact (str) – The factual statement

  • domain (str) – Domain or category of knowledge

  • confidence (float) – Confidence in this fact (0.0 to 1.0)

  • source (Optional[str]) – Source of this information

  • related_concepts (Optional[List[str]]) – Related concepts or topics

Return type:

str

Returns:

The memory ID

store_concept(agent_id, concept, definition, domain, properties=None, relationships=None)[source]

Store a concept with its definition and relationships

Parameters:
  • agent_id (str) – The agent learning this concept

  • concept (str) – The concept name

  • definition (str) – Definition of the concept

  • domain (str) – Domain or field of the concept

  • properties (Optional[Dict[str, Any]]) – Properties or attributes of the concept

  • relationships (Optional[Dict[str, List[str]]]) – Relationships to other concepts (e.g., {“is_a”: [“category”],

  • "relates_to" – [“other_concepts”]})

Return type:

str

Returns:

The memory ID

store_rule(agent_id, rule_name, rule_description, conditions, actions, domain, confidence=1.0)[source]

Store a procedural rule or pattern

Parameters:
  • agent_id (str) – The agent learning this rule

  • rule_name (str) – Name of the rule

  • rule_description (str) – Description of what the rule does

  • conditions (List[str]) – Conditions when the rule applies

  • actions (List[str]) – Actions to take when conditions are met

  • domain (str) – Domain of application

  • confidence (float) – Confidence in this rule

Return type:

str

Returns:

The memory ID

get_knowledge_in_domain(agent_id, domain, limit=50)[source]

Get all knowledge in a specific domain

Parameters:
  • agent_id (str) – The agent to get knowledge for

  • domain (str) – The domain to search in

  • limit (int) – Maximum number of entries to return

Return type:

List[MemoryEntry]

Returns:

List of semantic memories in the domain

Find concepts related to a given concept

Parameters:
  • agent_id (str) – The agent to search for

  • concept (str) – The concept to find relations for

  • limit (int) – Maximum number of related concepts

Return type:

MemorySearchResult

Returns:

Search results with related concepts

validate_knowledge(agent_id, statement, threshold=0.8)[source]

Check if a statement is consistent with stored knowledge

Parameters:
  • agent_id (str) – The agent to check knowledge for

  • statement (str) – The statement to validate

  • threshold (float) – Similarity threshold for matching

Return type:

Dict[str, Any]

Returns:

Validation result with confidence and supporting evidence

update_knowledge(agent_id, old_knowledge, new_knowledge, reason='Updated information')[source]

Update existing knowledge with new information

Parameters:
  • agent_id (str) – The agent updating knowledge

  • old_knowledge (str) – The knowledge to update

  • new_knowledge (str) – The new knowledge

  • reason (str) – Reason for the update

Return type:

bool

Returns:

True if update was successful

get_domain_expertise_level(agent_id, domain)[source]

Assess the agent’s expertise level in a domain

Parameters:
  • agent_id (str) – The agent to assess

  • domain (str) – The domain to assess expertise in

Return type:

Dict[str, Any]

Returns:

Expertise assessment with metrics

get_stats()[source]

Get semantic memory statistics

Return type:

Dict[str, Any]