The architecture
Prerequisites
- Working app with authentication and a customer/tenant concept
- Memic project with at least one environment
- Python 3.10+ (examples use FastAPI)
pip install memic fastapi uvicorn
Step 1 — Provisioning
See the Per-customer isolation recipe for provisioning code. At the end, every customer row in your DB has amemic_api_key_encrypted column.
Step 2 — Document upload endpoint
Let customers upload their own files:Step 3 — Status polling endpoint
Customers need to know when their file is searchable:Step 4 — Chat endpoint
The core of the RAG experience:- The system prompt lives in Memic, not in your code. You can tune the assistant’s persona from the dashboard without shipping new code.
memicis scoped to the current customer viaDepends(get_memic_client). Search, chat, prompts — everything is automatically tenant-isolated.
Step 5 — Frontend integration
Your frontend calls your backend (/documents, /chat) the same as it
would any other API. It doesn’t know Memic exists. Memic is an
implementation detail of your backend, not a direct frontend dependency.
Testing
At minimum, test:- Isolation — upload a file as Customer A, query as Customer B, assert zero results
- Prompt rendering — fetch
chatbot-system, render with a fakecompany_name, assert the output contains the company name - End-to-end chat — upload a known file, wait for
ready, chat, assert the answer references the file
What’s next?
- Rate limiting your API — even though Memic has its own rate limits, add your own limits per customer to prevent abuse
- Usage tracking — log Memic calls per customer so you can bill or monitor usage
- Caching — for frequently-repeated queries, add a Redis cache in front of Memic
- Observability — instrument the Memic calls with OpenTelemetry so you can trace end-to-end latency
Related
Per-customer isolation
Deep dive on the isolation pattern.
Production checklist
Before going live.