GitHub
Examples

Semantic Memory

Extract and store general knowledge facts that are true regardless of time.

Core Module
Scenario: Identifying Emma's colleagues and family

When to Use

Use semantic memory for facts, concepts, and relationships. Unlike episodic memory (which is about "events"), semantic memory is about "knowledge". Perfect for:

  • User profiles (Name, Occupation, Family)
  • World knowledge (Product details, Policies)
  • Extracted entities and their relationships

Key Operations

add_fact()

Insert a single knowledge fact

search()

Retrieve facts relevant to a query

Code Example

Here we manually add facts extracted from a conversation. In a real automated agent, these might be extracted by an LLM first.

# 1. Add extracted facts to the Knowledge Graph
facts = [
"Marcus is a senior engineer at Emma's company",
"Emma has a sister named Sarah",
"Nana Rose is Emma's grandmother"
]
for content in facts:
client.memory.facts.add_fact(
content=content,
kg_name="KG_Companion_Demo",
metadata={"category": "relationships"}
)
# 2. Query the Knowledge Graph
# The system can answer questions by synthesizing these facts
results = client.memory.facts.search(
query="Who are Emma's family members?",
kg_name="KG_Companion_Demo"
)
for res in results:
print(f"Fact found: {res.content}")

Key Takeaways

  • Semantic memory consolidates information. If you add "Emma is a PM" and later "Emma works as a Product Manager", the system handles the semantic similarity.
  • Facts are stored in a Knowledge Graph, allowing for structured retrieval.
  • This is the "long-term knowledge base" of your agent.