Skip to content

Commit 98d508c

Browse files
committed
ruff updates
1 parent 40bef0e commit 98d508c

9 files changed

Lines changed: 477 additions & 235 deletions

File tree

sdks/python/sdk/src/moss/__init__.pyi

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,76 @@ from __future__ import annotations
22

33
from typing import ClassVar, Dict, List, Optional, Sequence, Tuple
44

5-
65
class MossClient:
76
"""Semantic search client for vector similarity operations."""
87

98
DEFAULT_MODEL_ID: ClassVar[str]
109

1110
def __init__(self, project_id: str, project_key: str) -> None: ...
12-
1311
async def session(
1412
self,
1513
index_name: str,
1614
model_id: Optional[str] = None,
1715
) -> SessionIndex: ...
18-
1916
async def create_index(
2017
self,
2118
name: str,
2219
docs: List[DocumentInfo],
2320
model_id: Optional[str] = ...,
2421
) -> MutationResult: ...
25-
2622
async def create_index_from_files(
2723
self,
2824
name: str,
2925
files: List[ParseFileInput],
3026
model_id: Optional[str] = None,
3127
) -> MutationResult: ...
32-
3328
async def add_docs(
3429
self,
3530
name: str,
3631
docs: List[DocumentInfo],
3732
options: Optional[MutationOptions] = None,
3833
) -> MutationResult: ...
39-
4034
async def delete_docs(
4135
self,
4236
name: str,
4337
doc_ids: List[str],
4438
) -> MutationResult: ...
45-
4639
async def get_job_status(self, job_id: str) -> JobStatusResponse: ...
47-
4840
async def get_index(self, name: str) -> IndexInfo: ...
49-
5041
async def list_indexes(self) -> List[IndexInfo]: ...
51-
5242
async def delete_index(self, name: str) -> bool: ...
53-
5443
async def get_docs(
5544
self,
5645
name: str,
5746
options: Optional[GetDocumentsOptions] = None,
5847
) -> List[DocumentInfo]: ...
59-
6048
async def load_index(
6149
self,
6250
name: str,
6351
auto_refresh: bool = False,
6452
polling_interval_in_seconds: int = 600,
6553
) -> str: ...
66-
6754
async def unload_index(self, name: str) -> None: ...
68-
6955
async def load_indexes(
7056
self,
7157
names: List[str],
7258
auto_refresh: bool = False,
7359
polling_interval_in_seconds: int = 600,
7460
) -> LoadIndexesResult: ...
75-
7661
async def unload_indexes(self, names: List[str]) -> None: ...
77-
7862
async def query(
7963
self,
8064
name: str,
8165
query: str,
8266
options: Optional[QueryOptions] = None,
8367
) -> SearchResult: ...
84-
8568
async def query_multi_index(
8669
self,
8770
names: List[str],
8871
query: str,
8972
options: Optional[QueryOptions] = None,
9073
) -> SearchResult: ...
9174

92-
9375
class SessionIndex:
9476
"""Local in-session index for real-time indexing and querying."""
9577

@@ -101,23 +83,18 @@ class SessionIndex:
10183
docs: List[DocumentInfo],
10284
options: Optional[MutationOptions] = None,
10385
) -> Tuple[int, int]: ...
104-
10586
async def delete_docs(self, doc_ids: List[str]) -> int: ...
106-
10787
async def get_docs(
10888
self,
10989
options: Optional[GetDocumentsOptions] = None,
11090
) -> List[DocumentInfo]: ...
111-
11291
async def query(
11392
self,
11493
query: str,
11594
options: Optional[QueryOptions] = None,
11695
) -> SearchResult: ...
117-
11896
async def push_index(self) -> PushIndexResult: ...
11997

120-
12198
class ParseFileInput:
12299
"""Input descriptor for a single file in the parse pipeline."""
123100

@@ -134,7 +111,6 @@ class ParseFileInput:
134111
data: Optional[bytes] = None,
135112
) -> None: ...
136113

137-
138114
class PushIndexResult:
139115
"""Result from SessionIndex.push_index()."""
140116

@@ -143,7 +119,6 @@ class PushIndexResult:
143119
doc_count: int
144120
status: str
145121

146-
147122
class LoadIndexesResult:
148123
"""Outcome of a load_indexes call. Best-effort across the batch."""
149124

