Skip to content

Feat/index stats query params#1237

Open
vivek378521 wants to merge 9 commits into
meilisearch:mainfrom
vivek378521:feat/index-stats-query-params
Open

Feat/index stats query params#1237
vivek378521 wants to merge 9 commits into
meilisearch:mainfrom
vivek378521:feat/index-stats-query-params

Conversation

@vivek378521

@vivek378521 vivek378521 commented May 31, 2026

Copy link
Copy Markdown

Pull Request

Related issue

Fixes #1234

What does this PR do?

Meilisearch v1.44.0 adds two optional query parameters to GET /indexes/{indexUid}/stats and GET /stats:

  • showInternalDatabaseSizes — when true, index stat objects include an internalDatabaseSizes dictionary
  • sizeFormat"human" for readable sizes (e.g. "19.64 MiB") or "raw" for byte counts (default)

This PR wires those parameters through the Python SDK:

  • Index.get_stats() — keyword-only show_internal_database_sizes and size_format
  • Client.get_all_stats() — same parameters
  • IndexStats — optional internal_database_sizes: Dict[str, Any] (loosely typed; keys may change between Meilisearch versions, per API guidance)
  • SizeFormat enum (raw / human) for optional typing on size_format
  • Integration tests for both endpoints (raw vs human sizes, combined params)
  • .code-samples.meilisearch.yaml — updated get_index_stats_1 and get_indexes_stats_1

Query params are only sent when the caller provides them (backward compatible). Boolean values are encoded as lowercase true/false.

Example:

stats = client.index("movies").get_stats(
    show_internal_database_sizes=True,
    size_format="human",
)

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
    • Yes. Cursor (AI-assisted IDE) was used for implementation guidance, test structure, PR description drafting, and debugging (e.g. boolean query encoding). All changes were reviewed and committed by the author.
  • 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

    • Added optional support for internal database size details to both index and global stats endpoints via show_internal_database_sizes and size_format.
    • size_format can return raw values or human-readable sizes (e.g., "human" / RAW / HUMAN).
  • Documentation

    • Updated stats endpoint code samples to showcase internal size reporting with human-readable formatting.
  • Tests

    • Expanded coverage to verify internal size fields are present and correctly formatted for enum and string inputs.
  • Chores

    • Increased timeouts for embedder configuration update tests.

Support showInternalDatabaseSizes and sizeFormat on index stats,
extend IndexStats with internal_database_sizes, and add integration tests.
Support showInternalDatabaseSizes and sizeFormat on global stats,
with integration tests and updated code sample.
@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35909fce-d889-4def-9150-ddc1baa1cb3e

📥 Commits

Reviewing files that changed from the base of the PR and between b1918a8 and ec95306.

📒 Files selected for processing (8)
  • meilisearch/_httprequests.py
  • meilisearch/client.py
  • meilisearch/index.py
  • meilisearch/models/index.py
  • meilisearch/task.py
  • tests/client/test_chat_completions.py
  • tests/errors/test_timeout_error_meilisearch.py
  • tests/settings/test_settings_embedders.py
✅ Files skipped from review due to trivial changes (4)
  • tests/client/test_chat_completions.py
  • meilisearch/task.py
  • tests/errors/test_timeout_error_meilisearch.py
  • meilisearch/_httprequests.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • meilisearch/models/index.py
  • meilisearch/index.py
  • meilisearch/client.py
  • tests/settings/test_settings_embedders.py

📝 Walkthrough

Walkthrough

This PR adds optional stats query parameters for internal database sizes and human-readable formatting, extends the stats model, updates API samples, expands tests, and increases two embedder test timeouts.

Changes

Stats API Query Parameters Extension

Layer / File(s) Summary
Data Model & SizeFormat Enum
meilisearch/models/index.py
Introduces SizeFormat and adds internal_database_sizes to IndexStats.
Client.get_all_stats() API Extension
meilisearch/client.py
Adds keyword-only stats options and query-string construction for all-index stats.
Index.get_stats() API Extension
meilisearch/index.py
Adds matching keyword-only stats options and query-string construction for index stats.
Index API Test Coverage
tests/index/test_index_stats_meilisearch.py
Adds coverage for internal database sizes and human size formatting on index stats.
Client API Test Coverage
tests/client/test_client_stats_meilisearch.py
Adds coverage for internal database sizes and human size formatting on all-index stats.
Documentation Code Samples
.code-samples.meilisearch.yaml
Updates stats examples to pass the new parameters.

Test Infrastructure Improvements

