Neurophic
Memory

Get prompt context

Learn about how to get a prompt-ready block of relevant memories

Context is the read to make before a model call. Send what the user is asking about and get back a short block of the most relevant memories, formatted for a system prompt.

POST/v1/contexthttps://api.neurophic.ai

Request

identifier
string required 1-500 characters
Your end-user id.
query
string required 1-2,000 characters
What to search for. 1-2,000 characters.

Note

For query, use the user's latest message or a short summary of it. The search is by meaning and by keywords, so a plain sentence works better than a list of terms.

Response

200Success
result
string required
Up to five lines, each - <content> (memory|pattern|recent). Empty string when nothing is relevant.

Failures return one of the errors listed under API reference > Errors.

{
  "result": "- Prefers window seats and vegetarian meals on long flights. (memory)\n- Travels to Lisbon most months for work. (pattern)\n- Asked about upgrading to business class on the next trip. (recent)"
}

Tip

When nothing is relevant, result is the empty string "", unlike Retrieve, which returns "No relevant memories found.". Check for an empty string before adding the block to your prompt.

Note

Context lines carry no ids and no causal links between memories. To fetch or delete a specific memory, use Retrieve with format: "json", which returns ids.

Example

import { Neurophic } from 'neurophic';

const client = new Neurophic({ apiKey: process.env.NEUROPHIC_API_KEY });

const { result } = await client.context({
  identifier: 'user-123',
  query: 'help me book a flight to Lisbon',
});

const base = 'You are a travel assistant.';
const system = result
  ? `${base}\n\n## What you know about this user\n${result}`
  : base;