meilisearch-python-sdk 2.10.1__tar.gz → 2.11.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of meilisearch-python-sdk might be problematic. Click here for more details.

Files changed (26) hide show
  1. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/PKG-INFO +1 -1
  2. meilisearch_python_sdk-2.11.0/meilisearch_python_sdk/_version.py +1 -0
  3. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/index.py +190 -6
  4. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/search.py +40 -2
  5. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/pyproject.toml +14 -3
  6. meilisearch_python_sdk-2.10.1/meilisearch_python_sdk/_version.py +0 -1
  7. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/LICENSE +0 -0
  8. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/README.md +0 -0
  9. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/__init__.py +0 -0
  10. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/_client.py +0 -0
  11. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/_http_requests.py +0 -0
  12. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/_task.py +0 -0
  13. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/_utils.py +0 -0
  14. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/decorators.py +0 -0
  15. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/errors.py +0 -0
  16. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/__init__.py +0 -0
  17. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/client.py +0 -0
  18. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/documents.py +0 -0
  19. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/health.py +0 -0
  20. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/index.py +0 -0
  21. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/settings.py +0 -0
  22. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/task.py +0 -0
  23. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/models/version.py +0 -0
  24. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/plugins.py +0 -0
  25. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/py.typed +0 -0
  26. {meilisearch_python_sdk-2.10.1 → meilisearch_python_sdk-2.11.0}/meilisearch_python_sdk/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: meilisearch-python-sdk
3
- Version: 2.10.1
3
+ Version: 2.11.0
4
4
  Summary: A Python client providing both async and sync support for the Meilisearch API
5
5
  Home-page: https://github.com/sanders41/meilisearch-python-sdk
6
6
  License: MIT
@@ -0,0 +1 @@
1
+ VERSION = "2.11.0"
@@ -6,7 +6,7 @@ from csv import DictReader
6
6
  from datetime import datetime
7
7
  from functools import cached_property, partial
8
8
  from pathlib import Path
9
- from typing import TYPE_CHECKING, Any, Generator, MutableMapping, Sequence
9
+ from typing import TYPE_CHECKING, Any, Generator, Literal, MutableMapping, Sequence
10
10
  from urllib.parse import urlencode
11
11
  from warnings import warn
12
12
 
@@ -20,7 +20,12 @@ from meilisearch_python_sdk._utils import is_pydantic_2, iso_to_date_time, use_t
20
20
  from meilisearch_python_sdk.errors import InvalidDocumentError, MeilisearchError
21
21
  from meilisearch_python_sdk.models.documents import DocumentsInfo
22
22
  from meilisearch_python_sdk.models.index import IndexStats
23
- from meilisearch_python_sdk.models.search import FacetSearchResults, Hybrid, SearchResults
23
+ from meilisearch_python_sdk.models.search import (
24
+ FacetSearchResults,
25
+ Hybrid,
26
+ SearchResults,
27
+ SimilarSearchResults,
28
+ )
24
29
  from meilisearch_python_sdk.models.settings import (
25
30
  Embedders,
26
31
  Faceting,
@@ -737,6 +742,7 @@ class AsyncIndex(_BaseIndex):
737
742
  attributes_to_search_on: list[str] | None = None,
738
743
  show_ranking_score: bool = False,
739
744
  show_ranking_score_details: bool = False,
745
+ ranking_score_threshold: float | None = None,
740
746
  vector: list[float] | None = None,
741
747
  hybrid: Hybrid | None = None,
742
748
  ) -> SearchResults:
@@ -777,6 +783,9 @@ class AsyncIndex(_BaseIndex):
777
783
  Because this feature is experimental it may be removed or updated causing breaking
778
784
  changes in this library without a major version bump so use with caution. This
779
785
  feature became stable in Meiliseach v1.7.0.
786
+ ranking_score_threshold: If set, no document whose _rankingScore is under the
787
+ rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
788
+ to None.
780
789
  vector: List of vectors for vector search. Defaults to None. Note: This parameter can
781
790
  only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0.
782
791
  In order to use this feature in Meilisearch v1.3.0 you first need to enable the
@@ -808,6 +817,9 @@ class AsyncIndex(_BaseIndex):
808
817
  >>> index = client.index("movies")
809
818
  >>> search_results = await index.search("Tron")
