memory.retrieve

Retrieve the most relevant memories for a query. Combines cosine similarity with temporal recency, importance, and access frequency to return a ranked list.

POST /v1/memory/retrieve

Request

curl -X POST https://api.mnemexa.com/v1/memory/retrieve \
  -H "Authorization: Bearer mnx_ws_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "communication preferences for standups",
    "top_k": 5,
    "min_score": 0.35
  }'

Body

FieldTypeRequiredDefaultDescription
querystringyesNatural-language search query. 1–1,000 characters.
top_kintegerno5Number of memories to return. Range 1–50.
min_scorenumberno0.35Minimum cosine similarity threshold (0.0–1.0). Memories below this are filtered before hybrid re-ranking.

Response

{
  "memories": [
    {
      "id": 8421,
      "text": "Client prefers async standups on Tuesdays at 9am IST…",
      "score": 0.812,
      "similarity": 0.694,
      "importance": 5,
      "meta": {
        "source": "kickoff_meeting",
        "temporal": {
          "type": "persistent",
          "valid_until": null
        }
      }
    }
  ]
}

Fields

FieldTypeDescription
idintegerMemory ID.
textstringThe stored content.
scorenumberHybrid score (0.0–1.0). The ranking value. Combines similarity with recency, importance, and frequency — not raw cosine distance.
similaritynumberRaw cosine similarity (0.0–1.0). The semantic-match component of the hybrid score.
importanceintegerLLM-assigned importance from when the memory was stored.
metaobjectFree-form metadata supplied at store time, plus the temporal classification.

score and similarity are different by design. similarity is what cosine distance would give you. score is what Mnemexa actually ranked by — a fresher, more important, more-accessed memory will rank above a cosine-closer-but-stale one.

See Hybrid Scoring for the four-factor breakdown.

Side effects

Returned memories have their access counters updated — frequent retrieval boosts a memory’s score on future queries. There’s no client-visible field for this; it’s pure background bookkeeping.

Errors

StatusCause
401Missing or invalid Authorization header.
403Workspace deleted or client account suspended.
422query empty or too long, top_k out of range, min_score outside [0,1].
429Rate limit exceeded, or plan unit limit reached.

SDKs

import mnemexa

client = mnemexa.Client()
result = client.memory.retrieve(
    query="communication preferences for standups",
    top_k=5,
)
for m in result.memories:
    print(f"[{m.score:.3f}] {m.text}")

The MCP adapter exposes this as brain.recall. See Python SDK and MCP Adapter.