Skip to content

Conversation

@awais786
Copy link
Contributor

@awais786 awais786 commented Nov 11, 2025

Add support for compacting database indexes

Summary by CodeRabbit

  • New Features

    • Added index compaction capability. Users can now invoke the compact() method on any index to trigger compaction and monitor task completion.
  • Documentation

    • Added code samples demonstrating index compaction usage patterns.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Walkthrough

A new compact() method has been added to the Index class in the Meilisearch Python SDK. This method triggers an asynchronous index compaction operation via a POST request and returns a TaskInfo object. Supporting code sample and test have been added.

Changes

Cohort / File(s) Summary
Code Samples
.code-samples.meilisearch.yaml
Added new code sample compact_index_1 demonstrating usage of the compact() method on an index.
Implementation
meilisearch/index.py
Added public method compact() to the Index class that sends a POST request to {index}/{uid}/compact and returns a TaskInfo object representing the compaction task.
Tests
tests/index/test_index.py
Added test test_index_compact that validates compaction behavior by checking pre- and post-compaction index stats, verifying document count remains unchanged and indexing completes successfully.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Index
    participant API
    
    Client->>Index: compact()
    Index->>API: POST /{index_uid}/compact
    API-->>Index: TaskInfo (task queued)
    Index-->>Client: TaskInfo
    
    Note over API: Asynchronous compaction<br/>processing
    API-->>Client: Task completed
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Straightforward addition of a single method following existing SDK patterns
  • Method implementation is a simple POST wrapper with minimal logic
  • Test is focused and validates expected behavior
  • Code sample is self-explanatory

Poem

🐰 A compact little change hops into view,
Index optimization, shiny and new,
With TaskInfo returned, async and neat,
Our Meilisearch SDK feels complete!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: Add support for compacting database indexes.' directly and accurately summarizes the main change—adding a compact() method to the Index class for index compaction.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb13de1 and ec8613e.

📒 Files selected for processing (3)
  • .code-samples.meilisearch.yaml (1 hunks)
  • meilisearch/index.py (1 hunks)
  • tests/index/test_index.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/index/test_index.py (3)
tests/conftest.py (1)
  • client (15-16)
meilisearch/client.py (2)
  • index (226-242)
  • wait_for_task (636-663)
meilisearch/index.py (3)
  • get_stats (262-279)
  • compact (2337-2349)
  • wait_for_task (233-260)
meilisearch/index.py (2)
meilisearch/models/task.py (1)
  • TaskInfo (77-106)
meilisearch/_httprequests.py (1)
  • post (98-108)
🔇 Additional comments (3)
meilisearch/index.py (1)

2336-2349: Compact endpoint wiring looks good.
The method targets the expected indexes/{uid}/compact route and reuses the existing TaskInfo flow, so callers can wait on the task just like other async operations.

.code-samples.meilisearch.yaml (1)

14-15: Documentation sample matches the new API.
The snippet cleanly mirrors how users will call compact(), keeping the docs in sync with the SDK addition.

tests/index/test_index.py (1)

225-236: Great coverage for the compaction workflow.
Waiting on the task and checking both document count stability and is_indexing keeps the regression suite honest about expected compaction behavior.


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.

@awais786 awais786 marked this pull request as ready for review November 11, 2025 13:04
@Strift Strift added the enhancement New feature or request label Nov 11, 2025
@Strift Strift linked an issue Nov 11, 2025 that may be closed by this pull request
3 tasks
Copy link
Contributor

@Strift Strift left a comment

Choose a reason for hiding this comment

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

Hello @awais786 and thanks for your contribution 🙌

@Strift Strift added this pull request to the merge queue Nov 11, 2025
Merged via the queue into meilisearch:main with commit 42917f1 Nov 11, 2025
11 checks passed
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.23] Add support for compacting database indexes

2 participants