Best Practices
Learn effective patterns for using HyperSpark Memory. From tool selection to Decision Intelligence workflows.
Choosing the Right Tool
Use remember when:
Use ingest when:
Decision Intelligence Workflow
Search for Precedents
Before deciding, check if similar decisions were made before.
// Search for similar past decisions
const precedents = await find_precedent({
situation: "Customer requesting 20% discount on annual plan",
outcomeWanted: "successful",
topK: 5
});Log the Decision
Record your decision with full context and the memories that informed it.
// Log the decision with context
await log_decision({
action: "approved_20pct_discount",
context: "Customer requested discount. 3-year customer, no support issues.",
rationale: "Long-term loyalty justifies retention discount.",
memoriesConsidered: ["mem_abc123", "mem_def456"], // From precedent search
setsPrecedent: true,
policyApplied: "retention_discount_policy"
});Update the Outcome
When you know the result, update the decision for future reference.
// Later, when outcome is known
await update_decision_outcome({
decisionId: "mem_xyz789",
outcome: "successful",
outcomeNotes: "Customer renewed. Revenue retained: $2,400/year.",
outcomeMetrics: {
revenue_retained: 2400,
customer_ltv_years: 4
}
});Multi-Tenant Patterns
Create a tenant when:
Don't create tenants for:
// Always pass tenantId for tenant operations
await recall({
query: "customer preferences",
tenantId: "tenant_acme_corp", // Scopes to this tenant
topK: 10
});Rate Limit Handling
When you hit your query limit, the API returns a 429 response with helpful headers:
// Response headers on rate limit
{
"X-Usage-Limit": "8000",
"X-Usage-Used": "8000",
"X-Usage-Remaining": "0",
"X-Usage-Reset": "2025-02-01T00:00:00Z"
}
// Response body
{
"success": false,
"error": "Query limit exceeded",
"code": "LIMIT_EXCEEDED",
"resetAt": "2025-02-01T00:00:00Z",
"upgradeUrl": "/dashboard/billing"
}Best Practices:
Common Mistakes to Avoid
Skipping get_context means the AI has no memory of who the user is.
Wrong:
Jump straight into the task without context
Right:
Call get_context first, then proceed
Semantic search is slower and uses embeddings. For "what happened recently?", use the faster option.
Wrong:
recall({ query: "recent activity" })Right:
recall_recent({ since: "7d" })Decisions logged as "pending" without outcome updates don't build useful precedent data.
Tip: Set revisitAfter when logging decisions to remind yourself to update the outcome later.
Without tenantId, operations use the parent org's memory space, not the tenant's.
Wrong:
recall({ query: "..." }) // No tenantIdRight:
recall({
query: "...",
tenantId: "tenant_xxx"
})Ready to build?
Check out our quickstart guide or dive into the full API reference.