Skip to content

Add Or Update Networks #1097

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

MuddyHope
Copy link
Contributor

@MuddyHope MuddyHope commented Apr 9, 2025

Pull Request

Related issue

Fixes #1082

What does this PR do?

  • Remote Fedarated Search addition

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?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features

    • Added the ability to manage and retrieve remote network configurations within the client.
    • Enhanced multi-search functionality to support network federation options.
  • Bug Fixes

    • Improved documentation for multi-search queries, clarifying support for federation options.
  • Tests

    • Introduced new tests for network configuration management and multi-search with network federation.
    • Added fixtures and constants to support network-related tests.

@Strift Strift requested review from sanders41 and Copilot April 14, 2025 01:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Copy link

coderabbitai bot commented May 21, 2025

Walkthrough

This update introduces experimental support for remote federated search requests in the Meilisearch client. It adds methods to manage remote networks, extends multi-search functionality to accept federation options, and provides new tests and fixtures to validate network federation and configuration. Constants and documentation are updated accordingly.

Changes

File(s) Change Summary
meilisearch/client.py Added add_or_update_networks and get_all_networks methods to Client; enhanced multi_search docstring for federation options.
meilisearch/config.py Added network constant to Config.Paths for network endpoint reference.
tests/client/test_client_multi_search_meilisearch.py Added test_multi_search_with_network to test multi-search with federation options and network setup.
tests/client/test_client_network.py New file with tests for network API: test_get_all_networks and test_add_or_update_networks.
tests/common.py Added constants REMOTE_MS_1 and REMOTE_MS_2 for remote microservice identifiers.
tests/conftest.py Added enable_network_options fixture to enable/disable the network experimental feature during tests.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test
    participant Client as Meilisearch Client
    participant API as Meilisearch API

    Test->>Client: add_or_update_networks(networks_dict)
    Client->>API: PATCH /network with networks_dict
    API-->>Client: Updated networks info
    Client-->>Test: Updated networks info

    Test->>Client: multi_search([{"federationOptions": {...}}])
    Client->>API: POST /multi-search with federationOptions
    API-->>Client: Federated search results
    Client-->>Test: Federated search results
Loading

Assessment against linked issues