Layer / File(s) Summary
Embedder Configuration Test Timeouts
tests/settings/test_settings_embedders.py
Increases two embedder task wait timeouts.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: sanders41

Poem

🐰 I hopped through stats with lively cheer,
raw and human sizes now appear.
Internal DB crumbs, neat and grand,
hop from API right to my hand.
Byte by byte or bright and light,
this bunny says the stats feel right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several unrelated formatting/import-only edits and a test timeout increase are outside the stats-query-params scope. Remove or split the unrelated formatting and timeout changes into a separate cleanup PR.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly points to the main change: adding query parameters for stats endpoints.
Linked Issues check ✅ Passed The PR adds both stats query params, updates the two SDK methods, adds loosely typed internal sizes, tests, and code samples as requested.
Docstring Coverage ✅ Passed Docstring coverage is 93.33% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

39-54: ⚡ Quick win

The internal-sizes human-format check can silently no-op.

Unlike test_get_all_stats_with_internal_database_sizes, this test has no any(...) guard asserting that at least one index actually contains internalDatabaseSizes. If no index returns the key, the loop body never runs and the human-format assertion on internal sizes is skipped (only the top-level databaseSize check on Line 48 would cover the format). Add a presence guard to ensure the internal-size branch is exercised.

✅ Proposed guard
     assert isinstance(response["databaseSize"], str)
     assert HUMAN_SIZE_PATTERN.match(response["databaseSize"])
+    assert any(
+        "internalDatabaseSizes" in index_stats for index_stats in response["indexes"].values()
+    )
     for index_stats in response["indexes"].values():
         if "internalDatabaseSizes" in index_stats:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/client/test_client_stats_meilisearch.py` around lines 39 - 54, The test
test_get_all_stats_with_size_format can silently skip the internalDatabaseSizes
checks if no index contains that key; update the test to assert the branch is
exercised by collecting presence from response (e.g., use any(...) on
response["indexes"].values() to check for "internalDatabaseSizes") and assert
that at least one index contains internalDatabaseSizes before running the loop
that validates HUMAN_SIZE_PATTERN on those values; operate on the existing
response variable and keep the databaseSize string checks, then add the presence
guard to fail the test if no internal sizes are present.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/client/test_client_stats_meilisearch.py`:
- Around line 39-54: The test test_get_all_stats_with_size_format can silently
skip the internalDatabaseSizes checks if no index contains that key; update the
test to assert the branch is exercised by collecting presence from response
(e.g., use any(...) on response["indexes"].values() to check for
"internalDatabaseSizes") and assert that at least one index contains
internalDatabaseSizes before running the loop that validates HUMAN_SIZE_PATTERN
on those values; operate on the existing response variable and keep the
databaseSize string checks, then add the presence guard to fail the test if no
internal sizes are present.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e585e2a7-2f74-4d44-95cb-53d88495ad07

📥 Commits

Reviewing files that changed from the base of the PR and between ada25db and f2b7d58.

📒 Files selected for processing (6)
  • .code-samples.meilisearch.yaml
  • meilisearch/client.py
  • meilisearch/index.py
  • meilisearch/models/index.py
  • tests/client/test_client_stats_meilisearch.py
  • tests/index/test_index_stats_meilisearch.py

Address CodeRabbit feedback: fail test_get_all_stats_with_size_format if
no index returns internalDatabaseSizes, so human-size checks cannot pass silently.

@Strift Strift left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello @vivek378521, thanks for your PR!

This looks good, but CI is not passing. I suggest you run tests + formatting locally before requesting another review 🙏

@vivek378521

Copy link
Copy Markdown
Author

Hello @Strift

I ran all tests locally and now everything looks good. Please review.

Thank you for the time. I really appreciate it. :)

@DhavalGojiya

Copy link
Copy Markdown
Contributor

Hello @Strift

I ran all tests locally and now everything looks good. Please review.

Thank you for the time. I really appreciate it. :)

Need to resolve conflicts.

@vivek378521 vivek378521 requested a review from Strift July 2, 2026 13:40
@vivek378521

Copy link
Copy Markdown
Author

@DhavalGojiya @Strift Resolved merge conflicts. Thanks!

@DhavalGojiya

Copy link
Copy Markdown
Contributor

@DhavalGojiya @Strift Resolved merge conflicts. Thanks!

I think you forgot to run the linter and formatter again for this PR.
Could you please run them and make sure everything passes?

https://github.com/meilisearch/meilisearch-python/blob/main/CONTRIBUTING.md#tests-and-linter-

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.

[Meilisearch v1.44.0] Add human-formatted sizes and detailed DB sizes in stats

3 participants