Skip to content

feat(rag): add Milvus provider#6503

Open
zc277584121 wants to merge 1 commit into
crewAIInc:mainfrom
zc277584121:add-milvus-rag-client
Open

feat(rag): add Milvus provider#6503
zc277584121 wants to merge 1 commit into
crewAIInc:mainfrom
zc277584121:add-milvus-rag-client

Conversation

@zc277584121

Copy link
Copy Markdown

Summary

  • Add a Milvus RAG provider backed by pymilvus.MilvusClient.
  • Wire MilvusConfig into the RAG config/factory path and add a milvus optional extra.
  • Cover real Milvus Lite behavior, schema validation, metadata filtering, score ordering, and provider docs.

Tests

  • gh pr list --repo crewAIInc/crewAI --state all --search milvus
  • gh issue list --repo crewAIInc/crewAI --state all --search milvus
  • uv lock
  • uv run --extra milvus ruff check lib/crewai/src/crewai/rag/milvus lib/crewai/src/crewai/rag/config lib/crewai/src/crewai/rag/factory.py lib/crewai/tests/rag/milvus lib/crewai/tests/rag/config/test_factory.py lib/crewai/tests/rag/config/test_optional_imports.py
  • uv run --extra milvus mypy lib/crewai/src/crewai/rag/milvus lib/crewai/src/crewai/rag/config lib/crewai/src/crewai/rag/factory.py
  • uv run --extra milvus pytest lib/crewai/tests/rag/milvus lib/crewai/tests/rag/config/test_factory.py lib/crewai/tests/rag/config/test_optional_imports.py lib/crewai/tests/rag/test_client_factory_registry.py -q
  • uv run --extra milvus pytest lib/crewai/tests/knowledge/test_knowledge_storage_integration.py lib/crewai/tests/rag/test_error_handling.py -q
  • git diff --check

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 887b8a16-71bb-452f-8c37-f086a26251a8

📥 Commits

Reviewing files that changed from the base of the PR and between 8c3c2e6 and 4b2b4c3.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (21)
  • docs/edge/ar/concepts/knowledge.mdx
  • docs/edge/en/concepts/knowledge.mdx
  • lib/crewai/pyproject.toml
  • lib/crewai/src/crewai/rag/config/optional_imports/base.py
  • lib/crewai/src/crewai/rag/config/optional_imports/protocols.py
  • lib/crewai/src/crewai/rag/config/optional_imports/providers.py
  • lib/crewai/src/crewai/rag/config/optional_imports/types.py
  • lib/crewai/src/crewai/rag/config/types.py
  • lib/crewai/src/crewai/rag/factory.py
  • lib/crewai/src/crewai/rag/milvus/__init__.py
  • lib/crewai/src/crewai/rag/milvus/client.py
  • lib/crewai/src/crewai/rag/milvus/config.py
  • lib/crewai/src/crewai/rag/milvus/constants.py
  • lib/crewai/src/crewai/rag/milvus/factory.py
  • lib/crewai/src/crewai/rag/milvus/types.py
  • lib/crewai/src/crewai/rag/milvus/utils.py
  • lib/crewai/tests/rag/config/test_factory.py
  • lib/crewai/tests/rag/config/test_optional_imports.py
  • lib/crewai/tests/rag/milvus/__init__.py
  • lib/crewai/tests/rag/milvus/test_client.py
  • lib/crewai/tests/rag/milvus/test_config.py
✅ Files skipped from review due to trivial changes (5)
  • lib/crewai/tests/rag/milvus/init.py
  • lib/crewai/src/crewai/rag/milvus/factory.py
  • lib/crewai/src/crewai/rag/config/optional_imports/types.py
  • lib/crewai/src/crewai/rag/milvus/constants.py
  • lib/crewai/src/crewai/rag/milvus/init.py
🚧 Files skipped from review as they are similar to previous changes (15)
  • lib/crewai/tests/rag/milvus/test_config.py
  • lib/crewai/tests/rag/config/test_factory.py
  • lib/crewai/src/crewai/rag/milvus/config.py
  • lib/crewai/src/crewai/rag/config/optional_imports/base.py
  • lib/crewai/src/crewai/rag/factory.py
  • lib/crewai/tests/rag/config/test_optional_imports.py
  • lib/crewai/src/crewai/rag/config/optional_imports/providers.py
  • docs/edge/en/concepts/knowledge.mdx
  • lib/crewai/pyproject.toml
  • lib/crewai/src/crewai/rag/config/types.py
  • docs/edge/ar/concepts/knowledge.mdx
  • lib/crewai/src/crewai/rag/config/optional_imports/protocols.py
  • lib/crewai/src/crewai/rag/milvus/types.py
  • lib/crewai/src/crewai/rag/milvus/client.py
  • lib/crewai/tests/rag/milvus/test_client.py

📝 Walkthrough

Walkthrough

Added Milvus as a RAG vector-store provider, including configuration, optional dependency handling, factory dispatch, synchronous and asynchronous client operations, schema and filtering utilities, tests, and English/Arabic documentation.

Changes

Milvus RAG integration