810
819
  """
820
+ if ranking_score_threshold:
821
+ _validate_ranking_score_threshold(ranking_score_threshold)
822
+
811
823
  body = _process_search_parameters(
812
824
  q=query,
813
825
  offset=offset,
@@ -831,6 +843,7 @@ class AsyncIndex(_BaseIndex):
831
843
  show_ranking_score_details=show_ranking_score_details,
832
844
  vector=vector,
833
845
  hybrid=hybrid,
846
+ ranking_score_threshold=ranking_score_threshold,
834
847
  )
835
848
  search_url = f"{self._base_url_with_uid}/search"
836
849
 
@@ -981,12 +994,13 @@ class AsyncIndex(_BaseIndex):
981
994
  highlight_pre_tag: str = "<em>",
982
995
  highlight_post_tag: str = "</em>",
983
996
  crop_marker: str = "...",
984
- matching_strategy: str = "all",
997
+ matching_strategy: Literal["all", "last", "frequency"] = "all",
985
998
  hits_per_page: int | None = None,
986
999
  page: int | None = None,
987
1000
  attributes_to_search_on: list[str] | None = None,
988
1001
  show_ranking_score: bool = False,
989
1002
  show_ranking_score_details: bool = False,
1003
+ ranking_score_threshold: float | None = None,
990
1004
  vector: list[float] | None = None,
991
1005
  ) -> FacetSearchResults:
992
1006
  """Search the index.
@@ -1028,6 +1042,9 @@ class AsyncIndex(_BaseIndex):
1028
1042
  Because this feature is experimental it may be removed or updated causing breaking
1029
1043
  changes in this library without a major version bump so use with caution. This
1030
1044
  feature became stable in Meiliseach v1.7.0.
1045
+ ranking_score_threshold: If set, no document whose _rankingScore is under the
1046
+ rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
1047
+ to None.
1031
1048
  vector: List of vectors for vector search. Defaults to None. Note: This parameter can
1032
1049
  only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0.
1033
1050
  In order to use this feature in Meilisearch v1.3.0 you first need to enable the
@@ -1056,6 +1073,9 @@ class AsyncIndex(_BaseIndex):
1056
1073
  >>> facet_query="Sci-fi"
1057
1074
  >>> )
