-
Notifications
You must be signed in to change notification settings - Fork 99
feat: Added customMetadata in index apis #1179
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?
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds an optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)tests/index/test_index_document_meilisearch.py (2)
🔇 Additional comments (5)
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. Comment |
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.
Pull request overview
This PR adds support for the customMetadata field to index-related APIs in the Python SDK, aligning with recent Meilisearch server changes. The implementation adds an optional metadata parameter to all document manipulation methods (add, update, delete) that gets passed to the Meilisearch server as a query parameter.
Key changes:
- Added
customMetadatafield to theTaskmodel to capture metadata returned by the server - Updated all document methods in the
Indexclass to accept an optionalmetadataparameter - Enhanced test coverage by adding metadata assertions to document operation tests
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| meilisearch/models/task.py | Added customMetadata field as Optional[str] to Task model |
| meilisearch/index.py | Added metadata parameter to all document methods (add/update/delete variants) and updated URL building logic to include customMetadata as a query parameter |
| tests/index/test_index_document_meilisearch.py | Updated tests to pass metadata parameter and assert that customMetadata is persisted on task objects |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self, | ||
| documents: Sequence[Mapping[str, Any]], | ||
| batch_size: int = 1000, | ||
| primary_key: Optional[str] = None, |
Copilot
AI
Dec 3, 2025
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.
Inconsistent API design: In add_documents_in_batches, serializer is a keyword-only argument (line 521-522 uses *,), but in this method it's not keyword-only. For consistency, consider adding *, before serializer on line 906 to make it keyword-only, or update add_documents_in_batches to match this signature. The new metadata parameter should also be keyword-only to match the pattern in add_documents_in_batches.
| primary_key: Optional[str] = None, | |
| primary_key: Optional[str] = None, | |
| *, |
| index.wait_for_task(response.task_uid) | ||
| response = index.delete_documents(filter="genre=action", metadata="Test metadata") | ||
| task = index.wait_for_task(response.task_uid) | ||
| task.customMetadata = "Test metadata" |
Copilot
AI
Dec 3, 2025
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.
This line should be an assertion (assert task.customMetadata == "Test metadata") instead of an assignment. Unlike all other test cases in this file, this line assigns a value instead of verifying it, which means the test isn't actually validating that the metadata was properly persisted.
| task.customMetadata = "Test metadata" | |
| assert task.customMetadata == "Test metadata" |
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.
Actionable comments posted: 1
🧹 Nitpick comments (4)
meilisearch/index.py (4)
601-634: Inconsistent parameter style:metadatais positional here but keyword-only in similar methods.In
add_documents,add_documents_in_batches, andadd_documents_json, themetadataparameter is keyword-only (after*). However, inadd_documents_csv, it's a regular positional parameter.For API consistency, consider making
metadatakeyword-only:def add_documents_csv( self, str_documents: bytes, primary_key: Optional[str] = None, csv_delimiter: Optional[str] = None, + *, metadata: Optional[str] = None, ) -> TaskInfo:
636-666: Same inconsistency:metadatashould be keyword-only for consistency.def add_documents_ndjson( self, str_documents: bytes, primary_key: Optional[str] = None, + *, metadata: Optional[str] = None, ) -> TaskInfo:
751-781: Same inconsistency:metadatashould be keyword-only.def update_documents_ndjson( self, str_documents: str, primary_key: Optional[str] = None, + *, metadata: Optional[str] = None, ) -> TaskInfo:
820-853: Same inconsistency:metadatashould be keyword-only.def update_documents_csv( self, str_documents: str, primary_key: Optional[str] = None, csv_delimiter: Optional[str] = None, + *, metadata: Optional[str] = None, ) -> TaskInfo:
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
meilisearch/index.py(37 hunks)meilisearch/models/task.py(1 hunks)tests/index/test_index_document_meilisearch.py(15 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/index/test_index_document_meilisearch.py (1)
meilisearch/index.py (14)
add_documents(479-514)update(108-152)add_documents_in_batches(516-562)add_documents_json(564-599)update_documents(714-749)update_documents_json(783-818)update_documents_in_batches(901-946)delete_document(948-975)delete_documents(978-1030)delete_all_documents(1032-1055)add_documents_csv(601-634)update_documents_csv(820-853)add_documents_ndjson(636-666)update_documents_ndjson(751-781)
meilisearch/index.py (2)
meilisearch/_httprequests.py (2)
put(120-140)post(98-108)meilisearch/models/task.py (1)
TaskInfo(79-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Agent
🔇 Additional comments (31)
meilisearch/models/task.py (1)
25-25: LGTM -customMetadatafield added to Task model.The field correctly uses
Optional[str]and follows the existing CamelBase naming convention for API compatibility.tests/index/test_index_document_meilisearch.py (18)
31-40: LGTM - Test correctly verifies metadata propagation.
65-74: LGTM - Batch test correctly verifies metadata on each task.
112-120: LGTM - JSON serializer test with metadata verification.
129-140: LGTM - Raw documents test with metadata verification.
149-155: LGTM - Update documents test with metadata.
177-185: LGTM - Update documents JSON test with metadata.
194-205: LGTM - Update documents raw test with metadata.
393-398: LGTM - Update documents test with metadata.
423-432: LGTM - Update documents in batches test with metadata.
440-444: LGTM - Delete document test with metadata.
455-459: LGTM - Delete documents by ID test with metadata.
486-490: LGTM - Delete all documents test with metadata.
499-503: LGTM - Add documents CSV test with metadata.
525-530: LGTM - Update documents CSV test with metadata.
551-556: LGTM - Add documents JSON test with metadata.
563-567: LGTM - Update documents JSON test with metadata.
575-579: LGTM - Add documents NDJSON test with metadata.
587-592: LGTM - Update documents NDJSON test with metadata.meilisearch/index.py (12)
479-514: LGTM -add_documentsmethod correctly supports metadata parameter.The metadata is properly threaded through to
_build_urland documented in the docstring.
516-562: LGTM -add_documents_in_batchescorrectly propagates metadata to each batch.
564-599: LGTM -add_documents_jsoncorrectly propagates metadata.
668-712: LGTM -add_documents_rawcorrectly implements metadata as keyword-only.
714-749: LGTM -update_documentscorrectly implements metadata.
783-818: LGTM -update_documents_jsoncorrectly implements metadata as keyword-only.
855-899: LGTM -update_documents_rawcorrectly implements metadata as keyword-only.
901-946: LGTM -update_documents_in_batchescorrectly propagates metadata.Note: The parameter style follows the existing pattern for this method (positional optional parameters), though it differs from
add_documents_in_batcheswhich uses keyword-only parameters. This is a pre-existing inconsistency.
948-975: LGTM -delete_documentcorrectly implements metadata with URL encoding.
977-1030: LGTM -delete_documentscorrectly handles metadata in both the ids and filter branches.
1032-1055: LGTM -delete_all_documentscorrectly implements metadata.
2430-2445: LGTM -_build_urlcorrectly centralizes the metadata query parameter construction.Good approach to centralize the
metadata→customMetadatamapping in the URL builder.
|
@Strift Tests are failing because sharding require Enterprose addition now. Should we adjust test cases or somehow we can skip this check. |
Related issue
Fixes #1168
What does this PR do?
Update Index APIs to Support customMetadata
This PR updates the index-related APIs in the Python SDK to align with recent Meilisearch server changes and adds support for the new customMetadata field.
Key Updates
Added customMetadata support across index creation and update methods.
Synced request/response structures with the latest Meilisearch index API.
...
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.