Assembles conversation context from an explicit, per-source-configured set of sources — each source declares its own retrieval mode (text, semantic, hybrid), metadata filter, and candidate count. Results are merged and de-duplicated across sources, optionally reranked, then formatted and budgeted like build_context. The project scope is carried by the route id path parameter and the org is derived from that project. Provide a non-empty query, the user_id whose memory to assemble, and a non-empty sources list.
Body
Required
Per-source context build request
-
MaxTokens is the gross context-construction budget (not a fetch cost), interpreted like build_context: the server subtracts a 500-token formatting reserve, then greedily selects whole memory chunks that fit.
Minimum value is
1. -
Rerank reorders the merged results by a relevance rerank when available.
-
Sources is the explicit, per-source-configured set to search; the memory server enforces the count bounds (1..MAX_CONTEXT2_SOURCES), each source's top_k bounds, and the no-duplicate-source rule.
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.
-
Assembled context payload with per-source metadata
-
Invalid request body or missing user_id/query/sources
-
Missing or invalid credentials
-
Caller lacks read access to the project
-
Internal error
-
Memory service unreachable
curl \
--request POST 'https://agentengine.mongodb.com/api/v1/projects/{id}/memory/retrieval/context-from-sources' \
--header "Authorization: $API_KEY" \
--header "Content-Type: application/json" \
--data '{
"format_style": "string",
"include_memories": true,
"max_tokens": 42,
"model_type": "string",
"query": "string",
"query_embedding": [
42.0
],
"rerank": true,
"session_id": "string",
"sources": [
{
"metadata_filter": {},
"mode": "string",
"source": "string",
"top_k": 42
}
],
"user_id": "string",
"visibility": "string"
}'
{
"format_style": "string",
"include_memories": true,
"max_tokens": 42,
"model_type": "string",
"query": "string",
"query_embedding": [
42.0
],
"rerank": true,
"session_id": "string",
"sources": [
{
"metadata_filter": {},
"mode": "string",
"source": "string",
"top_k": 42
}
],
"user_id": "string",
"visibility": "string"
}
{
"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"
}
{
"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"
}
{}
{}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}