1058
1075
  """
1076
+ if ranking_score_threshold:
1077
+ _validate_ranking_score_threshold(ranking_score_threshold)
1078
+
1059
1079
  body = _process_search_parameters(
1060
1080
  q=query,
1061
1081
  facet_name=facet_name,
@@ -1079,6 +1099,7 @@ class AsyncIndex(_BaseIndex):
1079
1099
  attributes_to_search_on=attributes_to_search_on,
1080
1100
  show_ranking_score=show_ranking_score,
1081
1101
  show_ranking_score_details=show_ranking_score_details,
1102
+ ranking_score_threshold=ranking_score_threshold,
1082
1103
  vector=vector,
1083
1104
  )
1084
1105
  search_url = f"{self._base_url_with_uid}/facet-search"
@@ -1107,6 +1128,7 @@ class AsyncIndex(_BaseIndex):
1107
1128
  attributes_to_search_on=attributes_to_search_on,
1108
1129
  show_ranking_score=show_ranking_score,
1109
1130
  show_ranking_score_details=show_ranking_score_details,
1131
+ ranking_score_threshold=ranking_score_threshold,
1110
1132
  vector=vector,
1111
1133
  )
1112
1134
 
@@ -1138,6 +1160,7 @@ class AsyncIndex(_BaseIndex):
1138
1160
  attributes_to_search_on=attributes_to_search_on,
1139
1161
  show_ranking_score=show_ranking_score,
1140
1162
  show_ranking_score_details=show_ranking_score_details,
1163
+ ranking_score_threshold=ranking_score_threshold,
1141
1164
  vector=vector,
1142
1165
  )
1143
1166
  )
@@ -1180,6 +1203,7 @@ class AsyncIndex(_BaseIndex):
1180
1203
  attributes_to_search_on=attributes_to_search_on,
1181
1204
  show_ranking_score=show_ranking_score,
1182
1205
  show_ranking_score_details=show_ranking_score_details,
1206
+ ranking_score_threshold=ranking_score_threshold,
1183
1207
  vector=vector,
1184
1208
  )
1185
1209
  )
@@ -1208,6 +1232,75 @@ class AsyncIndex(_BaseIndex):
1208
1232
 
1209
1233
  return result
1210
1234
 
1235
+ async def search_similar_documents(
1236
+ self,
1237
+ id: str,
1238
+ *,
1239
+ offset: int | None = None,
1240
+ limit: int | None = None,
1241
+ filter: str | None = None,
1242
+ embedder: str = "default",
1243
+ attributes_to_retrieve: list[str] | None = None,
1244
+ show_ranking_score: bool = False,
1245
+ show_ranking_score_details: bool = False,
1246
+ ranking_score_threshold: float | None = None,
1247
+ ) -> SimilarSearchResults:
1248
+ """Search the index.
1249
+
1250
+ Args:
1251
+ id: The id for the target document that is being used to find similar documents.
1252
+ offset: Number of documents to skip. Defaults to 0.
1253
+ limit: Maximum number of documents returned. Defaults to 20.
1254
+ filter: Filter queries by an attribute value. Defaults to None.
1255
+ embedder: The vector DB to use for the search.
1256
+ attributes_to_retrieve: Attributes to display in the returned documents.
1257
+ Defaults to ["*"].
1258
+ show_ranking_score: If set to True the ranking score will be returned with each document
1259
+ in the search. Defaults to False.
1260
+ show_ranking_score_details: If set to True the ranking details will be returned with
1261
+ each document in the search. Defaults to False.
1262
+ ranking_score_threshold: If set, no document whose _rankingScore is under the
1263
+ rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
1264
+ to None.
1265
+
1266
+ Returns:
1267
+
1268
+ Results of the search
1269
+
1270
+ Raises:
1271
+
1272
+ MeilisearchCommunicationError: If there was an error communicating with the server.
1273
+ MeilisearchApiError: If the Meilisearch API returned an error.
1274
+
1275
+ Examples:
1276
+
1277
+ >>> from meilisearch_python_sdk import AsyncClient
1278
+ >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
1279
+ >>> index = client.index("movies")
1280
+ >>> search_results = await index.search_similar_documents("123")
1281
+ """
1282
+ payload = {
1283
+ "id": id,
1284
+ "filter": filter,
1285
+ "embedder": embedder,
1286
+ "attributesToRetrieve": attributes_to_retrieve,
1287
+ "showRankingScore": show_ranking_score,
1288
+ "showRankingScoreDetails": show_ranking_score_details,
1289
+ "rankingScoreThreshold": ranking_score_threshold,
1290
+ }
1291
+
1292
+ if offset:
1293
+ payload["offset"] = offset
1294
+
1295
+ if limit:
1296
+ payload["limit"] = limit
1297
+
1298
+ response = await self._http_requests.post(
1299
+ f"{self._base_url_with_uid}/similar", body=payload
1300
+ )
1301
+
1302
+ return SimilarSearchResults(**response.json())
1303
+
1211
1304
  async def get_document(self, document_id: str) -> JsonDict:
1212
1305
  """Get one document with given document identifier.
1213
1306
 
@@ -5008,12 +5101,13 @@ class Index(_BaseIndex):
5008
5101
  highlight_pre_tag: str = "<em>",
5009
5102
  highlight_post_tag: str = "</em>",
5010
5103
  crop_marker: str = "...",
5011
- matching_strategy: str = "all",
5104
+ matching_strategy: Literal["all", "last", "frequency"] = "all",
5012
5105
  hits_per_page: int | None = None,
5013
5106
  page: int | None = None,
5014
5107
  attributes_to_search_on: list[str] | None = None,
5015
5108
  show_ranking_score: bool = False,
5016
5109
  show_ranking_score_details: bool = False,
5110
+ ranking_score_threshold: float | None = None,
5017
5111
  vector: list[float] | None = None,
5018
5112
  hybrid: Hybrid | None = None,
5019
5113
  ) -> SearchResults:
@@ -5054,6 +5148,9 @@ class Index(_BaseIndex):
5054
5148
  Because this feature is experimental it may be removed or updated causing breaking
5055
5149
  changes in this library without a major version bump so use with caution. This
5056
5150
  feature became stable in Meiliseach v1.7.0.
5151
+ ranking_score_threshold: If set, no document whose _rankingScore is under the
5152
+ rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
5153
+ to None.
5057
5154
  vector: List of vectors for vector search. Defaults to None. Note: This parameter can
5058
5155
  only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0.
5059
5156
  In order to use this feature in Meilisearch v1.3.0 you first need to enable the
@@ -5085,6 +5182,9 @@ class Index(_BaseIndex):
5085
5182
  >>> index = client.index("movies")
5086
5183
  >>> search_results = index.search("Tron")
