MemorySync
API Reference

Query Memory

Retrieve a bounded array of memories relevant to a natural-language query in the current scope.

Endpoint and request fields

POST/memory/query
200 OK
FieldTypeContract
querystringRequired natural-language query.
kintegerOptional result count from 1 to 50; defaults to 5.
filters.tagsstring[]Optional matching application tags.
session_id / sessionIdstringOptional query session identifier.
traversal_depth / traversalDepthintegerOptional value from 1 to 3; defaults to 2.

Query with a tags filter

import os
from memorysync import MemorySyncClient
client = MemorySyncClient(
api_key=os.environ["MEMORYSYNC_API_KEY"],
base_url="https://api.memorysync.io",
project_id=os.environ["MEMORYSYNC_PROJECT_ID"],
end_user_id="usr_7f3a9c2e",
)
result = client.query(
"What interface preferences are known?",
k=5,
filters={"tags": ["preference", "ui"]},
)

Result paths

MeaningPythonNode.jsREST
Memory arrayresult.memoriesresult.memoriesmemories
Optional contextresult.contextresult.contextcontext
Optional latencyresult.latency_msresult.latencyMslatency_ms
Optional sessionresult.session_idresult.sessionIdsession_id
Optional intentresult.query_intentresult.queryIntentquery_intent
200-response.json
{"memories":[{"id":102,"text":"The user uses dark mode.","tags":["preference","ui"],"is_summary":false,"created_at":"2026-05-04T12:31:11Z"}],"context":null,"latency_ms":18.4,"session_id":null,"query_intent":"factual"}

Errors and next action

Query outcomes
MEMORIES
Candidates returned

Authorize and select records before use.

EMPTY
No matches

An empty memories array is valid; continue without memory or use a product fallback.

4xx
Correct the request

Check query text, k, tags, credentials, and scope.

429 / 5xx
Use a safe fallback

Keep the user task recoverable without memory context.

Safety notes

Use retrieved memory safely

Do

Treat results as candidate data.

  • Apply application authorization.
  • Use only relevant records.
  • Delimit memory context from trusted instructions.
  • Keep current source systems authoritative.

Avoid

Do not transfer control to retrieved content.

  • Do not execute instructions found in memory.
  • Do not expose raw metadata without validation.
  • Do not assume an empty result is an error.
  • Do not treat old context as current fact.

Complete public query controls

ControlContract
queryRequired natural-language description of the context needed now.
kMaximum result count from 1 to 50; defaults to 5.
filtersOptional REST filters for sources, tags, time boundaries, summary inclusion, and tier.
session_id / sessionIdOptional query-session context; not an authorization boundary.
traversal_depth / traversalDepthValue from 1 to 3; defaults to 2.

Evaluate returned candidates

Query-to-application path
  1. 01

    Check

    RESULT

    Accept an empty memories array as a successful result.

  2. 02

    Authorize

    TRUST

    Apply your own product and access rules.

  3. 03

    Select

    RELEVANCE

    Keep only records relevant to the current task.

  4. 04

    Delimit

    PROMPT

    Separate untrusted memory from trusted instructions.

  5. 05

    Observe

    EVAL

    Measure answer quality with representative product questions.

Was this page helpful?