Objective Addressed Explanation
Add support for the new network API ([#1082])
Update the multi-search functionality to accept the remote parameter ([#1082])

Poem

In the warren of code, a network appears,
Remote friends now join, as the search frontier clears.
With PATCH and with GET, the connections are spun,
Federation options—oh, what fun!
The tests all agree, the future looks bright—
Rabbits and Meilisearch, hopping into the night! 🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 1

♻️ Duplicate comments (1)
meilisearch/client.py (1)

783-796: Typo in the docstring.

There is a typo in the word "containeing" in the docstring - it should be "containing".

🧹 Nitpick comments (2)
tests/client/test_client_network.py (1)

7-12: Testing approach could be more comprehensive

While the basic test for get_all_networks confirms the response type, consider adding more specific assertions about the expected structure of the response.

 def test_get_all_networks(client):
     """Tests get all network in MS"""
     response = client.get_all_networks()
 
     assert isinstance(response, dict)
+    assert "self" in response
+    assert "remotes" in response
+    assert isinstance(response["remotes"], dict)
tests/client/test_client_multi_search_meilisearch.py (1)

80-111: Well-structured test for network federation functionality.

This test correctly validates the integration between multi-search and the new network federation feature. It properly:

  1. Uses the enable_network_options fixture
  2. Sets up network configurations
  3. Performs a federated search query
  4. Verifies the expected response structure and metadata

Consider improving these assertions:

- assert len(response["hits"]) >= 0
+ assert len(response["hits"]) > 0  # Ensure we actually got results

The current assertion len(response["hits"]) >= 0 will always pass since a list length can't be negative.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3f787ce and 7dcf7d0.

📒 Files selected for processing (6)
  • meilisearch/client.py (2 hunks)
  • meilisearch/config.py (1 hunks)
  • tests/client/test_client_multi_search_meilisearch.py (2 hunks)
  • tests/client/test_client_network.py (1 hunks)
  • tests/common.py (1 hunks)
  • tests/conftest.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/client/test_client_network.py (2)
tests/conftest.py (1)
  • client (15-16)
meilisearch/client.py (2)
  • get_all_networks (783-796)
  • add_or_update_networks (761-781)
tests/client/test_client_multi_search_meilisearch.py (2)
tests/conftest.py (2)
  • client (15-16)
  • index_with_documents (121-128)
meilisearch/client.py (2)
  • add_or_update_networks (761-781)
  • multi_search (226-255)
meilisearch/client.py (1)
meilisearch/_httprequests.py (2)
  • patch (99-107)
  • get (84-85)
tests/conftest.py (1)
meilisearch/_httprequests.py (1)
  • patch (99-107)
🔇 Additional comments (7)
meilisearch/config.py (1)

48-48: LGTM: Network path constant added

The new network path constant follows the existing pattern and will enable the federated search functionality.

tests/conftest.py (1)

279-293: LGTM: Network options fixture properly implemented

The new fixture follows the established pattern of other experimental feature fixtures, correctly enabling the network feature before tests and disabling it afterward.

tests/common.py (1)

17-18: LGTM: Remote Meilisearch instance constants added

These constants will be used as identifiers for remote Meilisearch instances in the network-related tests.

meilisearch/client.py (3)

237-238: Great addition to the documentation!

This documentation update clearly explains that queries can now include remote options in federationOptions, which is essential for users who want to use the new network federation functionality.


761-782: Well-implemented method for managing remote networks.

The add_or_update_networks method is correctly implemented with appropriate type annotations, error handling, and follows the Meilisearch API design patterns. It correctly uses the HTTP PATCH method to update network configurations.


783-796: Well-implemented network retrieval method.

The get_all_networks method is correctly implemented with proper return type annotations and follows the Meilisearch API design patterns. It correctly uses the HTTP GET method to retrieve network configurations.

tests/client/test_client_multi_search_meilisearch.py (1)

4-4: Appropriate imports added.

The additional imports from tests.common are correctly added to support the new network-related test.

Comment on lines +14 to +30
@pytest.mark.usefixtures("enable_network_options")
def test_add_or_update_networks(client):
"""Tests upsert network remote instance."""
body = {
"self": REMOTE_MS_1,
"remotes": {
REMOTE_MS_1: {"url": "http://localhost:7700", "searchApiKey": "xxxxxxxxxxxxxx"},
REMOTE_MS_2: {"url": "http://localhost:7720", "searchApiKey": "xxxxxxxxxxxxxxx"},
},
}
response = client.add_or_update_networks(body=body)

assert isinstance(response, dict)
assert response["self"] == REMOTE_MS_1
assert len(response["remotes"]) >= 2
assert REMOTE_MS_2 in response["remotes"]
assert REMOTE_MS_1 in response["remotes"]
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider adding edge case tests

The happy path test looks good, but consider adding tests for edge cases such as:

  1. Empty remotes dictionary
  2. Invalid URLs or API keys
  3. Non-existent remote instances

Also, ensure that the test URLs don't point to actual production services. The current localhost URLs look good, but it's worth verifying these are test environments only.


🏁 Script executed:

#!/bin/bash
# Check if there are any other URLs used in tests
rg --ignore-case "http" tests/ | grep -v "localhost" | grep -v "127.0.0.1"

Length of output: 1884


Enhance test_add_or_update_networks with edge‐case coverage

While the happy-path for upserting networks looks solid, please add tests for these scenarios in tests/client/test_client_network.py:

  • Empty remotes dictionary (what should the response be? error vs. no-ops)
  • Malformed URLs (e.g. htp://…) or missing/invalid API keys
  • self value not included in the remotes payload
  • Non-existent remote instance identifiers

Note: this test already uses only localhost endpoints, so there’s no risk of hitting production services here.

🤖 Prompt for AI Agents
In tests/client/test_client_network.py around lines 14 to 30, the current test
only covers the happy path for adding or updating networks. To improve coverage,
add separate test cases for edge scenarios: an empty remotes dictionary to
verify behavior (error or no-op), malformed URLs or invalid/missing API keys to
check validation, a self value not present in the remotes dictionary to test
consistency, and non-existent remote instance identifiers to confirm error
handling. Ensure these tests use localhost URLs or mocks to avoid external
calls.

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.

[v1.13] Remote federated search requests (experimental)
1 participant