5087
5184
  """
5185
+ if ranking_score_threshold:
5186
+ _validate_ranking_score_threshold(ranking_score_threshold)
5187
+
5088
5188
  body = _process_search_parameters(
5089
5189
  q=query,
5090
5190
  offset=offset,
@@ -5108,6 +5208,7 @@ class Index(_BaseIndex):
5108
5208
  show_ranking_score_details=show_ranking_score_details,
5109
5209
  vector=vector,
5110
5210
  hybrid=hybrid,
5211
+ ranking_score_threshold=ranking_score_threshold,
5111
5212
  )
5112
5213
 
5113
5214
  if self._pre_search_plugins:
@@ -5172,6 +5273,7 @@ class Index(_BaseIndex):
5172
5273
  attributes_to_search_on: list[str] | None = None,
5173
5274
  show_ranking_score: bool = False,
5174
5275
  show_ranking_score_details: bool = False,
5276
+ ranking_score_threshold: float | None = None,
5175
5277
  vector: list[float] | None = None,
5176
5278
  ) -> FacetSearchResults:
5177
5279
  """Search the index.
@@ -5213,6 +5315,9 @@ class Index(_BaseIndex):
5213
5315
  Because this feature is experimental it may be removed or updated causing breaking
5214
5316
  changes in this library without a major version bump so use with caution. This
5215
5317
  feature became stable in Meiliseach v1.7.0.
5318
+ ranking_score_threshold: If set, no document whose _rankingScore is under the
5319
+ rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
5320
+ to None.
5216
5321
  vector: List of vectors for vector search. Defaults to None. Note: This parameter can
5217
5322
  only be used with Meilisearch >= v1.3.0, and is experimental in Meilisearch v1.3.0.
5218
5323
  In order to use this feature in Meilisearch v1.3.0 you first need to enable the
@@ -5241,6 +5346,9 @@ class Index(_BaseIndex):
5241
5346
  >>> facet_query="Sci-fi"
5242
5347
  >>> )
5243
5348
  """
5349
+ if ranking_score_threshold:
5350
+ _validate_ranking_score_threshold(ranking_score_threshold)
5351
+
5244
5352
  body = _process_search_parameters(
5245
5353
  q=query,
5246
5354
  facet_name=facet_name,
@@ -5264,6 +5372,7 @@ class Index(_BaseIndex):
5264
5372
  attributes_to_search_on=attributes_to_search_on,
5265
5373
  show_ranking_score=show_ranking_score,
5266
5374
  show_ranking_score_details=show_ranking_score_details,
5375
+ ranking_score_threshold=ranking_score_threshold,
5267
5376
  vector=vector,
5268
5377
  )
5269
5378
 
@@ -5291,6 +5400,7 @@ class Index(_BaseIndex):
5291
5400
  attributes_to_search_on=attributes_to_search_on,
5292
5401
  show_ranking_score=show_ranking_score,
5293
5402
  show_ranking_score_details=show_ranking_score_details,
5403
+ ranking_score_threshold=ranking_score_threshold,
5294
5404
  vector=vector,
5295
5405
  )
5296
5406
 
@@ -5303,6 +5413,73 @@ class Index(_BaseIndex):
5303
5413
 
5304
5414
  return result
5305
5415
 
5416
+ def search_similar_documents(
5417
+ self,
5418
+ id: str,
5419
+ *,
5420
+ offset: int | None = None,
5421
+ limit: int | None = None,
5422
+ filter: str | None = None,
5423
+ embedder: str = "default",
5424
+ attributes_to_retrieve: list[str] | None = None,
5425
+ show_ranking_score: bool = False,
5426
+ show_ranking_score_details: bool = False,
5427
+ ranking_score_threshold: float | None = None,
5428
+ ) -> SimilarSearchResults:
5429
+ """Search the index.
5430
+
5431
+ Args:
5432
+ id: The id for the target document that is being used to find similar documents.
5433
+ offset: Number of documents to skip. Defaults to 0.
5434
+ limit: Maximum number of documents returned. Defaults to 20.
5435
+ filter: Filter queries by an attribute value. Defaults to None.
5436
+ embedder: The vector DB to use for the search.
5437
+ attributes_to_retrieve: Attributes to display in the returned documents.
5438
+ Defaults to ["*"].
5439
+ show_ranking_score: If set to True the ranking score will be returned with each document
5440
+ in the search. Defaults to False.
5441
+ show_ranking_score_details: If set to True the ranking details will be returned with
5442
+ each document in the search. Defaults to False.
5443
+ ranking_score_threshold: If set, no document whose _rankingScore is under the
5444
+ rankingScoreThreshold is returned. The value must be between 0.0 and 1.0. Defaults
5445
+ to None.
5446
+
5447
+ Returns:
5448
+
5449
+ Results of the search
5450
+
5451
+ Raises:
5452
+
5453
+ MeilisearchCommunicationError: If there was an error communicating with the server.
5454
+ MeilisearchApiError: If the Meilisearch API returned an error.
5455
+
5456
+ Examples:
5457
+
5458
+ >>> from meilisearch_python_sdk import Client
5459
+ >>> client = Client("http://localhost.com", "masterKey")
5460
+ >>> index = client.index("movies")
5461
+ >>> search_results = index.search_similar_documents("123")
5462
+ """
5463
+ payload = {
5464
+ "id": id,
5465
+ "filter": filter,
5466
+ "embedder": embedder,
5467
+ "attributesToRetrieve": attributes_to_retrieve,
5468
+ "showRankingScore": show_ranking_score,
5469
+ "showRankingScoreDetails": show_ranking_score_details,
5470
+ "rankingScoreThreshold": ranking_score_threshold,
5471
+ }
5472
+
5473
+ if offset:
5474
+ payload["offset"] = offset
5475
+
5476
+ if limit:
5477
+ payload["limit"] = limit
5478
+
5479
+ response = self._http_requests.post(f"{self._base_url_with_uid}/similar", body=payload)
5480
+
5481
+ return SimilarSearchResults(**response.json())
5482
+
5306
5483
  def get_document(self, document_id: str) -> JsonDict:
5307
5484
  """Get one document with given document identifier.
