Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 50386
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 5368
🌐 Web query:
Pydantic 2 int field validation string with units "1.5 GiB" rejects💡 Result:
In Pydantic V2, a field annotated as
intwill reject a string input like "1.5 GiB" because Pydantic's defaultintvalidation is strict regarding non-numeric string content [1]. While Pydantic V2 allows some coercion of numeric strings (e.g., "123" toint), it does not natively support parsing human-readable byte strings containing units or fractions [1]. To handle "1.5 GiB" or similar strings in a Pydantic model, you must use a validator to preprocess the input into an integer before it reaches the standard validation logic [2]. Recommended approach: 1. Use a custom validator: Apply aBeforeValidatoror@field_validator(mode='before')to the field [2][3]. 2. Parse the string: Use a utility library that handles byte-size string parsing, such ashumanfriendly[4],py-humanize-bytes[5][6], ornumparse[7]. Example implementation:python from typing import Annotated, Any from pydantic import BaseModel, BeforeValidator from humanfriendly import parse_size # or another parsing library # Use a validator to convert "1.5 GiB" to an integer def parse_bytes_to_int(value: Any) -> int: if isinstance(value, str): return int(parse_size(value)) return value class StorageModel(BaseModel): size_bytes: Annotated[int, BeforeValidator(parse_bytes_to_int)] # Usage model = StorageModel(size_bytes="1.5 GiB") print(model.size_bytes) # Output: 1610612736If you require internal handling without external dependencies, you can implement a helper function using regex or string splitting as seen in common open-source utilities [8], but using an established library is generally recommended to handle edge cases in unit parsing [5][7][4].Citations:
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 14810
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 2856
🌐 Web query:
Meilisearch stats API sizeFormat human indexSize usedDatabaseSize response💡 Result:
In Meilisearch, the stats API endpoints (specifically GET /stats and GET /indexes/{index_uid}/stats) support query parameters to control how database sizes are reported [1][2]. The sizeFormat query parameter allows you to specify the format of database sizes in the response [3][1]. It accepts the following values: "raw" (default): Returns sizes as a number representing bytes [3][1]. "human": Returns sizes as a human-readable string with an appropriate unit (e.g., "MiB", "GiB") [3][1][2]. Regarding database size metrics, Meilisearch provides two distinct fields [4][5]: databaseSize: Represents the total disk space claimed by Meilisearch [4][5]. Because Meilisearch uses LMDB, this value does not decrease when documents are deleted, as the database does not automatically free unused space [4][5]. usedDatabaseSize: Represents the actual space used by the data stored in Meilisearch [4][5]. This value excludes the unused space claimed by LMDB and will decrease when documents are deleted [4][5]. These features, including the sizeFormat and the usedDatabaseSize field, were introduced in recent versions of Meilisearch (notably v1.13 for usedDatabaseSize and v1.44 for sizeFormat) [4][1][2].
Citations:
🌐 Web query:
site:meilisearch.com/docs/reference/api/indexes/get-stats-of-index "indexSize" "usedDatabaseSize"💡 Result:
The terms indexSize and usedDatabaseSize do not represent a standard, universally defined pair of metrics across all database systems, nor are they both standard fields returned by the common MongoDB db.stats command. In the context of database statistics: indexSize generally refers to the total size of all indexes created on a database or a specific collection, measured in bytes. This reflects the disk space consumed by index structures to facilitate faster query performance. usedDatabaseSize is not a standard term in major database management systems like MongoDB. It is possible this term is either a custom metric, a misremembered name for another statistic, or specific to a particular third-party tool or niche database technology not identified in the available documentation. In systems like MongoDB, similar concepts are usually expressed through metrics such as dataSize (the total size of the uncompressed data held in the database) or storageSize (the total amount of space allocated to the database collections, including unallocated space). If you are encountering these terms in a specific application or dashboard, it is recommended to consult the documentation for that specific software, as they may have defined custom metrics for reporting storage consumption.
Citations:
🌐 Web query:
site:github.com/meilisearch/meilisearch "usedIndexSize" "indexSize" stats💡 Result:
In Meilisearch, indexSize and usedIndexSize are statistics provided by the GET /indexes/{index_uid}/stats and GET /stats endpoints [1]. These metrics were introduced in version 1.53.0 to provide better visibility into database storage usage [1]. While specific technical documentation detailing the precise calculation difference between these two fields is not provided in the search results, they are collectively used to monitor index storage consumption within the Meilisearch engine [1]. indexSize generally represents the total size allocated or used by the index, while usedIndexSize typically indicates the actual portion of that space currently occupied by data, allowing users to better understand fragmentation or storage efficiency [1].
Citations:
🏁 Script executed:
Repository: meilisearch/meilisearch-python
Length of output: 7062
🌐 Web query:
"usedIndexSize" "sizeFormat" Meilisearch💡 Result:
In Meilisearch, indexSize and usedIndexSize are metrics introduced in version 1.53.0 to provide detailed insight into the storage footprint of an index [1][2]. 1. indexSize: Represents the total size of the index database, measured in bytes by default [1][2]. 2. usedIndexSize: Represents the size of the used pages within the index database, also measured in bytes by default [1][2]. These fields are available in the response when querying index statistics, such as the Get stats of index or Get stats of all indexes endpoints [1]. Regarding the sizeFormat mentioned in your query: these fields are designed to honor a sizeFormat parameter when supported, allowing you to toggle the output between raw byte integers and human-readable string formats [3][1]. According to Meilisearch's internal API schema definitions for size types, the value can be returned either as an integer (in bytes) or as a human-readable string with an appropriate unit [3]. It is important to note that Meilisearch uses LMDB for storage, which pre-allocates disk space [4][5]. Because LMDB marks deleted space as free but does not always immediately return it to the operating system, disk usage may appear higher than the actual data volume, and it can grow over time [4]. Top results: [3], [1], [2]
Citations:
Accept human-formatted size responses.
The stats API returns
indexSizeandusedIndexSizeas integers or human-readable strings.Index.get_stats()passes the response directly toIndexStats(**stats), whose fields accept onlyint | None. Accept both formats or normalize the values before model construction.🤖 Prompt for AI Agents