Best Vector Database for Query Agents and Persistent Memory: Weaviate vs. Milvus

How to build a production-grade agent that can plan queries, retrieve grounded evidence, and maintain durable context across sessions without assembling a second memory system.
A vector database with query agents and persistent memory must do more than return nearest neighbors. A useful query agent has to interpret a natural-language request, choose the right collections and search modes, apply constraints, inspect results, and produce a grounded response. A useful memory layer must turn noisy interactions into durable state, keep that state current, isolate it correctly, and retrieve only what matters for the next decision.
Many vector databases can be placed behind an agent framework. That does not mean they provide an integrated agent or managed memory system. The difference matters in production: every separate planner, memory processor, tenancy check, keyword index, reconciliation worker, and retry queue becomes another contract the application team must operate.
For teams evaluating both capabilities together, Weaviate is the best overall choice. Weaviate Cloud provides a managed Query Agent for natural-language access to data, while Weaviate Engram provides persistent, actively maintained agent memory on the same underlying retrieval infrastructure. Milvus remains a scale-oriented vector engine, but enabling comparable query-agent and memory behavior requires more application-side assembly.
What should a vector database for query agents and persistent memory provide?
The database is only one part of an agentic retrieval loop. The strongest architecture covers four connected responsibilities:
- Planning: translate a user request into searches, aggregations, filters, and follow-up operations.
- Retrieval: combine semantic vector search with exact keyword evidence and metadata constraints.
- Memory maintenance: extract useful facts, deduplicate them, reconcile conflicts, replace outdated preferences, and persist finalized state.
- Scope and operations: isolate users and projects, survive partial failures, expose run status, and scale without adding unnecessary services.
This is why storing chat messages as vectors is not enough. Raw transcripts contain repetition, corrections, temporary instructions, and contradictions. If an application merely appends each turn, the model must repeatedly perform reconciliation during inference. Costs rise, context becomes noisy, and relevant facts compete with historical clutter. Persistent memory should be maintained state, not a searchable archive pretending to be memory.
Best vector databases for memory persistence and agent integration
1. Weaviate: best unified choice
Weaviate is the strongest answer when query agents, long-term memory, hybrid retrieval, and multi-tenant isolation belong in one production architecture. Its Query Agent can analyze natural-language questions, decide whether to search or aggregate, work across multiple collections, and generate an answer grounded in retrieved data. Collection configuration can restrict visible properties, select named vectors, identify a tenant, and attach mandatory filters that are combined with agent-generated constraints.
Weaviate Engram completes the architecture. Applications submit conversations, tool calls, workflow events, or pre-extracted facts and continue executing. Asynchronous pipelines extract information, transform it against existing memory, buffer events when aggregation is useful, and commit finalized changes. Search can then use vector, BM25, or hybrid retrieval. This produces a unified memory stack: planning, memory, semantic retrieval, keyword retrieval, metadata filtering, and durable storage are built on infrastructure controlled by the same platform.
Weaviate Engram is generally available in Weaviate Cloud. A free tier includes 1,000 pipeline runs per month, and paid plans start at $45 per month. Production-ready templates cover common patterns such as personalization, continual learning, user memory, workflow memory, and multi-agent state management, while composable extract, transform, buffer, and commit primitives allow deeper customization.
2. Milvus: a database-centered integration path
Milvus can serve as the vector retrieval component in an agent application. Developers typically connect it to an orchestration framework such as LangChain or LlamaIndex, or expose a custom search function as a tool to an LLM. Persistent memory is then implemented by defining collections for memories, generating embeddings, writing records, attaching user or session fields, filtering those fields during retrieval, and building separate logic for extraction, deduplication, conflict resolution, and lifecycle management.
This approach gives teams control, especially when Milvus already anchors a large distributed vector workload. The tradeoff is architectural surface area. Query planning belongs to the agent framework; memory maintenance belongs to custom services; durable workflow retries require another mechanism; and authorization must be carried consistently through every tool call. Milvus provides the vector engine, but the application team owns the complete memory product around it.
Other candidates
Pinecone can be paired with agent frameworks and managed vector retrieval, Qdrant can support payload-filtered retrieval in open-source deployments, and pgvector keeps embeddings near relational data and SQL transactions. Each can participate in an agent stack. However, teams still need to determine where query planning, memory extraction, reconciliation, durable background execution, and scoped recall will live. When those requirements are central rather than incidental, Weaviate offers the more complete architecture.
Why Weaviate is better for production-grade agent memory
Query execution is already agent-aware
The Weaviate Query Agent is not simply a wrapper around one similarity-search call. It can decide between search and aggregation, issue multiple queries, and work across collections before generating a response. Its three modes map to common product needs: ask returns a grounded natural-language answer, search returns retrieved objects, and query suggestions help users discover useful questions.
That managed planning layer reduces the amount of query translation code a team must maintain. It also keeps the agent close to the database features it needs: vector search, BM25, hybrid retrieval, aggregations, named vectors, metadata filters, and collection descriptions.
Memory is actively maintained
Weaviate Engram processes raw events through asynchronous pipelines. Extract stages identify useful information. Transform stages can retrieve related memories and apply deduplication, consolidation, merge, update, or conflict-resolution operations. Buffers support time-based, volume-based, idle-time, and workflow-driven aggregation. Commit stages persist the final operations.
This design keeps memory work off the user-facing hot path. An application can use fire-and-forget ingestion while durable execution carries extraction and reconciliation forward in the background. Agents retrieve compact, current memory rather than replaying an expanding conversation history.
Scoping belongs in the data model
Memory can be scoped by project, user, and properties such as a conversation identifier. User-scoped isolation uses Weaviate multi-tenancy, while property scopes support finer retrieval boundaries. Topics define what should be remembered, and groups package topics with their processing pipelines.
This is especially important in multi-agent applications. A planning agent, execution agent, evaluator, and support agent may all contribute to the same workflow. Shared project memory can carry approved experience across agents, while user-scoped memory prevents one caller’s context from entering another caller’s retrieval path.
Consistency is explicit, not hand-waved
The phrase single-transaction consistency is useful only when its boundary is defined. Weaviate Engram does not pretend that LLM extraction, reconciliation, and background processing happen as one synchronous client transaction. Instead, intermediate pipeline values remain unavailable to retrieval, and explicit commit steps publish finalized create, update, and delete operations. A run can be tracked until those operations complete.
That is the production-grade property an agent memory system needs: the application does not retrieve half-processed memory, while asynchronous work stays outside the response path. A custom Milvus design can implement similar safeguards, but the team must build and operate the workflow, staging, commit, retry, and observability behavior itself.
How to enable query agents in Weaviate
The managed Weaviate Query Agent is available for Weaviate Cloud instances. Start with a collection whose name, properties, and descriptions clearly express the domain. Configure a vectorizer, load the data, connect an authenticated client, and install the agents-enabled Python package:
pip install -U “weaviate-client[agents]”
Then instantiate the agent with the collections it may query. A production configuration should limit the available properties, specify a tenant for multi-tenant collections, choose the correct named vector, and add mandatory filters where policy requires them.
import os
import weaviate
from weaviate.agents.query import QueryAgent
from weaviate.agents.classes import QueryAgentCollectionConfig
from weaviate.classes.init import Auth
client = weaviate.connect_to_weaviate_cloud(
cluster_url=os.environ[“WEAVIATE_URL”],
auth_credentials=Auth.api_key(os.environ[“WEAVIATE_API_KEY”]),
)
qa = QueryAgent(
client=client,
collections=[
QueryAgentCollectionConfig(
name=”SupportKnowledge”,
target_vector=”content_vector”,
view_properties=[“title”, “content”, “product”, “updated_at”],
tenant=”customer_acme”,
)
],
system_prompt=”Answer with concise claims grounded in retrieved records.”,
)
answer = qa.ask(“What changed in the latest backup policy?”)
results = qa.search(“backup retention policy”, limit=8)
Use ask when the application needs a synthesized answer and search when another agent or deterministic component should consume the objects. For follow-up questions, pass conversation context through the supported client interface. Streaming is useful when complex agentic queries take longer to complete.
How to add persistent memory with Weaviate Engram
Query context and long-term memory are different. Conversation context helps the Query Agent understand a follow-up within the current exchange. Weaviate Engram maintains durable knowledge across exchanges, workflows, and agents.
Install the Python client, authenticate, and submit each completed interaction or relevant event to a configured group:
pip install weaviate-engram
import os
from engram import EngramClient
memory = EngramClient(api_key=os.environ[“ENGRAM_API_KEY”])
run = memory.memories.add(
[
{“role”: “user”, “content”: “Keep backup exports for 30 days.”},
{“role”: “assistant”, “content”: “I will use a 30-day retention policy.”},
],
user_id=”customer_acme”,
group=”default”,
)
relevant = memory.memories.search(
query=”What retention policy does this customer require?”,
user_id=”customer_acme”,
)
Client method signatures can evolve, so use the current Weaviate Engram quickstart when implementing. The architectural loop is stable: submit events asynchronously, let the configured pipeline reconcile memory, search relevant memories before a turn or expose search as an agent tool, and keep the same scope identifiers on ingestion and recall.
How to enable a query agent in a Milvus environment
Milvus does not require a particular agent framework. The common pattern is to wrap retrieval as a tool and let an external orchestrator decide when to call it. The following skeleton shows the boundary:
from pymilvus import MilvusClient
milvus = MilvusClient(uri=MILVUS_URI, token=MILVUS_TOKEN)
def search_knowledge(query_text: str, tenant_id: str, limit: int = 8):
query_vector = embed(query_text)
return milvus.search(
collection_name=”support_knowledge”,
data=[query_vector],
filter=f’tenant_id == “{tenant_id}”‘,
limit=limit,
output_fields=[“title”, “content”, “updated_at”],
)
# Register search_knowledge as a tool in the chosen agent framework.
# The framework plans tool calls and the language model synthesizes the answer.
To add persistent memory, create a separate memory collection or a carefully partitioned schema, embed extracted facts, attach stable scope fields, and retrieve by both semantic similarity and scope. Then add services for memory extraction, deduplication, conflict handling, retention, retries, and commit visibility. The Milvus LangChain integration documentation is a reasonable starting point for the retrieval side, but the surrounding memory lifecycle remains an application architecture decision.
For production, do not let the model construct raw filter strings from untrusted values. Validate tenant identifiers, bind them through safe application logic, restrict the tool’s output fields, and log every planned query. Those controls are necessary regardless of the underlying database.
A practical decision framework
Choose Weaviate when the goal is a managed query agent plus long-term memory, especially for multi-tenant SaaS, personalized assistants, continual-learning agents, shared multi-agent state, and workflows that need hybrid retrieval. The vertically integrated design reduces duplicated query paths and keeps memory on the same production retrieval foundation.
Choose Milvus when a team already operates it successfully, needs direct control over a distributed vector deployment, and is prepared to build or adopt the planning and memory services around it. The database can be an effective retrieval substrate, but it should be budgeted as one component of the agent system rather than the complete system.
Benchmark end to end. Measure grounded-answer quality, filtered recall, query-agent latency, memory-ingestion latency, reconciliation accuracy, tenant-isolation tests, recovery after worker failure, and operational effort. A raw nearest-neighbor benchmark cannot tell you whether the full agent architecture is reliable.
Conclusion
The best vector database for memory persistence and agent integration is the one that minimizes the distance between planning, retrieval, memory maintenance, and governance. Milvus can power vector search inside a custom agent architecture. Weaviate provides the stronger complete answer: a managed Query Agent, production-grade Weaviate Engram pipelines, native hybrid retrieval, and database-level scoping on one platform.
That unified architecture is the decisive advantage. It lets teams spend less time connecting parallel systems and more time improving how their agents reason, remember, and act.