5308
5485
 
@@ -8072,7 +8249,7 @@ async def _async_load_documents_from_file(
8072
8249
  and not csv_delimiter.isascii()
8073
8250
  ):
8074
8251
  raise ValueError("csv_delimiter must be a single ascii character")
8075
- with open(file_path) as f:
8252
+ with open(file_path) as f: # noqa: ASYNC101 ASYNC230
8076
8253
  if csv_delimiter:
8077
8254
  documents = await loop.run_in_executor(
8078
8255
  None, partial(DictReader, f, delimiter=csv_delimiter)
@@ -8082,7 +8259,7 @@ async def _async_load_documents_from_file(
8082
8259
  return list(documents)
8083
8260
 
8084
8261
  if file_path.suffix == ".ndjson":
8085
- with open(file_path) as f:
8262
+ with open(file_path) as f: # noqa: ASYNC101 ASYNC230
8086
8263
  return [await loop.run_in_executor(None, partial(json.loads, x)) for x in f]
8087
8264
 
8088
8265
  async with aiofiles.open(file_path, mode="r") as f: # type: ignore
@@ -8192,6 +8369,7 @@ def _process_search_parameters(
8192
8369
  attributes_to_search_on: list[str] | None = None,
8193
8370
  show_ranking_score: bool = False,
8194
8371
  show_ranking_score_details: bool = False,
8372
+ ranking_score_threshold: float | None = None,
8195
8373
  vector: list[float] | None = None,
8196
8374
  hybrid: Hybrid | None = None,
8197
8375
  ) -> JsonDict:
@@ -8218,6 +8396,7 @@ def _process_search_parameters(
8218
8396
  "page": page,
8219
8397
  "attributesToSearchOn": attributes_to_search_on,
8220
8398
  "showRankingScore": show_ranking_score,
8399
+ "rankingScoreThreshold": ranking_score_threshold,
8221
8400
  }
8222
8401
 
8223
8402
  if facet_name:
@@ -8311,3 +8490,8 @@ def _embedder_json_to_settings_model( # pragma: no cover
8311
8490
  def _validate_file_type(file_path: Path) -> None:
8312
8491
  if file_path.suffix not in (".json", ".csv", ".ndjson"):
8313
8492
  raise MeilisearchError("File must be a json, ndjson, or csv file")
8493
+
8494
+
8495
+ def _validate_ranking_score_threshold(ranking_score_threshold: float) -> None:
8496
+ if not 0.0 <= ranking_score_threshold <= 1.0:
8497
+ raise MeilisearchError("ranking_score_threshold must be between 0.0 and 1.0")
@@ -1,8 +1,11 @@
1
1
  from typing import List, Optional
2
+ from warnings import warn
2
3
 
4
+ import pydantic
3
5
  from camel_converter.pydantic_base import CamelBase
4
- from pydantic import Field
5
6
 
7
+ from meilisearch_python_sdk._utils import is_pydantic_2
8
+ from meilisearch_python_sdk.errors import MeilisearchError
6
9
  from meilisearch_python_sdk.types import Filter, JsonDict
7
10
 
8
11
 
@@ -24,7 +27,7 @@ class Hybrid(CamelBase):
24
27
 
25
28
  class SearchParams(CamelBase):
26
29
  index_uid: str
27
- query: Optional[str] = Field(None, alias="q")
30
+ query: Optional[str] = pydantic.Field(None, alias="q")
28
31
  offset: int = 0
29
32
  limit: int = 20
30
33
  filter: Optional[Filter] = None
@@ -44,9 +47,35 @@ class SearchParams(CamelBase):
44
47
  attributes_to_search_on: Optional[List[str]] = None
45
48
  show_ranking_score: bool = False
46
49
  show_ranking_score_details: bool = False
50
+ ranking_score_threshold: Optional[float] = None
47
51
  vector: Optional[List[float]] = None
48
52
  hybrid: Optional[Hybrid] = None
49
53
 
54
+ if is_pydantic_2():
55
+
56
+ @pydantic.field_validator("ranking_score_threshold", mode="before") # type: ignore[attr-defined]
57
+ @classmethod
58
+ def validate_ranking_score_threshold(cls, v: Optional[float]) -> Optional[float]:
59
+ if v and not 0.0 <= v <= 1.0:
60
+ raise MeilisearchError("ranking_score_threshold must be between 0.0 and 1.0")
61
+
62
+ return v
63
+
64
+ else: # pragma: no cover
65
+ warn(
66
+ "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
67
+ DeprecationWarning,
68
+ stacklevel=2,
69
+ )
70
+
71
+ @pydantic.validator("ranking_score_threshold", pre=True)
72
+ @classmethod
73
+ def validate_expires_at(cls, v: Optional[float]) -> Optional[float]:
74
+ if v and not 0.0 <= v <= 1.0:
75
+ raise MeilisearchError("ranking_score_threshold must be between 0.0 and 1.0")
76
+
77
+ return v
78
+
50
79
 
51
80
  class SearchResults(CamelBase):
52
81
  hits: List[JsonDict]
@@ -65,3 +94,12 @@ class SearchResults(CamelBase):
65
94
 
66
95
  class SearchResultsWithUID(SearchResults):
67
96
  index_uid: str
97
+
98
+
99
+ class SimilarSearchResults(CamelBase):
100
+ hits: List[JsonDict]
101
+ id: str
102
+ processing_time_ms: int
103
+ limit: Optional[int] = None
104
+ offset: Optional[int] = None
105
+ estimated_total_hits: Optional[int] = None
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "meilisearch-python-sdk"
3
- version = "2.10.1"
3
+ version = "2.11.0"
4
4
  description = "A Python client providing both async and sync support for the Meilisearch API"
5
5
  authors = ["Paul Sanders <psanders1@gmail.com>"]
6
6
  license = "MIT"
@@ -40,7 +40,8 @@ pre-commit = ">=2.20.0"
40
40
  pytest = ">=7.1.3"
41
41
  pytest-cov = ">=4.0.0"
42
42
  pytest-asyncio = ">=0.19.0"
43
- ruff = ">=0.0.259"
43
+ pytest-xdist = ">=3.6.1"
44
+ ruff = ">=0.1.2"
44
45
  tomli = {version = ">=2.0.1", python = "<3.11"}
45
46
  types-aiofiles = ">=22.1.0"
46
47
 
@@ -56,6 +57,7 @@ build-backend = "poetry.core.masonry.api"
56
57
  minversion = "6.0"
57
58
  addopts = "--cov=meilisearch_python_sdk --cov-report term-missing --no-cov-on-fail"
58
59
  asyncio_mode = "auto"
60
+ markers = ["no_parallel"]
59
61
 
60
62
  [tool.mypy]
61
63
  check_untyped_defs = true
@@ -76,7 +78,16 @@ target-version = "py38"
76
78
  fix = true
77
79
 
78
80
  [tool.ruff.lint]
79
- select=["E", "B", "F", "UP", "I001", "T201", "T203"]
81
+ select=[
82
+ "E", # pycodestyle
83
+ "B", #
84
+ "F", # pyflakes
85
+ "UP", # pyupgrade
86
+ "I001", # unsorted-imports
87
+ "T201",
88
+ "T203",
89
+ "ASYNC" # flake8-async
90
+ ]
80
91
  ignore=[
81
92
  # Recommened ignores by ruff when using formatter
82
93
  "E501",
@@ -1 +0,0 @@
1
- VERSION = "2.10.1"