Logo IconGuided Mind
v2.4Sign In
Python SDK

Long Memory

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.

Storing Records

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.",
)

Searching Long-Term Memories

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}")

Personalisation Pattern

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}"

Methods

MethodReturnsDescription
store_record(user_id, role, content)MemoryRecordPersist a message for a user
search(query, limit?, threshold?)SearchResponseSemantic search over stored records
astore_record(...)Awaitable[MemoryRecord]Async store
asearch(...)Awaitable[SearchResponse]Async search

Short vs. Long Memory

Short MemoryLong Memory
Keysession_iduser_id
ExpiryConfigurable TTL (24h default)Never — persists indefinitely
RetrievalOrdered list by timeSemantic search by relevance
Storage limitPer-session capUnlimited
Best forActive conversation contextCross-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.