@@ -156,31 +131,27 @@ class LoadIndexesResult:
156131
failed: Optional[Dict[str, str]] = None,
157132
) -> None: ...
158133

159-
160134
class MutationResult:
161135
"""Return value from create_index / add_docs / delete_docs."""
162136

163137
job_id: str
164138
index_name: str
165139
doc_count: int
166140

167-
168141
class MutationOptions:
169142
"""Options for add_docs (e.g. upsert behavior)."""
170143

171144
upsert: Optional[bool]
172145

173146
def __init__(self, upsert: Optional[bool] = None) -> None: ...
174147

175-
176148
class GetDocumentsOptions:
177149
"""Options for get_docs (e.g. filter by document IDs)."""
178150

179151
doc_ids: Optional[List[str]]
180152

181153
def __init__(self, doc_ids: Optional[List[str]] = None) -> None: ...
182154

183-
184155
class JobStatus:
185156
PENDING_UPLOAD: ClassVar[str]
186157
UPLOADING: ClassVar[str]
@@ -190,7 +161,6 @@ class JobStatus:
190161

191162
value: str
192163

193-
194164
class JobPhase:
195165
DOWNLOADING: ClassVar[str]
196166
DESERIALIZING: ClassVar[str]
@@ -201,14 +171,12 @@ class JobPhase:
201171

202172
value: str
203173

204-
205174
class JobProgress:
206175
job_id: str
207176
status: JobStatus
208177
progress: float
209178
current_phase: Optional[JobPhase]
210179

211-
212180
class JobStatusResponse:
213181
job_id: str
214182
status: JobStatus
@@ -219,13 +187,11 @@ class JobStatusResponse:
219187
updated_at: str
220188
completed_at: Optional[str]
221189

222-
223190
class ModelRef:
224191
id: str
225192
version: str
226193
def __init__(self, id: str, version: str) -> None: ...
227194

228-
229195
class QueryResultDocumentInfo:
230196
id: str
231197
text: str
@@ -241,7 +207,6 @@ class QueryResultDocumentInfo:
241207
index_name: Optional[str] = ...,
242208
) -> None: ...
243209

244-
245210
class DocumentInfo:
246211
id: str
247212
text: str
@@ -255,7 +220,6 @@ class DocumentInfo:
255220
embedding: Optional[Sequence[float]] = ...,
256221
) -> None: ...
257222

258-
259223
class QueryOptions:
260224
embedding: Optional[Sequence[float]]
261225
top_k: Optional[int]
@@ -269,7 +233,6 @@ class QueryOptions:
269233
filter: Optional[dict] = ...,
270234
) -> None: ...
271235

272-
273236
class IndexInfo:
274237
id: str
275238
name: str
@@ -291,7 +254,6 @@ class IndexInfo:
291254
model: ModelRef,
292255
) -> None: ...
293256

294-
295257
class SearchResult:
296258
docs: List[QueryResultDocumentInfo]
297259
query: str
@@ -305,15 +267,13 @@ class SearchResult:
305267
time_taken_ms: Optional[int] = None,
306268
) -> None: ...
307269

308-
309270
class IndexStatus:
310271
NotStarted: ClassVar[str]
311272
Building: ClassVar[str]
312273
Ready: ClassVar[str]
313274
Failed: ClassVar[str]
314275
def __init__(self, value: str) -> None: ...
315276

316-
317277
IndexStatusValues: Dict[str, str]
318278

319279
__version__: str

sdks/python/sdk/src/moss/client/moss_client.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import httpx
1111

