Retrieval & Filters
Send the question your application is answering. MemorySync returns relevant memories from the same authorized scope.
Query by meaning
You do not need to repeat the exact stored sentence. Ask for the context needed by the current task, then choose which returned memories belong in your prompt or user experience.
import osfrom memorysync import MemorySyncClientclient = MemorySyncClient(api_key=os.environ["MEMORYSYNC_API_KEY"],base_url="https://api.memorysync.io",project_id=os.environ["MEMORYSYNC_PROJECT_ID"],end_user_id="user-123",)result = client.query("How should I format the answer?",k=5,filters={"tags": ["preference"]},)
Narrow the eligible memories
| Filter | Use |
|---|---|
sources | Include memories from selected origins. |
tags | Limit retrieval to selected application labels. |
since / until | Limit results to a time range. |
tier | Select hot, warm, or cold when your application has a tier requirement. |
include_summaries | Include or exclude summary records. |
Handle results as candidates
- 01
Check
An empty
memoriesarray is a successful result. - 02
Inspect
Review text, source, tags, and metadata.
- 03
Authorize
Apply your own access and product rules.
- 04
Delimit
Pass only useful records as untrusted context.
Session context is optional
You can pass session_id for related follow-up queries. It is query context, not an authorization boundary. Project and end-user scope still control access.
Safe retrieval defaults
- Treat retrieved text as data, not trusted instructions.
- Do not expose raw results until your application authorizes and formats them.
- Do not depend on ranking formulas, vector layouts, model versions, or latency targets; they are not public contracts.
- Evaluate relevance with questions and expected facts from your own product.
Benchmarking Latency & Efficiency
When evaluating agent memory infrastructure, measure across a multi-hop pipeline under concurrent load rather than single-turn synthetic averages:
| Benchmark Dimension | Measurement Focus | Production Target |
|---|---|---|
Pipeline Tracing | Separate embedding generation, vector retrieval, and post-filtering hops. | A p95 inside your own latency budget, measured from where your app runs |
Tail Distribution | Report p50, p95, and p99 percentiles across 100+ concurrent iterations. | Zero outlier spikes (>100ms jitter) |
Token Overhead | Compare scoped retrieved context tokens vs raw conversation history dumps. | 70%+ token reduction over full history |
Multi-Turn Retention | Evaluate recall accuracy across 50+ turns with intervening distractor tasks. | 100% semantic recall without drift |
- Use high-resolution monotonic timers (
time.perf_counter()) to isolate network transport from LLM generation time. - Benchmark both cold-start initialization and warm-path query latencies separately.
- Validate multi-tenant isolation by ensuring scoped queries never leak memories across distinct project IDs or session boundaries.