Long-term memory per user, millions of tenants
Short-term memory lives in the context window; long-term memory lands here as rows: millions of tenants per collection via partition key, or 65,536 collections for separate schemas.
Milvus is an open-source database for AI agents: long-term memory for millions of tenants, RBAC, hybrid search, grep and MCP. Row-level security is available only in Zilliz Cloud enterprise edition.
Short-term memory lives in the context window; long-term memory lands here as rows: millions of tenants per collection via partition key, or 65,536 collections for separate schemas.
RBAC gives each agent or tool its own role. Row-level security is available only in Zilliz Cloud enterprise edition.
Combine dense and BM25 retrieval with regex, LIKE, and phrase filters, then rerank, in one request.
Use agent_id, user_id or session_id as the partition key to organize millions of tenants in one collection. Include the tenant filter on every request. Episodic, semantic and procedural memories can use a type field; separate collections when schemas or permission boundaries differ.
Open-source Milvus provides users, roles and privileges at instance, database and collection levels. Row-level security is available only in Zilliz Cloud enterprise edition; a partition key is not an authorization mechanism.
Agents need meaning and exact strings: error codes, file paths, order numbers. Regex filters run alone or inside hybrid search.
Milvus is the agent memory layer under the frameworks agents already use; an MCP server for agents lets Claude Desktop or Cursor query it directly.
| Agent requirement | Milvus capability | Availability |
|---|---|---|
| Long-term memory per user at million scale (multi-tenant agent database) | Partition key: millions of tenants per collection | Open source |
| Separate schema or role per tenant | Collection or database per tenant: 65,536 / 64 by default | Open source |
| Least-privilege access per agent or tool | RBAC: roles, built-in and custom privilege groups | Open source |
| One service account, many end users (row-level security) | Row-level security bound to the caller | Zilliz Cloud (enterprise) |
| Semantic + exact-string recall | Hybrid search with regex, LIKE, TEXT_MATCH filters | Open source, Milvus 3.0+ |
Sources: milvus.io/docs multi_tenancy, rbac, privilege_group, multi-vector-search, pattern-matching.
Recall one user's memories that match a regex, ranked by dense and BM25 retrieval fused with RRF.
from pymilvus import MilvusClient, AnnSearchRequest, RRFRanker
client = MilvusClient(uri="http://localhost:19530", token="root:Milvus")
question = "what did we promise about the refund?"
scope = 'user_id == "u42" and content =~ "(?i)refund.*order [0-9]+"'
# embed() stands for your embedding model; it returns a list of floats.
dense = AnnSearchRequest(data=[embed(question)], anns_field="dense",
param={}, limit=20, expr=scope)
# BM25 sparse field generated from content: pass the raw query text.
sparse = AnnSearchRequest(data=[question], anns_field="sparse",
param={}, limit=20, expr=scope)
hits = client.hybrid_search(
collection_name="agent_memory",
reqs=[dense, sparse],
ranker=RRFRanker(),
limit=5,
output_fields=["content"],
)Assumes user_id as the partition key, a VARCHAR content field, a dense vector field, and a BM25 sparse field. Add an NGRAM index on content to speed up the regex. Code requires a running server and your own embedding model; it is an example, not a benchmark.
One that isolates memory per user at scale, enforces permissions in the database and answers semantic and exact-string queries. Milvus does all three open source; Zilliz Cloud adds row-level security.
Stateful agents need a system of record and a memory layer. Keep orders and billing in your transactional database; put memories, documents and tool results in Milvus, with tenant-scoped hybrid search and per-row expiry built in.
Short-term vs long-term agent memory: short-term is the context window and ends with the session; long-term persists across sessions as rows, an embedding plus user_id, timestamp, memory type (episodic, semantic, procedural) and source, recalled by tenant-scoped hybrid search.
Three ways: upsert replaces a memory by primary key, Entity TTL (Milvus 3.0+) expires rows on a schedule, and delete by filter erases everything for one user_id, honoring a deletion request.
Scope data, not prompts: a partition key per tenant, RBAC roles per agent or tool, and on Zilliz Cloud row-level security filtering every read and write by caller, so a prompt injection cannot widen the scope.
No. RAG retrieves shared documents the agent did not write; memory is per user, written by the agent as it runs. Milvus holds both with the same hybrid search and filters.
Start with the Quickstart, give each agent or user a partition key and a role, plug in Mem0 or MCP, then move the same code to a cluster or Zilliz Cloud.