12-
_DEFAULT_MANAGE_URL = "https://service.usemoss.dev/v1/manage"
13-
1412
from moss_core import (
1513
ManageClient,
1614
DocumentInfo,
@@ -30,6 +28,8 @@
3028

3129
logger = logging.getLogger(__name__)
3230

31+
_DEFAULT_MANAGE_URL = "https://service.usemoss.dev/v1/manage"
32+
3333

3434
def _get_manage_url() -> str:
3535
"""Manage URL, overridable via env for staging/local/self-hosted setups."""
@@ -59,6 +59,7 @@ class ParseFileInput:
5959
Both ``name`` and ``content_type`` are required. Only ``"application/pdf"``
6060
is currently supported as ``content_type``.
6161
"""
62+
6263
name: str
6364
content_type: str
6465
path: Optional[str] = None
@@ -94,8 +95,12 @@ def __init__(self, project_id: str, project_key: str) -> None:
9495
self._project_key = project_key
9596
self._client_id = str(uuid.uuid4())
9697
manage_url = _get_manage_url()
97-
self._manage = ManageClient(project_id, project_key, manage_url, self._client_id)
98-
self._manager = IndexManager(project_id, project_key, manage_url, self._client_id)
98+
self._manage = ManageClient(
99+
project_id, project_key, manage_url, self._client_id
100+
)
101+
self._manager = IndexManager(
102+
project_id, project_key, manage_url, self._client_id
103+
)
99104

100105
# -- Mutations --------------------------------------------------
101106

@@ -108,7 +113,10 @@ async def create_index(
108113
"""Create a new index and populate it with documents."""
109114
resolved_model_id = self._resolve_model_id(docs, model_id)
110115
return await asyncio.to_thread(
111-
self._manage.create_index, name, docs, resolved_model_id,
116+
self._manage.create_index,
117+
name,
118+
docs,
119+
resolved_model_id,
112120
)
113121

114122
async def create_index_from_files(
@@ -139,6 +147,7 @@ async def create_index_from_files(
139147
"Use create_index() with pre-computed embeddings instead."
140148
)
141149
from moss_core import ParseFileInput as CoreParseFileInput
150+
142151
core_files = [
143152
CoreParseFileInput(f.name, f.content_type, path=f.path, data=f.data)
144153
for f in files
@@ -155,7 +164,10 @@ async def add_docs(
155164
) -> MutationResult:
156165
"""Add or update documents in an index."""
157166
return await asyncio.to_thread(
158-
self._manage.add_docs, name, docs, options,
167+
self._manage.add_docs,
168+
name,
169+
docs,
170+
options,
159171
)
160172

161173
async def delete_docs(
@@ -165,7 +177,9 @@ async def delete_docs(
165177
) -> MutationResult:
166178
"""Delete documents from an index by their IDs."""
167179
return await asyncio.to_thread(
168-
self._manage.delete_docs, name, doc_ids,
180+
self._manage.delete_docs,
181+
name,
182+
doc_ids,
169183
)
170184

171185
async def get_job_status(self, job_id: str) -> JobStatusResponse:
@@ -210,7 +224,10 @@ async def load_index(
210224
"""
211225
try:
212226
await asyncio.to_thread(
213-
self._manager.load_index, name, auto_refresh, polling_interval_in_seconds,
227+
self._manager.load_index,
228+
name,
229+
auto_refresh,
230+
polling_interval_in_seconds,
214231
)
215232
await asyncio.to_thread(self._manager.load_query_model, name)
216233
return name
@@ -429,7 +446,12 @@ async def _query_local(
429446
if query_embedding is None:
430447
try:
431448
return await asyncio.to_thread(
432-
self._manager.query_text, name, query, top_k, alpha, filter_,
449+
self._manager.query_text,
450+
name,
451+
query,
452+
top_k,
453+
alpha,
454+
filter_,
433455
)
434456
except RuntimeError as e:
435457
if "requires explicit query embeddings" in str(e):
@@ -440,7 +462,13 @@ async def _query_local(
440462
raise
441463

442464
return await asyncio.to_thread(
443-
self._manager.query, name, query, list(query_embedding), top_k, alpha, filter_,
465+
self._manager.query,
466+
name,
467+
query,
468+
list(query_embedding),
469+
top_k,
470+
alpha,
471+
filter_,
444472
)
445473

446474
async def _query_cloud(

sdks/python/sdk/tests/test_cloud_fallback.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ async def cloud_fallback_index(self, moss_client):
5151
index_name = generate_unique_index_name("test-cloud-fallback")
5252

5353
# Create the index with documents
54-
docs = [
55-
DocumentInfo(id=doc["id"], text=doc["text"]) for doc in TEST_DOCUMENTS
56-
]
54+
docs = [DocumentInfo(id=doc["id"], text=doc["text"]) for doc in TEST_DOCUMENTS]
5755
await moss_client.create_index(index_name, docs, TEST_MODEL_ID)
5856

5957
yield index_name

0 commit comments

Comments
 (0)