Skip to main content
POST
/
memory
/
context
curl -X POST https://api.60db.ai/memory/context \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What do you know about my preferences?",
    "top_k": 8,
    "max_context_length": 2000,
    "include_timeline": true
  }'
{
  "success": true,
  "data": {
    "context": {
      "chunks": [
        {
          "chunk_id": "c_01HV...",
          "source_id": "mem_01HV8K...",
          "text": "User prefers vegetarian food, lactose intolerant",
          "score": 0.92
        }
      ],
      "sources": [
        {
          "source_id": "mem_01HV8K...",
          "title": "Dietary preferences",
          "text": "User prefers vegetarian food, lactose intolerant",
          "score": 0.92
        }
      ]
    },
    "prompt_ready": "## User Memories\n- User prefers vegetarian food, lactose intolerant",
    "message": "Context assembled from 1 memories and 0 recent events"
  }
}
Purpose-built for retrieval-augmented generation (RAG). Given a user query, the endpoint retrieves the most relevant memories, recent events, and graph relationships, then returns a pre-formatted context string ready to prepend to your LLM prompt. This is the easiest way to add memory to your AI chat. One call → formatted context.

Request

Headers

Authorization
string
required
Bearer token with your API key
Content-Type
string
required
application/json

Body

query
string
required
The user’s query. This drives retrieval.
session_id
string
Chat session ID for hierarchical session context.
top_k
integer
default:"10"
Number of memories to retrieve. Max 100.
max_context_length
integer
default:"4000"
Maximum assembled context length in tokens. Older chunks truncated if exceeded.
include_graph
boolean
default:"false"
Include knowledge-graph relationships.
include_timeline
boolean
default:"true"
Include recent events from EventStoreDB.

Response

data.prompt_ready
string
The key field — a pre-formatted context string you can prepend directly to your LLM system message.
data.context
object
Structured context with separate chunks, sources, graph_context, and timeline sections.
data.message
string
Status message (e.g., “Context assembled from 8 memories and 3 recent events”).

Complete RAG example

curl -X POST https://api.60db.ai/memory/context \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What do you know about my preferences?",
    "top_k": 8,
    "max_context_length": 2000,
    "include_timeline": true
  }'
{
  "success": true,
  "data": {
    "context": {
      "chunks": [
        {
          "chunk_id": "c_01HV...",
          "source_id": "mem_01HV8K...",
          "text": "User prefers vegetarian food, lactose intolerant",
          "score": 0.92
        }
      ],
      "sources": [
        {
          "source_id": "mem_01HV8K...",
          "title": "Dietary preferences",
          "text": "User prefers vegetarian food, lactose intolerant",
          "score": 0.92
        }
      ]
    },
    "prompt_ready": "## User Memories\n- User prefers vegetarian food, lactose intolerant",
    "message": "Context assembled from 1 memories and 0 recent events"
  }
}

Billing

Flat **0.0005perqueryslightlyhigherthan/memory/searchbecausecontextassemblyalsoformatsanLLMreadypromptwithrecenteventsandoptionalgraphcontext.Achatapplicationdoing1,000turns/daycostsabout0.0005 per query** — slightly higher than `/memory/search` because context assembly also formats an LLM-ready prompt with recent events and optional graph context. A chat application doing 1,000 turns/day costs about 15/month. Response headers:
HeaderMeaning
x-credit-balanceWallet balance after this charge
x-credit-charged0.000500
x-billing-txAudit row UUID
If the memory service is unreachable and the endpoint returns the graceful-degradation empty context (see below), you are not charged — the auto-refund guard reverses the deduction.
See Pricing & Billing for the full rate card.

Graceful degradation

If the Memory service is unavailable, /memory/context returns prompt_ready: "" instead of failing. Your application can continue with no context — the SLM chat will still work, just without memory-grounded responses.
No-context response
{
  "success": true,
  "data": {
    "context": { "chunks": [], "sources": [] },
    "prompt_ready": "",
    "message": "Memory system not ready — no context assembled"
  }
}
Best practice: Always check if prompt_ready is non-empty before prepending it.