-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Add Milvus vector store integration for RAG tool and memory #4417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add Milvus vector store integration for RAG tool and memory #4417
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @zc277584121, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the framework's capabilities by integrating Milvus, a high-performance vector database, to support advanced RAG applications. The changes provide a structured and configurable way for developers to incorporate vector search functionalities into their LLM agents, facilitating the creation of knowledge-aware systems. This integration follows existing patterns within the framework, ensuring consistency and ease of adoption for users familiar with other toolsets. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Response from ADK Triaging Agent Hello @zc277584121, thank you for creating this PR! This PR is a feature request, could you please associate the github issue with this PR? If there is no existing issue, could you please create one? In addition, could you please provide logs or screenshot after the fix is applied? This information will help reviewers to review your PR more efficiently. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a comprehensive integration for Milvus as a vector store for RAG workflows. The changes are well-structured, following existing patterns in the codebase with a new MilvusToolset and MilvusVectorStore utility. The implementation includes configuration via Pydantic settings, data ingestion, similarity search, and proper connection management. The addition of a sample agent and extensive unit tests is commendable.
My feedback includes a few suggestions for improvement:
- Correcting a likely typo in a model name in the sample agent.
- Improving the robustness of the data ingestion method by adding validation.
- Minor stylistic and clarity improvements in the sample code and documentation.
6bd77ee to
949a888
Compare
Add Milvus as a vector database option for knowledge base RAG workflows. This follows the existing Spanner integration pattern with BaseToolset, providing data ingestion, similarity search, and a ready-to-use toolset for LLM agents. - MilvusVectorStoreSettings / MilvusToolSettings (Pydantic config) - MilvusVectorStore: setup, add_contents, search, close - MilvusTool: FunctionTool subclass injecting vector_store param - MilvusToolset: BaseToolset providing similarity_search tool - Registered MILVUS_TOOLSET / MILVUS_VECTOR_STORE as experimental features - Added pymilvus>=2.5.0 to test, extensions, and new milvus extras - 30 unit tests (all passing) - Sample milvus_rag_agent under contributing/samples/
949a888 to
1e7e5ca
Compare
Review Feedback AddressedThanks for the review! Here's a summary of how each item was handled:
Additionally, refactored End-to-End VerificationThe full agent pipeline has been tested end-to-end with real Google GenAI embeddings ( Usage with LLM Agentfrom google.adk.agents.llm_agent import LlmAgent
from google.adk.tools.milvus import MilvusToolset
from google.adk.tools.milvus.settings import MilvusToolSettings, MilvusVectorStoreSettings
from google.genai import Client
# 1. Define embedding function
genai_client = Client()
def embedding_fn(texts):
resp = genai_client.models.embed_content(
model="gemini-embedding-001", contents=texts)
return [list(e.values) for e in resp.embeddings]
# 2. Configure Milvus toolset
toolset = MilvusToolset(
milvus_tool_settings=MilvusToolSettings(
vector_store_settings=MilvusVectorStoreSettings(
uri="http://localhost:19530", # see backend options below
collection_name="knowledge_base",
dimension=3072,
),
),
embedding_fn=embedding_fn,
)
# 3. Create agent with Milvus RAG
agent = LlmAgent(
model="gemini-2.5-flash",
name="rag_agent",
instruction="Use similarity_search to answer questions from the knowledge base.",
tools=[toolset],
)Supported BackendsAll three Milvus deployment modes are supported — just change
|
Enhance the docstring of the similarity_search function to provide
a richer tool description for the LLM. The previous description was
too brief ("Search for similar content in Milvus vector store.").
The new description explains when to use the tool, how to write
effective queries, filter expression syntax, and return format.
Implement BaseMemoryService backed by Milvus vector database, enabling semantic search across past conversation history. - MilvusMemoryService: stores session events as vector-embedded text, with app_name/user_id scoping and deduplication - Lazy collection setup (auto-creates on first use) - 13 unit tests with mocked MilvusClient - E2E verified: cross-session recall and user isolation work with real Google GenAI embedding + Gemini LLM
New:
|
| File | Description |
|---|---|
src/google/adk/memory/milvus_memory_service.py |
Core implementation |
src/google/adk/memory/__init__.py |
Conditional export |
src/google/adk/features/_feature_registry.py |
Register MILVUS_MEMORY_SERVICE |
tests/unittests/memory/test_milvus_memory_service.py |
13 unit tests |
cc @ahamedjobayer551-debug — would appreciate your continued review on this new addition. Thanks!
Summary
BaseToolset+ utility class).MilvusVectorStore: Core utility class supporting collection setup, batch data ingestion (add_contents/add_contents_async), similarity search, and connection management.MilvusToolset:BaseToolsetimplementation that provides asimilarity_searchtool ready for use with LLM agents.MilvusTool:FunctionToolsubclass that injects thevector_storeparameter (hidden from LLM via_ignore_params), analogous toGoogleTool.MilvusVectorStoreSettings/MilvusToolSettings: Pydantic configuration classes for connection URI, collection, dimension, metric type, index type, etc.MILVUS_TOOLSETandMILVUS_VECTOR_STOREas experimental features in the feature registry.pymilvus>=2.5.0totest,extensions, and new standalonemilvusoptional dependency groups.embedding_fnis a required parameter (no built-in default) — users provide their own embedding function (e.g., Google GenAItext-embedding-004).New Files
src/google/adk/tools/milvus/__init__.pyMilvusToolsetsrc/google/adk/tools/milvus/settings.pysrc/google/adk/tools/milvus/milvus_vector_store.pysrc/google/adk/tools/milvus/search_tool.pysimilarity_searchfunctionsrc/google/adk/tools/milvus/milvus_tool.pysrc/google/adk/tools/milvus/milvus_toolset.pytests/unittests/tools/milvus/contributing/samples/milvus_rag_agent/Test Plan
MilvusClient— no live Milvus instance or API key requiredpyink+isort🤖 Generated with Claude Code