Skip to content

Commit 18a2c8a

Browse files
authored
Add docstrings for _search_indexes (#140)
1 parent c56a988 commit 18a2c8a

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

src/yandex_cloud_ml_sdk/_search_indexes/chunking_strategy.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from yandex_cloud_ml_sdk._sdk import BaseSDK
1313

1414

15-
1615
class BaseIndexChunkingStrategy(abc.ABC):
16+
"""A class for an index chunking strategy, from which all other strategies are inherited."""
1717
@classmethod
1818
@abc.abstractmethod
1919
def _from_proto(cls, proto: Any, sdk: BaseSDK) -> BaseIndexChunkingStrategy:
@@ -35,8 +35,14 @@ def _from_upper_proto(cls, proto: ProtoChunkingStrategy, sdk: BaseSDK) -> BaseIn
3535

3636
@dataclass(frozen=True)
3737
class StaticIndexChunkingStrategy(BaseIndexChunkingStrategy):
38-
max_chunk_size_tokens: int
38+
"""
39+
This class implements a static chunking strategy (i.e. a specific strategy with specific properties).
3940
41+
It is characterized by maximum chunk size and overlap in tokens.
42+
"""
43+
#: the maximum size of each chunk in tokens
44+
max_chunk_size_tokens: int
45+
#: the number of overlapping tokens between consecutive chunks
4046
chunk_overlap_tokens: int
4147

4248
@classmethod

src/yandex_cloud_ml_sdk/_search_indexes/domain.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616
from yandex_cloud_ml_sdk._types.misc import UNDEFINED, UndefinedOr, get_defined_value, is_defined
1717
from yandex_cloud_ml_sdk._types.operation import AsyncOperation, Operation, OperationTypeT
1818
from yandex_cloud_ml_sdk._utils.coerce import ResourceType, coerce_resource_ids
19+
from yandex_cloud_ml_sdk._utils.doc import doc_from
1920
from yandex_cloud_ml_sdk._utils.sync import run_sync, run_sync_generator
2021

2122
from .index_type import BaseSearchIndexType
2223
from .search_index import AsyncSearchIndex, SearchIndex, SearchIndexTypeT
2324

2425

2526
class BaseSearchIndexes(BaseDomain, Generic[SearchIndexTypeT, OperationTypeT]):
27+
"""
28+
A class for search indexes. It is a part of Assistants API
29+
and it provides the foundation for creating and managing search indexes.
30+
"""
2631
_impl: type[SearchIndexTypeT]
2732
_operation_type: type[OperationTypeT]
2833

@@ -39,6 +44,22 @@ async def _create_deferred(
3944
expiration_policy: UndefinedOr[ExpirationPolicyAlias] = UNDEFINED,
4045
timeout: float = 60,
4146
) -> OperationTypeT:
47+
"""
48+
Create a deferred search index.
49+
50+
It returns an operation that can be used to track the creation process.
51+
52+
:param files: the files to be indexed.
53+
:param index_type: the type of the search index.
54+
:param name: the name of the search index.
55+
:param description: a description for the search index.
56+
:param labels: a set of labels for the search index.
57+
:param ttl_days: time-to-live in days for the search index.
58+
:param expiration_policy: expiration policy for the file.
59+
Assepts for passing ``static`` or ``since_last_active`` strings. Should be defined if ``ttl_days`` has been defined, otherwise both parameters should be undefined.
60+
:param timeout: the time to wait for the operation to complete.
61+
Defaults to 60 seconds.
62+
"""
4263
if is_defined(ttl_days) != is_defined(expiration_policy):
4364
raise ValueError("ttl_days and expiration policy must be both defined either undefined")
4465

@@ -83,6 +104,14 @@ async def _get(
83104
*,
84105
timeout: float = 60,
85106
) -> SearchIndexTypeT:
107+
"""Retrieve a search index by its id.
108+
109+
This method fetches an already created search index using its unique identifier.
110+
111+
:param search_index_id: the unique identifier of the search index to retrieve.
112+
:param timeout: the time to wait for the operation to complete.
113+
Defaults to 60 seconds.
114+
"""
86115
# TODO: we need a global per-sdk cache on ids to rule out
87116
# possibility we have two SearchIndexs with same ids but different fields
88117
request = GetSearchIndexRequest(search_index_id=search_index_id)
@@ -103,6 +132,15 @@ async def _list(
103132
page_size: UndefinedOr[int] = UNDEFINED,
104133
timeout: float = 60
105134
) -> AsyncIterator[SearchIndexTypeT]:
135+
"""List search indexes in the specified folder.
136+
137+
This method retrieves a list of search indexes. It continues
138+
to fetch search indexes until there are no more available.
139+
140+
:param page_size: the maximum number of search indexes to return per page.
141+
:param timeout: the time to wait for the operation to complete.
142+
Defaults to 60 seconds.
143+
"""
106144
page_token_ = ''
107145
page_size_ = get_defined_value(page_size, 0)
108146

@@ -129,10 +167,12 @@ async def _list(
129167
page_token_ = response.next_page_token
130168

131169

170+
@doc_from(BaseSearchIndexes)
132171
class AsyncSearchIndexes(BaseSearchIndexes[AsyncSearchIndex, AsyncOperation[AsyncSearchIndex]]):
133172
_impl = AsyncSearchIndex
134173
_operation_type = AsyncOperation[AsyncSearchIndex]
135174

175+
@doc_from(BaseSearchIndexes._create_deferred)
136176
async def create_deferred(
137177
self,
138178
files: ResourceType[BaseFile],
@@ -156,6 +196,7 @@ async def create_deferred(
156196
timeout=timeout
157197
)
158198

199+
@doc_from(BaseSearchIndexes._get)
159200
async def get(
160201
self,
161202
search_index_id: str,
@@ -167,6 +208,7 @@ async def get(
167208
timeout=timeout,
168209
)
169210

211+
@doc_from(BaseSearchIndexes._list)
170212
async def list(
171213
self,
172214
*,
@@ -180,6 +222,7 @@ async def list(
180222
yield search_index
181223

182224

225+
@doc_from(BaseSearchIndexes)
183226
class SearchIndexes(BaseSearchIndexes[SearchIndex, Operation[SearchIndex]]):
184227
_impl = SearchIndex
185228
_operation_type = Operation[SearchIndex]
@@ -188,6 +231,7 @@ class SearchIndexes(BaseSearchIndexes[SearchIndex, Operation[SearchIndex]]):
188231
__create_deferred = run_sync(BaseSearchIndexes._create_deferred)
189232
__list = run_sync_generator(BaseSearchIndexes._list)
190233

234+
@doc_from(BaseSearchIndexes._create_deferred)
191235
def create_deferred(
192236
self,
193237
files: ResourceType[BaseFile],
@@ -211,6 +255,7 @@ def create_deferred(
211255
timeout=timeout
212256
)
213257

258+
@doc_from(BaseSearchIndexes._get)
214259
def get(
215260
self,
216261
search_index_id: str,
@@ -222,6 +267,7 @@ def get(
222267
timeout=timeout,
223268
)
224269

270+
@doc_from(BaseSearchIndexes._list)
225271
def list(
226272
self,
227273
*,
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
# pylint: disable=no-name-in-module
21
from __future__ import annotations
32

43
from dataclasses import dataclass
54
from datetime import datetime
65

7-
from yandex.cloud.ai.assistants.v1.searchindex.search_index_file_pb2 import SearchIndexFile as ProtoSearchIndexFile
8-
96
from yandex_cloud_ml_sdk._types.resource import BaseResource
107

118

129
@dataclass(frozen=True)
13-
class SearchIndexFile(BaseResource[ProtoSearchIndexFile]):
10+
class SearchIndexFile(BaseResource):
11+
"""This class represents a file associated with a search index."""
12+
#: the unique identifier for the search index
1413
search_index_id: str
14+
#: the identifier of the user or system that created the file
1515
created_by: str
16+
#: the timestamp when the file was created
1617
created_at: datetime

src/yandex_cloud_ml_sdk/_search_indexes/normalization_strategy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99

1010

1111
class IndexNormalizationStrategy(ProtoEnumBase, enum.IntEnum):
12+
"""
13+
Enumeration for index normalization strategies.
14+
15+
This class defines the various normalization strategies that can be applied
16+
to an index.
17+
"""
18+
#: indicates that no normalization strategy has been specified
1219
NORMALIZATION_STRATEGY_UNSPECIFIED = NormalizationStrategy.NORMALIZATION_STRATEGY_UNSPECIFIED
20+
#: represents the Min-Max normalization strategy
1321
MIN_MAX = NormalizationStrategy.MIN_MAX
22+
#: represents the L2 normalization strategy
1423
L2 = NormalizationStrategy.L2

0 commit comments

Comments
 (0)