Skip to content

Conversation

@ron-42
Copy link
Contributor

@ron-42 ron-42 commented Nov 2, 2025

Summary

Adds support for radius and range_filter parameters in Milvus vector database searches, allowing users to fine-tune search behavior at runtime by specifying similarity ranges.

Changes:

  • Added optional search_params parameter to 4 search methods: search(), async_search(), hybrid_search(), async_hybrid_search()
  • Supports range-based searches with radius (outer boundary) and range_filter (inner boundary)
  • Full backward compatibility maintained
  • Includes test coverage (25/25 tests passing)

Fixes #5173

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Improvement
  • Model update
  • Other:

Checklist

  • Code complies with style guidelines
  • Ran format/validation scripts (./scripts/format.sh and ./scripts/validate.sh)
  • Self-review completed
  • Documentation updated (comments, docstrings)
  • Examples and guides: Relevant cookbook examples have been included or updated (if applicable)
  • Tested in clean environment
  • Tests added/updated (if applicable)

Changes Made

Modified libs/agno/agno/vectordb/milvus/milvus.py to accept search_params dictionary in:

  • search() / async_search() - Parameters passed directly to Milvus client
  • hybrid_search() / async_hybrid_search() - Parameters merged into dense/sparse search configs

Added tests in libs/agno/tests/unit/vectordb/test_milvusdb.py:

  • test_search_with_radius_and_range_filter() - Tests sync search with parameters
  • test_async_search_with_search_params() - Tests async search with parameters

Usage Example

from agno.vectordb.milvus import Milvus

# Initialize Milvus vector database
vector_db = Milvus(
    collection="my_collection",
    uri="http://localhost:19530",
)

# Search with radius only (outer boundary)
results = vector_db.search(
    query="your search query",
    limit=10,
    search_params={
        "radius": 0.8,  # Only return results with similarity >= 0.8
    }
)

# Search within a similarity range [0.5, 0.8]
results = vector_db.search(
    query="your search query",
    limit=10,
    search_params={
        "radius": 0.8,        # Outer boundary (maximum distance)
        "range_filter": 0.5,  # Inner boundary (minimum distance)
    }
)

# Works with async search too
results = await vector_db.async_search(
    query="your search query",
    limit=10,
    search_params={"radius": 0.9, "range_filter": 0.6}
)

Backward Compatibility

  • search_params is optional (defaults to None)
  • ✅ No breaking changes to existing code
  • ✅ Works with all distance metrics (cosine, L2, IP)
  • ✅ All 25 tests passing

Additional Notes

  • Works with Milvus Lite, Milvus server, and Zilliz Cloud
  • Range searches may return fewer results than limit if constraints are strict
  • No performance overhead when search_params is not provided
  • Related: Milvus Range Search Docs

@ron-42 ron-42 requested a review from a team as a code owner November 2, 2025 13:58
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.

[Bug] milvus need radius and range_filter

1 participant