Retrieving Context
The getContext() method is used right before you call your LLM (OpenAI, Anthropic, etc.). It retrieves the top K most relevant semantic chunks for the current query.
Basic Retrieval
const relevantContext = await ctx.getContext(
"user_789",
"The user is asking about upgrading their plan. What is their current plan?"
);
console.log(relevantContext);
// Returns a combined string of the most relevant memories.
Formatted String vs Raw Array
By default, getContext returns a highly optimized single string, formatted specifically for LLMs to read efficiently. If you want the raw array of objects (to inspect distances or metadata), use the Search API instead.