From d43d82068b18a09e46ce712c051d09e701c2b060 Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Tue, 8 Apr 2025 16:29:46 +0300 Subject: [PATCH 1/3] feat(types): add hnsw parameters to field schema --- src/typesense/types/collection.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/typesense/types/collection.py b/src/typesense/types/collection.py index e929fa6..b27de93 100644 --- a/src/typesense/types/collection.py +++ b/src/typesense/types/collection.py @@ -70,10 +70,22 @@ class CollectionFieldSchema(typing.Generic[_TType], typing.TypedDict, total=Fals symbols_to_index: typing.NotRequired[typing.List[str]] token_separators: typing.NotRequired[typing.List[str]] num_dim: typing.NotRequired[float] + hnsw_params: typing.NotRequired[HNSWParamsSchema] range_index: typing.NotRequired[bool] index: typing.NotRequired[bool] vec_dist: typing.NotRequired[typing.Union[typing.Literal["cosine", "ip"], str]] +class HNSWParamsSchema(typing.TypedDict): + """ + The schema for the HNSW parameters in the CollectionFieldSchema. + + Attributes: + M (int): The number of bi-directional links created for every new element. + ef_construction (int): The size of the dynamic list for the nearest neighbors. + """ + + M: typing.NotRequired[int] + ef_construction: typing.NotRequired[int] class RegularCollectionFieldSchema(CollectionFieldSchema[_FieldType]): """ From aabd06d38dc3466a40973844542ad5bdec75d6c5 Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Tue, 8 Apr 2025 17:18:09 +0300 Subject: [PATCH 2/3] chore: lint --- setup.cfg | 2 +- src/typesense/types/collection.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index ecafea2..088736f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,7 +23,7 @@ exclude = .git,__pycache__,venv,.eggs,*.egg,src/typesense/__init__.py ignore = Q000, WPS602, WPS432, WPS305, WPS221, WPS230, WPS234, WPS433, WPS440, W503, WPS331, WPS306, WPS237, WPS202, RST301, RST306, WPS214, WPS235, WPS226, WPS337, WPS320, F821, WPS201 per-file-ignores = tests/*.py: S101, WPS226, WPS118, WPS202, WPS204, WPS218, WPS211, WPS604, WPS431, WPS210, WPS201, WPS437 - src/typesense/types/*.py: B950, WPS215, WPS111, WPS462, WPS322, WPS428, WPS114, WPS110, WPS202 + src/typesense/types/*.py: B950, WPS215, WPS111, WPS462, WPS322, WPS428, WPS114, WPS110, WPS202, WPS115 src/typesense/documents.py: WPS320, E704, D102, WPS428, WPS220 src/typesense/stemming_dictionaries.py: WPS320, E704, D102, WPS428, WPS220 src/typesense/api_call.py: WPS110, WPS211 diff --git a/src/typesense/types/collection.py b/src/typesense/types/collection.py index b27de93..4419347 100644 --- a/src/typesense/types/collection.py +++ b/src/typesense/types/collection.py @@ -75,6 +75,7 @@ class CollectionFieldSchema(typing.Generic[_TType], typing.TypedDict, total=Fals index: typing.NotRequired[bool] vec_dist: typing.NotRequired[typing.Union[typing.Literal["cosine", "ip"], str]] + class HNSWParamsSchema(typing.TypedDict): """ The schema for the HNSW parameters in the CollectionFieldSchema. @@ -87,6 +88,7 @@ class HNSWParamsSchema(typing.TypedDict): M: typing.NotRequired[int] ef_construction: typing.NotRequired[int] + class RegularCollectionFieldSchema(CollectionFieldSchema[_FieldType]): """ The schema of a regular field in a collection. From 1df5fe0edcff46b8650dbd39d4a55156183616f0 Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Wed, 9 Apr 2025 11:41:48 +0300 Subject: [PATCH 3/3] fix(types): move hnsw params class above ref --- src/typesense/types/collection.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/typesense/types/collection.py b/src/typesense/types/collection.py index 4419347..9e8a397 100644 --- a/src/typesense/types/collection.py +++ b/src/typesense/types/collection.py @@ -36,6 +36,19 @@ Locales = typing.Literal["ja", "zh", "ko", "th", "el", "ru", "rs", "uk", "be", ""] +class HNSWParamsSchema(typing.TypedDict): + """ + The schema for the HNSW parameters in the CollectionFieldSchema. + + Attributes: + M (int): The number of bi-directional links created for every new element. + ef_construction (int): The size of the dynamic list for the nearest neighbors. + """ + + M: typing.NotRequired[int] + ef_construction: typing.NotRequired[int] + + class CollectionFieldSchema(typing.Generic[_TType], typing.TypedDict, total=False): """ CollectionFieldSchema represents the schema of a field in a collection. @@ -76,19 +89,6 @@ class CollectionFieldSchema(typing.Generic[_TType], typing.TypedDict, total=Fals vec_dist: typing.NotRequired[typing.Union[typing.Literal["cosine", "ip"], str]] -class HNSWParamsSchema(typing.TypedDict): - """ - The schema for the HNSW parameters in the CollectionFieldSchema. - - Attributes: - M (int): The number of bi-directional links created for every new element. - ef_construction (int): The size of the dynamic list for the nearest neighbors. - """ - - M: typing.NotRequired[int] - ef_construction: typing.NotRequired[int] - - class RegularCollectionFieldSchema(CollectionFieldSchema[_FieldType]): """ The schema of a regular field in a collection.