
Persistent per-user memory with semantic search and automatic summarisation.
Long Memory stores conversation records keyed by a user_id and retains them indefinitely.
Records are embedded and indexed for semantic search, so you can retrieve the most relevant
past interactions for any given query — even across many sessions and months of history.
Access it via client.memory.long.
from guidedmind import Client
client = Client()
client.memory.long.store_record(
user_id="user-456",
role="user",
content="I'm interested in the Pro plan for my team of 10.",
)
client.memory.long.store_record(
user_id="user-456",
role="assistant",
content="The Pro plan supports up to 20 members and includes advanced analytics.",
)response = client.memory.long.search(
query="What did the user say about pricing?",
limit=10,
threshold=0.75,
)
print(f"Found {response.total} relevant memories")
for result in response.results:
print(f" [{result.score:.3f}] {result.content}")A typical pattern for personalising AI responses using long-term memory:
def build_personalised_context(user_id: str, current_query: str) -> str:
"""Retrieve relevant past interactions to inject as context."""
memories = client.memory.long.search(
query=current_query,
limit=5,
threshold=0.70,
)
if not memories.results:
return ""
lines = [f"- {r.content}" for r in memories.results]
return "Relevant history for this user:\n" + "\n".join(lines)
# Then inject into your LLM system prompt:
context = build_personalised_context("user-456", "Tell me about plan upgrades")
system_prompt = f"You are a helpful assistant.\n\n{context}"| Method | Returns | Description |
|---|---|---|
store_record(user_id, role, content) | MemoryRecord | Persist a message for a user |
search(query, limit?, threshold?) | SearchResponse | Semantic search over stored records |
astore_record(...) | Awaitable[MemoryRecord] | Async store |
asearch(...) | Awaitable[SearchResponse] | Async search |
| Short Memory | Long Memory | |
|---|---|---|
| Key | session_id | user_id |
| Expiry | Configurable TTL (24h default) | Never — persists indefinitely |
| Retrieval | Ordered list by time | Semantic search by relevance |
| Storage limit | Per-session cap | Unlimited |
| Best for | Active conversation context | Cross-session personalisation |
Use both together: Short Memory for the current conversation context, Long Memory to recall preferences and past interactions that predate the current session.