Skip to main content

Recall: Retrieving Memories

The Recall operation searches and retrieves relevant memories from a memory bank. Using the TEMPR retrieval strategy, it finds information that matches your query through multiple search methods—semantic similarity, keyword matching, entity relationships, and temporal reasoning.

Overview

Recall enables intelligent memory retrieval:

  • TEMPR multi-strategy search (semantic, keyword, graph, temporal)
  • Relevance-ranked results
  • Configurable result limits
  • Memory type filtering (World Facts, Experience, Observations)

Basic Usage

from hindsight_client import Hindsight

client = Hindsight(
base_url="https://api.hindsight.vectorize.io",
api_key="your-api-key"
)

# Simple recall
result = client.recall(
bank_id="your-bank-id",
query="What are the user's preferences?"
)

for memory in result.results:
print(f"[{memory.type}] {memory.text}")

How It Works

When you call Recall:

  1. Query Processing - Your query is analyzed for semantic meaning, keywords, entities, and temporal references
  2. TEMPR Search - Four parallel search methods execute:
    • Semantic - Finds conceptually similar memories
    • Keyword (BM25) - Matches exact terms and phrases
    • Graph - Traverses entity relationships
    • Temporal - Handles time-based queries ("last week", "in March")
  3. Ranking - Results from all methods are fused and ordered by relevance
  4. Filtering - Optional filters are applied (type, date, etc.)
  5. Response - Top matching memories are returned

Request Parameters

ParameterTypeRequiredDescription
bank_idstringYesMemory bank to search (in URL path)
querystringYesSearch query (natural language)
typesarrayNoFilter by memory types
budgetstringNoSearch depth: "low", "mid", "high" (default: "mid")
max_tokensintegerNoMax tokens in response (default: 4096)
tracebooleanNoInclude debug trace (default: false)
query_timestampstringNoReference time for temporal queries (ISO 8601)

Response

{
"results": [
{
"id": "mem_abc123",
"text": "User prefers dark mode interfaces",
"type": "observation",
"entities": ["user"],
"context": "",
"mentioned_at": "2024-03-15T10:30:00Z"
},
{
"id": "mem_def456",
"text": "User's timezone is Pacific Standard Time",
"type": "world",
"entities": ["user"],
"context": "",
"mentioned_at": "2024-03-14T14:20:00Z"
}
],
"entities": {
"user": {
"entity_id": "ent_456",
"canonical_name": "user",
"observations": []
}
}
}
FieldDescription
resultsArray of matching memories
results[].idUnique memory identifier
results[].textThe memory text
results[].typeMemory category (world, experience, observation)
results[].entitiesEntities mentioned in the memory
results[].contextContext when the memory was formed
results[].mentioned_atWhen the memory was stored
entitiesEntity details for entities in results

Query Best Practices

Use Natural Language

memories = client.recall(
bank_id=bank_id,
query="What programming languages does the user know?"
)

Be Specific

memories = client.recall(
bank_id=bank_id,
query="What did we discuss about the project timeline in our last meeting?"
)

Ask Questions

Framing queries as questions often yields better results:

# Questions work well
memories = client.recall(query="What are the user's hobbies?")
memories = client.recall(query="When does the client prefer to have meetings?")
memories = client.recall(query="What technology stack is the project using?")

Filtering Results

By Memory Type

# Only get world facts and observations
memories = client.recall(
bank_id=bank_id,
query="Tell me about the user",
types=["world_fact", "observation"]
)

By Relevance Score

# Only highly relevant results
memories = client.recall(
bank_id=bank_id,
query="user preferences",
min_score=0.8
)

Limiting Results

# Get top 5 results
memories = client.recall(
bank_id=bank_id,
query="project requirements",
limit=5
)

Understanding Scores

The relevance score (0-1) indicates how well a memory matches your query:

Score RangeInterpretation
0.9 - 1.0Excellent match, directly relevant
0.8 - 0.9Strong match, highly relevant
0.7 - 0.8Good match, relevant
0.6 - 0.7Moderate match, somewhat relevant
< 0.6Weak match, may not be useful

Advanced Patterns

Combine query with context for better results:

context = "We're discussing the new mobile app feature"
question = "What design preferences have been mentioned?"

memories = client.recall(
bank_id=bank_id,
query=f"{context} {question}"
)

Iterative Refinement

Start broad, then narrow down:

# First, broad search
all_prefs = client.recall(query="user preferences")

# Then, specific search based on results
color_prefs = client.recall(query="preferred colors for UI design")

Combining with Retain

Build conversational memory:

# Store what the user says
client.retain(
bank_id=bank_id,
content=f"User said: {user_message}"
)

# Recall relevant context for response
context = client.recall(
bank_id=bank_id,
query=user_message,
limit=5
)

Using in the UI

The Recall view in memory banks provides a debugging interface:

  1. Navigate to your memory bank
  2. Click Recall in the sidebar
  3. Enter your search query
  4. View results with:
    • Memory content
    • Relevance scores
    • Memory types
    • Retrieval traces

This is useful for:

  • Testing query effectiveness
  • Debugging retrieval issues
  • Understanding score distributions

Token Usage

Recall operations consume tokens based on:

  • Query length
  • Number of results retrieved
  • Memory content sizes

Monitor usage on the Usage Analytics page.

Error Handling

try:
result = client.recall(bank_id=bank_id, query=query)
for memory in result.results:
print(memory.text)
except Exception as e:
print(f"Error: {e}")

Common Errors

ErrorCauseSolution
401 UnauthorizedInvalid API keyCheck your API key
402 Payment RequiredInsufficient creditsAdd credits to your account
404 Not FoundInvalid bank_idVerify the bank exists
400 Bad RequestEmpty queryProvide a search query

Performance Tips

  1. Limit results - Only request the number of memories you need
  2. Filter by type - Narrow scope when you know what you're looking for
  3. Use min_score - Filter out low-relevance matches
  4. Cache results - Store frequently-needed memories locally