Build conversation context

POST /api/v1/projects/{id}/memory/context

Assembles conversation context from memory (default sources: episodic, semantic; include stm in enabled_sources for recent turns). The project scope is carried by the route id path parameter and the org is derived from that project. Provide a non-empty query (typically the latest user message) and the user_id whose memory to assemble.

Path parameters

  • id string Required

    Project ID

application/json

Body Required

Context build request

  • enabled_sources array[string]

    EnabledSources selects memory sources (stm, episodic, semantic, taxonomic, procedural); omitted defaults to episodic, semantic.

  • format_style string
  • include_memories boolean
  • max_tokens integer

    MaxTokens is the gross context-construction budget (not a fetch cost). After retrieval and ranking the memory server subtracts a 500-token formatting reserve, then greedily selects whole memory chunks that fit. Positive values at or below 500 leave no budget for memories. Values above 500 can still yield empty context when no chunk fits.

    Minimum value is 1.

  • metadata_filter object

    Additional properties are allowed.

  • model_type string
  • query string Required
  • query_embedding array[number]
  • session_id string
  • similarity_threshold number
  • top_k integer

    Minimum value is 1, maximum value is 200.

  • user_id string Required
  • visibility string

Responses

  • Unsupported or malformed API version, an operation unavailable in the selected published contract, or an unacceptable representation (including unsupported media-type parameters or excluded SSE). Existing authentication, authorization, and rate-limit failures take precedence.

    Hide response attributes Show response attributes object
    • badRequestDetail object

      Optional validation details defined by the standard error schema; API negotiation errors do not emit this field.

      Hide badRequestDetail attribute Show badRequestDetail attribute object
      • fields array[object]

        Fields with validation failures.

        Hide fields attributes Show fields attributes object

        A field and its validation failure.

        • description string Required

          Human-readable validation failure.

        • field string Required

          Name or path of the invalid request field.

    • detail string Required

      Human-readable error details.

    • error integer Required

      HTTP status code.

    • errorCode string Required

      Machine-readable error code.

    • parameters array[string]

      Request parameter names associated with the error; omitted when none apply.

    • reason string Required

      HTTP status reason phrase.

    Hide response attributes Show response attributes object
    • badRequestDetail object

      Optional validation details defined by the standard error schema; API negotiation errors do not emit this field.

      Hide badRequestDetail attribute Show badRequestDetail attribute object
      • fields array[object]

        Fields with validation failures.

        Hide fields attributes Show fields attributes object

        A field and its validation failure.

        • description string Required

          Human-readable validation failure.

        • field string Required

          Name or path of the invalid request field.

    • detail string Required

      Human-readable error details.

    • error integer Required

      HTTP status code.

    • errorCode string Required

      Machine-readable error code.

    • parameters array[string]

      Request parameter names associated with the error; omitted when none apply.

    • reason string Required

      HTTP status reason phrase.

  • 200

    Assembled context payload

  • 400

    Invalid request body, missing user_id/query, or top_k outside 1-200

    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
  • 401

    Missing or invalid credentials

    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
  • 403

    Caller lacks read access to the project

    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
  • 500

    Internal error

    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
  • 502

    Memory service unreachable

    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
    Hide response attributes Show response attributes object
    • code string
    • error string
    • success boolean
POST /api/v1/projects/{id}/memory/context
curl \
 --request POST 'https://agentengine.mongodb.com/api/v1/projects/{id}/memory/context' \
 --header "Authorization: $API_KEY" \
 --header "Content-Type: application/json" \
 --data '{
  "enabled_sources": [
    "string"
  ],
  "format_style": "string",
  "include_memories": true,
  "max_tokens": 42,
  "metadata_filter": {},
  "model_type": "string",
  "query": "string",
  "query_embedding": [
    42.0
  ],
  "session_id": "string",
  "similarity_threshold": 42.0,
  "top_k": 42,
  "user_id": "string",
  "visibility": "string"
}'
Request examples
{
  "enabled_sources": [
    "string"
  ],
  "format_style": "string",
  "include_memories": true,
  "max_tokens": 42,
  "metadata_filter": {},
  "model_type": "string",
  "query": "string",
  "query_embedding": [
    42.0
  ],
  "session_id": "string",
  "similarity_threshold": 42.0,
  "top_k": 42,
  "user_id": "string",
  "visibility": "string"
}
Response examples (406)
{
  "detail": "This operation is not available in API version 2026-09-20-preview.",
  "error": 406,
  "errorCode": "OPERATION_NOT_IN_API_VERSION",
  "parameters": [
    "Accept"
  ],
  "reason": "Not Acceptable"
}
{
  "detail": "This operation supports text/event-stream, which the Accept header excludes. Remove unsupported media-type parameters or accept this type with a positive q value.",
  "error": 406,
  "errorCode": "UNACCEPTABLE_MEDIA_TYPE",
  "parameters": [
    "Accept"
  ],
  "reason": "Not Acceptable"
}
{
  "detail": "The requested API version is not supported. Supported versions: 2026-09-20-preview.",
  "error": 406,
  "errorCode": "UNSUPPORTED_API_VERSION",
  "parameters": [
    "Accept"
  ],
  "reason": "Not Acceptable"
}
Response examples (406)
{
  "detail": "This operation is not available in API version 2026-09-20-preview.",
  "error": 406,
  "errorCode": "OPERATION_NOT_IN_API_VERSION",
  "parameters": [
    "Accept"
  ],
  "reason": "Not Acceptable"
}
Response examples (200)
{}
Response examples (200)
{}
Response examples (400)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (400)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (401)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (401)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (403)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (403)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (500)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (500)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (502)
{
  "code": "string",
  "error": "string",
  "success": true
}
Response examples (502)
{
  "code": "string",
  "error": "string",
  "success": true
}