Skip to content

Conversation

@jawad-khan
Copy link

@jawad-khan jawad-khan commented Nov 14, 2025

Pull Request

This PR introduces sharding support to the Meilisearch Python SDK. I have tested the sharding functionality locally using two remote nodes, and all related test cases passed successfully.

Related issue

Fixes #<1137>

What does this PR do?

As mentioned in the issue, I have tested all of these points locally and added tests for the parts that can be covered within the test suite.

  • Update the Network methods to accept sending the sharding parameter
  • Update the Network methods to include remotes.[remoteName].writeApiKey in the responses
  • Update the Tasks methods to include remotes objects in the tasks response index update method to allow renaming
  • Add new test cases to test implementation

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Summary by CodeRabbit

  • New Features

    • Introduced network federation capabilities with support for distributed sharding across multiple remote instances.
    • Added configurable API key management for secure authentication between federated network nodes.
    • Extended the Task model to support network configuration metadata.
  • Tests

    • Added comprehensive test coverage for network sharding configuration and multi-instance federation scenarios.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

These changes add network sharding support to the MeiliSearch client by introducing an optional network field to the Task model and expanding test coverage with sharding configuration and write API key management for remote instances.

Changes

Cohort / File(s) Summary
Model Extension
meilisearch/models/task.py
Added optional network field of type Optional[Dict[str, Any]] with default value None to the Task model.
Network Configuration Tests
tests/client/test_client_network.py, tests/client/test_client_multi_search_meilisearch.py
Enhanced network federation test configurations by adding "sharding": True to request bodies, extending remote entries with writeApiKey fields alongside existing url and searchApiKey, and adding assertions to verify response["sharding"] equality.
Sharding Test Suite
tests/client/test_client_sharding.py
New test file with pytest-based test validating network sharding settings updates and retrieval via client, including assertions on self, remote URLs, API keys, and sharding flag.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Model field addition is minimal and non-breaking
  • Test changes are primarily data configuration updates and assertion extensions
  • New test file follows consistent patterns with existing test structure
  • Areas for attention:
    • Verify Task model serialization/deserialization handles the new optional network field without issues
    • Ensure test fixtures (enable_network_options, REMOTE_MS_1, BASE_URL) are correctly imported and available
    • Confirm that writeApiKey integration with sharding does not conflict with existing API key handling

Poem

🐰 A network takes shape, with sharding so bright,
Tasks now remember their network delight,
Keys for the remotes, both left and right,
The test suite hops forward with newfound might! 🌟

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding sharding support to the Python SDK. The changeset demonstrates this through network configuration updates, test cases for sharding, and a new network field in the Task model.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/client/test_client_multi_search_meilisearch.py (1)

107-107: Add assertion to verify sharding was configured.

The response from add_or_update_networks should be validated to confirm that sharding was successfully enabled, similar to the assertion in test_client_network.py line 37.

Apply this diff to add the missing assertion:

     assert "results" not in resp
+    assert resp["sharding"] is True
     assert "results" not in response
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a54e3c2 and d43103a.

📒 Files selected for processing (4)
  • meilisearch/models/task.py (1 hunks)
  • tests/client/test_client_multi_search_meilisearch.py (1 hunks)
  • tests/client/test_client_network.py (1 hunks)
  • tests/client/test_client_sharding.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/client/test_client_network.py (2)
tests/conftest.py (1)
  • client (15-16)
meilisearch/client.py (1)
  • add_or_update_networks (779-799)
tests/client/test_client_sharding.py (2)
tests/conftest.py (1)
  • client (15-16)
meilisearch/client.py (2)
  • add_or_update_networks (779-799)
  • get_all_networks (801-814)
🔇 Additional comments (4)
tests/client/test_client_multi_search_meilisearch.py (1)

84-101: LGTM! Network configuration correctly includes sharding and writeApiKey fields.

The addition of "sharding": True and "writeApiKey" fields to the network configuration aligns with the PR's objective of introducing sharding support.

tests/client/test_client_network.py (1)

17-37: LGTM! Test properly validates sharding configuration.

The test correctly adds the sharding flag and writeApiKey fields to the network configuration, and includes appropriate assertions to verify the response.

tests/client/test_client_sharding.py (1)

1-35: LGTM! Comprehensive test coverage for sharding functionality.

This new test file provides thorough validation of the sharding feature, including:

  • Setting network configuration with sharding enabled
  • Validating writeApiKey fields are properly stored and retrieved
  • Confirming the sharding flag persists across update/get operations
meilisearch/models/task.py (1)

24-24: The Task.network field is correctly implemented and will deserialize from API responses.

The field definition follows the correct pattern for optional generic dictionaries. When the network experimental feature is enabled, the field will contain replication metadata (origin or remotes data), and Pydantic will automatically deserialize it from the API response. The existing network tests in the codebase validate network configuration endpoints; the field itself will be populated transparently when tasks are retrieved.

@Strift Strift added the enhancement New feature or request label Nov 17, 2025
@Strift Strift linked an issue Nov 17, 2025 that may be closed by this pull request
4 tasks
@jawad-khan jawad-khan force-pushed the jawad/sharding-support branch from d43103a to 48b1dd0 Compare November 17, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.19.0] Add sharding support

2 participants