Layer / File(s) Summary
Provider contracts and configuration
lib/crewai/pyproject.toml, lib/crewai/src/crewai/rag/config/..., lib/crewai/src/crewai/rag/milvus/types.py, lib/crewai/src/crewai/rag/milvus/config.py, lib/crewai/src/crewai/rag/milvus/constants.py
Adds the Milvus optional dependency, provider types, missing-provider handling, configuration defaults, embedding protocols, and connection parameters.
Milvus client and data operations
lib/crewai/src/crewai/rag/milvus/client.py, lib/crewai/src/crewai/rag/milvus/utils.py
Implements collection lifecycle, document upserts, synchronous and asynchronous search, schema validation, metadata filters, score normalization, result conversion, deletion, and reset operations.
Factory dispatch and provider loading
lib/crewai/src/crewai/rag/factory.py, lib/crewai/src/crewai/rag/milvus/factory.py
Routes Milvus configurations to a factory that creates the PyMilvus client wrapper.
Milvus integration and configuration tests
lib/crewai/tests/rag/config/..., lib/crewai/tests/rag/milvus/...
Tests provider dispatch, missing-dependency errors, default and custom configuration, Milvus Lite operations, async behavior, schemas, filtering, and scoring.
RAG provider documentation
docs/edge/en/concepts/knowledge.mdx, docs/edge/ar/concepts/knowledge.mdx
Documents Milvus support, Milvus Lite defaults, remote connection options, and Milvus operation examples.

Sequence Diagram(s)

sequenceDiagram
  participant RAGConfig
  participant RAGFactory
  participant MilvusFactory
  participant MilvusClient
  participant Milvus

  RAGConfig->>RAGFactory: select provider "milvus"
  RAGFactory->>MilvusFactory: require Milvus factory
  MilvusFactory->>Milvus: create pymilvus client
  MilvusFactory->>MilvusClient: wrap client and embedding function
  MilvusClient->>Milvus: create collection and upsert documents
  MilvusClient->>Milvus: search vectors with filters
  Milvus-->>MilvusClient: return search hits
  MilvusClient-->>RAGFactory: return SearchResult values
Loading

Suggested reviewers: alex-clawd

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a Milvus RAG provider.
Description check ✅ Passed The description is directly related to the changeset and accurately summarizes the Milvus provider, config, docs, and tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: Cheney Zhang <chen.zhang@zilliz.com>
@zc277584121 zc277584121 force-pushed the add-milvus-rag-client branch from 8c3c2e6 to 4b2b4c3 Compare July 10, 2026 01:02

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/crewai/src/crewai/rag/milvus/types.py (1)

35-43: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

any_schema() accepts non-callable values for the embedding function field.

MilvusEmbeddingFunctionWrapper.__get_pydantic_core_schema__ returns core_schema.any_schema(), which means Pydantic will accept any value — including non-callables like 42 or None — for the embedding_function config field. This creates a gap between the type annotation (which expects an EmbeddingFunction) and runtime validation. If config is loaded from a file (YAML/JSON), invalid values would pass validation and only fail later with a confusing TypeError when the client invokes the function.

Consider using core_schema.callable_schema() or a custom validator to at least ensure the value is callable.

♻️ Proposed refactor
 class MilvusEmbeddingFunctionWrapper(EmbeddingFunction):
     """Base class for Milvus embedding functions used by Pydantic validation."""

     `@classmethod`
     def __get_pydantic_core_schema__(
         cls, _source_type: Any, _handler: GetCoreSchemaHandler
     ) -> CoreSchema:
         """Generate Pydantic core schema for Milvus embedding functions."""
-        return core_schema.any_schema()
+        return core_schema.callable_schema()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai/src/crewai/rag/milvus/types.py` around lines 35 - 43, Update
MilvusEmbeddingFunctionWrapper.__get_pydantic_core_schema__ to return a schema
that validates values are callable, such as core_schema.callable_schema(), or
add an equivalent custom validator; ensure invalid values like None or numeric
values are rejected during Pydantic validation while valid embedding functions
remain accepted.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/crewai/src/crewai/rag/milvus/types.py`:
- Around line 35-43: Update
MilvusEmbeddingFunctionWrapper.__get_pydantic_core_schema__ to return a schema
that validates values are callable, such as core_schema.callable_schema(), or
add an equivalent custom validator; ensure invalid values like None or numeric
values are rejected during Pydantic validation while valid embedding functions
remain accepted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c65fbc91-0076-4b2b-a7e6-686a7b87cb95

📥 Commits

Reviewing files that changed from the base of the PR and between 7baf8f9 and 8c3c2e6.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (21)
  • docs/edge/ar/concepts/knowledge.mdx
  • docs/edge/en/concepts/knowledge.mdx
  • lib/crewai/pyproject.toml
  • lib/crewai/src/crewai/rag/config/optional_imports/base.py
  • lib/crewai/src/crewai/rag/config/optional_imports/protocols.py
  • lib/crewai/src/crewai/rag/config/optional_imports/providers.py
  • lib/crewai/src/crewai/rag/config/optional_imports/types.py
  • lib/crewai/src/crewai/rag/config/types.py
  • lib/crewai/src/crewai/rag/factory.py
  • lib/crewai/src/crewai/rag/milvus/__init__.py
  • lib/crewai/src/crewai/rag/milvus/client.py
  • lib/crewai/src/crewai/rag/milvus/config.py
  • lib/crewai/src/crewai/rag/milvus/constants.py
  • lib/crewai/src/crewai/rag/milvus/factory.py
  • lib/crewai/src/crewai/rag/milvus/types.py
  • lib/crewai/src/crewai/rag/milvus/utils.py
  • lib/crewai/tests/rag/config/test_factory.py
  • lib/crewai/tests/rag/config/test_optional_imports.py
  • lib/crewai/tests/rag/milvus/__init__.py
  • lib/crewai/tests/rag/milvus/test_client.py
  • lib/crewai/tests/rag/milvus/test_config.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant