-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_integration.py
More file actions
805 lines (703 loc) · 29 KB
/
test_integration.py
File metadata and controls
805 lines (703 loc) · 29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
"""
Comprehensive integration tests for Pharia SDK — exercises every resource method
against the live API using the fluent API pattern.
Requires PHARIA_DATA_API_BASE_URL and PHARIA_API_KEY env vars.
Known issues discovered during testing:
- MediaType.JSON ("json") is rejected by the API; use "application/json" instead.
- Dataset creation requires multipart/form-data; the SDK sends JSON — dataset
create/update_datapoints are broken at the SDK level.
- PresignedURL TypedDict doesn't match the actual API response shape.
- Document schemaVersion must be "V1" (not "1").
"""
import uuid
import httpx
import pytest
from pharia import And
from pharia import Client
from pharia import Filter
from pharia.models import MediaType
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
PREFIX = f"sdk-e2e-{uuid.uuid4().hex[:8]}"
def unique(label: str) -> str:
return f"{PREFIX}-{label}-{uuid.uuid4().hex[:6]}"
# ---------------------------------------------------------------------------
# Client
# ---------------------------------------------------------------------------
class TestClient:
"""Client initialisation and option helpers."""
def test_client_init(self):
client = Client()
assert client.base_url
assert client.api_key
assert "Authorization" in client.headers
def test_with_options(self):
client = Client()
new = client.with_options(timeout=42.0)
assert new.timeout == 42.0
assert new.api_key == client.api_key
def test_with_namespace(self):
client = Client()
ns = client.with_namespace("/api/v1")
assert ns.base_url.endswith("/api/v1")
class TestStages:
"""Full CRUD + embedding helpers for stages."""
@pytest.mark.asyncio
async def test_list_stages(self):
client = Client()
resp = await client.v1.stages.list(page=0, size=5)
assert "total" in resp
assert "stages" in resp
@pytest.mark.asyncio
async def test_list_stages_with_filters(self):
client = Client()
resp = await client.v1.stages.list(page=0, size=5, with_search_store=True)
assert "total" in resp
resp2 = await client.v1.stages.list(page=0, size=5, name="nonexistent-xyz")
assert resp2["total"] == 0 or "stages" in resp2
@pytest.mark.asyncio
async def test_create_simple_stage_and_delete(self):
client = Client()
name = unique("simple-stage")
stage = await client.v1.stages.create(name=name)
assert stage["stageId"]
assert stage["name"] == name
# GET
got = await client.v1.stages(stage["stageId"]).get()
assert got["stageId"] == stage["stageId"]
# DELETE
await client.v1.stages(stage["stageId"]).delete()
@pytest.mark.asyncio
async def test_create_and_update_stage(self):
client = Client()
stage = await client.v1.stages.create(name=unique("update-stage"))
sid = stage["stageId"]
try:
updated = await client.v1.stages(sid).update(access_policy="private")
assert updated is not None
finally:
await client.v1.stages(sid).delete()
@pytest.mark.asyncio
async def test_batch_get_and_delete(self):
client = Client()
s1 = await client.v1.stages.create(name=unique("batch-1"))
s2 = await client.v1.stages.create(name=unique("batch-2"))
ids = [s1["stageId"], s2["stageId"]]
try:
results = await client.v1.stages(*ids).get(concurrency=5)
assert len(results) == 2
finally:
await client.v1.stages(*ids).delete(concurrency=5)
@pytest.mark.asyncio
async def test_instruct_stage(self):
client = Client()
stage = await client.v1.stages.instruct.create(
name=unique("instruct-stage"),
embedding_model="pharia-1-embedding-4608-control",
instruction_document="Represent the document for retrieval",
instruction_query="Represent the query for retrieval",
hybrid_index="bm25",
max_chunk_size_tokens=512,
chunk_overlap_tokens=128,
)
assert stage["stageId"]
ss = stage.get("searchStore")
assert ss is not None
assert ss["embeddingStrategy"]["type"] == "instruct"
await client.v1.stages(stage["stageId"]).delete()
@pytest.mark.asyncio
async def test_semantic_stage(self):
client = Client()
stage = await client.v1.stages.semantic.create(
name=unique("semantic-stage"),
embedding_model="luminous-base",
representation="asymmetric",
hybrid_index="bm25",
max_chunk_size_tokens=1024,
chunk_overlap_tokens=256,
)
assert stage["stageId"]
ss = stage.get("searchStore")
assert ss is not None
assert ss["embeddingStrategy"]["type"] == "semantic"
await client.v1.stages(stage["stageId"]).delete()
@pytest.mark.asyncio
async def test_vllm_stage(self):
client = Client()
stage = await client.v1.stages.vllm.create(
name=unique("vllm-stage"),
embedding_model="qwen3-embedding-8b",
hybrid_index="bm25",
max_chunk_size_tokens=2046,
chunk_overlap_tokens=512,
)
assert stage["stageId"]
assert stage.get("searchStore") is not None
await client.v1.stages(stage["stageId"]).delete()
# ---------------------------------------------------------------------------
# Stage Runs
# ---------------------------------------------------------------------------
class TestStageRuns:
@pytest.mark.asyncio
async def test_list_runs(self):
client = Client()
stage = await client.v1.stages.create(name=unique("runs-list"))
sid = stage["stageId"]
try:
runs = await client.v1.stages(sid).runs.list(page=0, size=5)
assert "total" in runs
assert "runs" in runs
finally:
await client.v1.stages(sid).delete()
# ---------------------------------------------------------------------------
# Stage Files (list / get / presigned_url)
# ---------------------------------------------------------------------------
class TestStageFiles:
@pytest.mark.asyncio
async def test_list_files(self):
client = Client()
stage = await client.v1.stages.create(name=unique("files-list"))
sid = stage["stageId"]
try:
files = await client.v1.stages(sid).files.list(page=0, size=5)
assert "total" in files
assert "files" in files
finally:
await client.v1.stages(sid).delete()
@pytest.mark.asyncio
async def test_list_files_with_name_filter(self):
client = Client()
stage = await client.v1.stages.create(name=unique("files-filter"))
sid = stage["stageId"]
try:
files = await client.v1.stages(sid).files.list(page=0, size=5, name="nonexistent")
assert "total" in files
finally:
await client.v1.stages(sid).delete()
@pytest.mark.asyncio
async def test_get_file_content(self):
"""Upload a file, download it, verify bytes match."""
client = Client()
stage = await client.v1.stages.create(name=unique("file-get"))
sid = stage["stageId"]
try:
payload = b'{"hello": "world"}\n'
uploaded = await client.v1.stages(sid).files.upload(
source_data=payload, filename="test.jsonl", media_type="application/x-ndjson"
)
fid = uploaded["fileId"]
content = await client.v1.stages(sid).files(fid).get()
assert isinstance(content, bytes)
assert content == payload
finally:
await client.v1.stages(sid).delete()
@pytest.mark.asyncio
async def test_presigned_url(self):
"""Upload a file, get its presigned URL."""
client = Client()
stage = await client.v1.stages.create(name=unique("file-presign"))
sid = stage["stageId"]
try:
uploaded = await client.v1.stages(sid).files.upload(
source_data=b"test content", filename="test.txt", media_type="text/plain"
)
fid = uploaded["fileId"]
purl = await client.v1.stages(sid).files(fid).presigned_url(ttl=60)
assert purl.get("presignedUrl") or purl.get("url")
finally:
await client.v1.stages(sid).delete()
class TestRepositories:
@pytest.mark.asyncio
async def test_list_repositories(self):
client = Client()
resp = await client.v1.repositories.list(page=0, size=5)
assert "total" in resp
assert "repositories" in resp
@pytest.mark.asyncio
async def test_create_get_delete_repository(self):
client = Client()
name = unique("repo")
repo = await client.v1.repositories.create(
name=name, media_type=MediaType.JSONLINES, modality="text"
)
rid = repo["repositoryId"]
assert rid
assert repo["name"] == name
got = await client.v1.repositories(rid).get()
assert got["repositoryId"] == rid
await client.v1.repositories(rid).delete()
@pytest.mark.asyncio
async def test_batch_get_repositories(self):
client = Client()
r1 = await client.v1.repositories.create(
name=unique("batch-repo-1"), media_type=MediaType.JSONLINES, modality="text"
)
r2 = await client.v1.repositories.create(
name=unique("batch-repo-2"), media_type=MediaType.JSONLINES, modality="text"
)
ids = [r1["repositoryId"], r2["repositoryId"]]
try:
results = await client.v1.repositories(*ids).get()
assert len(results) == 2
finally:
await client.v1.repositories(*ids).delete()
# ---------------------------------------------------------------------------
# Datasets
# NOTE: dataset creation requires multipart/form-data but the SDK sends JSON.
# These tests document the known SDK limitation.
# ---------------------------------------------------------------------------
class TestDatasets:
@pytest.mark.asyncio
async def test_list_datasets(self):
"""Listing datasets on an existing repo works (GET endpoint)."""
client = Client()
repos = await client.v1.repositories.list(page=0, size=10)
if not repos["repositories"]:
pytest.skip("No repositories to list datasets from")
for repo in repos["repositories"]:
rid = repo["repositoryId"]
try:
ds_list = await client.v1.repositories(rid).datasets.list(page=0, size=5)
assert "total" in ds_list
assert "datasets" in ds_list
return
except httpx.HTTPStatusError:
continue
pytest.skip("No repositories with datasets endpoint available")
@pytest.mark.asyncio
async def test_get_existing_dataset(self):
"""Get an existing dataset if one exists."""
client = Client()
repos = await client.v1.repositories.list(page=0, size=10)
for repo in repos.get("repositories", []):
rid = repo["repositoryId"]
try:
ds_list = await client.v1.repositories(rid).datasets.list(page=0, size=1)
except httpx.HTTPStatusError:
continue
if ds_list.get("datasets"):
did = ds_list["datasets"][0]["datasetId"]
ds = await client.v1.repositories(rid).datasets(did).get()
assert ds["datasetId"] == did
return
pytest.skip("No datasets found in any repository")
@pytest.mark.asyncio
async def test_create_dataset_known_broken(self):
"""Dataset creation fails: API requires multipart/form-data, SDK sends JSON."""
client = Client()
repo = await client.v1.repositories.create(
name=unique("ds-repo"), media_type=MediaType.JSONLINES, modality="text"
)
rid = repo["repositoryId"]
try:
with pytest.raises(httpx.HTTPStatusError):
await client.v1.repositories(rid).datasets.create(name=unique("ds"))
finally:
await client.v1.repositories(rid).delete()
class TestBatchStageNested:
"""E2E tests for batch stage .files and .runs fan-out."""
@pytest.mark.asyncio
async def test_batch_stages_files_list(self):
client = Client()
s1 = await client.v1.stages.create(name=unique("bfiles-1"))
s2 = await client.v1.stages.create(name=unique("bfiles-2"))
ids = [s1["stageId"], s2["stageId"]]
try:
results = await client.v1.stages(*ids).files.list(page=0, size=5)
assert len(results) == 2
for r in results:
assert "total" in r
assert "files" in r
finally:
await client.v1.stages(*ids).delete()
@pytest.mark.asyncio
async def test_batch_stages_runs_list(self):
client = Client()
s1 = await client.v1.stages.create(name=unique("bruns-1"))
s2 = await client.v1.stages.create(name=unique("bruns-2"))
ids = [s1["stageId"], s2["stageId"]]
try:
results = await client.v1.stages(*ids).runs.list(page=0, size=5)
assert len(results) == 2
for r in results:
assert "total" in r
assert "runs" in r
finally:
await client.v1.stages(*ids).delete()
class TestBatchSearchStoreNested:
"""E2E tests for batch search store .documents fan-out."""
@pytest.mark.asyncio
async def test_batch_search_stores_documents_list(self):
client = Client()
ss1 = await client.v1.search_stores.semantic.create(
name=unique("bdocs-ss-1"), embedding_model="luminous-base", representation="asymmetric"
)
ss2 = await client.v1.search_stores.semantic.create(
name=unique("bdocs-ss-2"), embedding_model="luminous-base", representation="asymmetric"
)
ids = [ss1["id"], ss2["id"]]
try:
results = await client.v1.search_stores(*ids).documents.list(page=1, size=5)
assert len(results) == 2
for r in results:
assert "total" in r
assert "results" in r
finally:
await client.v1.search_stores(*ids).delete()
class TestBatchRepositoryNested:
"""E2E tests for batch repository .datasets fan-out."""
@pytest.mark.asyncio
async def test_batch_repositories_datasets_list(self):
client = Client()
r1 = await client.v1.repositories.create(
name=unique("bds-repo-1"), media_type=MediaType.JSONLINES, modality="text"
)
r2 = await client.v1.repositories.create(
name=unique("bds-repo-2"), media_type=MediaType.JSONLINES, modality="text"
)
ids = [r1["repositoryId"], r2["repositoryId"]]
try:
results = await client.v1.repositories(*ids).datasets.list(page=0, size=5)
assert len(results) == 2
for r in results:
assert "total" in r
assert "datasets" in r
finally:
await client.v1.repositories(*ids).delete()
class TestBatchConnectorNested:
"""E2E tests for batch connector .files and .runs fan-out."""
@pytest.mark.asyncio
async def test_batch_connectors_files_list(self):
client = Client()
listing = await client.v1.connectors.list(page=0, size=2)
conns = listing["connectors"]
if len(conns) < 2:
pytest.skip("Need >=2 connectors for batch nested test")
ids = [c["id"] for c in conns[:2]]
results = await client.v1.connectors(*ids).files.list(page=0, size=5)
assert len(results) == 2
for r in results:
assert "total" in r
@pytest.mark.asyncio
async def test_batch_connectors_runs_list(self):
client = Client()
listing = await client.v1.connectors.list(page=0, size=2)
conns = listing["connectors"]
if len(conns) < 2:
pytest.skip("Need >=2 connectors for batch nested test")
ids = [c["id"] for c in conns[:2]]
results = await client.v1.connectors(*ids).runs.list(page=0, size=5)
assert len(results) == 2
for r in results:
assert "total" in r
assert "runs" in r
class TestConnectors:
@pytest.mark.asyncio
async def test_list_connectors(self):
client = Client()
resp = await client.v1.connectors.list(page=0, size=5)
assert "total" in resp
assert "connectors" in resp
@pytest.mark.asyncio
async def test_list_connectors_with_filters(self):
client = Client()
resp = await client.v1.connectors.list(page=0, size=5, name="nonexistent-xyz")
assert "total" in resp
@pytest.mark.asyncio
async def test_get_connector(self):
client = Client()
listing = await client.v1.connectors.list(page=0, size=1)
if not listing["connectors"]:
pytest.skip("No connectors available")
cid = listing["connectors"][0]["id"]
conn = await client.v1.connectors(cid).get()
assert conn["id"] == cid
@pytest.mark.asyncio
async def test_connector_files(self):
client = Client()
listing = await client.v1.connectors.list(page=0, size=1)
if not listing["connectors"]:
pytest.skip("No connectors available")
cid = listing["connectors"][0]["id"]
files = await client.v1.connectors(cid).files.list(page=0, size=5)
assert "total" in files
@pytest.mark.asyncio
async def test_connector_runs(self):
client = Client()
listing = await client.v1.connectors.list(page=0, size=1)
if not listing["connectors"]:
pytest.skip("No connectors available")
cid = listing["connectors"][0]["id"]
runs = await client.v1.connectors(cid).runs.list(page=0, size=5)
assert "total" in runs
assert "runs" in runs
@pytest.mark.asyncio
async def test_batch_get_connectors(self):
client = Client()
listing = await client.v1.connectors.list(page=0, size=2)
conns = listing["connectors"]
if len(conns) < 2:
pytest.skip("Need >=2 connectors for batch test")
ids = [c["id"] for c in conns[:2]]
results = await client.v1.connectors(*ids).get()
assert len(results) == 2
# ---------------------------------------------------------------------------
# Search Stores (list / create / get / update / search / delete / batch)
# ---------------------------------------------------------------------------
class TestSearchStores:
@pytest.mark.asyncio
async def test_list_search_stores(self):
client = Client()
resp = await client.v1.search_stores.list(page=1, size=5)
assert "total" in resp
assert "results" in resp
@pytest.mark.asyncio
async def test_semantic_search_store_lifecycle(self):
client = Client()
ss = await client.v1.search_stores.semantic.create(
name=unique("semantic-ss"),
embedding_model="luminous-base",
representation="asymmetric",
max_chunk_size_tokens=512,
chunk_overlap_tokens=128,
)
ssid = ss["id"]
assert ssid
# GET
got = await client.v1.search_stores(ssid).get()
assert got["id"] == ssid
assert got["embeddingStrategy"]["type"] == "semantic"
# UPDATE
updated = await client.v1.search_stores(ssid).update(metadata={"env": "e2e-test"})
assert updated is not None
# DELETE
await client.v1.search_stores(ssid).delete()
@pytest.mark.asyncio
async def test_instruct_search_store_lifecycle(self):
client = Client()
ss = await client.v1.search_stores.instruct.create(
name=unique("instruct-ss"),
embedding_model="pharia-1-embedding-4608-control",
instruction_document="Represent the document for retrieval",
instruction_query="Represent the query for retrieval",
max_chunk_size_tokens=512,
chunk_overlap_tokens=128,
)
ssid = ss["id"]
assert ssid
assert ss["embeddingStrategy"]["type"] == "instruct"
await client.v1.search_stores(ssid).delete()
@pytest.mark.asyncio
async def test_vllm_search_store_lifecycle(self):
client = Client()
ss = await client.v1.search_stores.vllm.create(
name=unique("vllm-ss"),
embedding_model="qwen3-embedding-8b",
max_chunk_size_tokens=512,
chunk_overlap_tokens=128,
)
ssid = ss["id"]
assert ssid
assert ss["embeddingStrategy"]["type"] == "vllm"
await client.v1.search_stores(ssid).delete()
@pytest.mark.asyncio
async def test_batch_get_and_delete_search_stores(self):
client = Client()
s1 = await client.v1.search_stores.semantic.create(
name=unique("batch-ss-1"), embedding_model="luminous-base", representation="asymmetric"
)
s2 = await client.v1.search_stores.semantic.create(
name=unique("batch-ss-2"), embedding_model="luminous-base", representation="asymmetric"
)
ids = [s1["id"], s2["id"]]
try:
results = await client.v1.search_stores(*ids).get()
assert len(results) == 2
finally:
await client.v1.search_stores(*ids).delete()
@pytest.mark.asyncio
async def test_search_existing_store(self):
"""Search against an existing search store with documents."""
client = Client()
listing = await client.v1.search_stores.list(page=1, size=10)
stores = listing.get("results", [])
if not stores:
pytest.skip("No search stores available for search test")
for store in stores:
ssid = store["id"]
try:
result = await client.v1.search_stores(ssid).search(query="test", max_results=3)
assert isinstance(result, list)
return
except Exception:
continue
pytest.skip("No search store returned results")
@pytest.mark.asyncio
async def test_search_with_metadata_filter(self):
"""Upload a document with metadata, then recover it using a filter."""
client = Client()
ss = await client.v1.search_stores.vllm.create(
name=unique("filter-ss"),
embedding_model="qwen3-embedding-8b",
max_chunk_size_tokens=512,
chunk_overlap_tokens=128,
metadata_schema={"category": "string"},
)
ssid = ss["id"]
try:
doc_name = unique("filter-doc")
await (
client.v1.search_stores(ssid)
.documents(doc_name)
.create_or_update(
schema_version="V1",
contents=[
{
"modality": "text",
"text": "Machine learning is a subset of artificial intelligence.",
}
],
metadata={"category": "science"},
)
)
# Matching filter — should find the document
result = await client.v1.search_stores(ssid).search(
query="artificial intelligence",
max_results=5,
filters=[And(Filter("category") == "science")],
)
assert isinstance(result, list)
# Non-matching filter — should return nothing
result_empty = await client.v1.search_stores(ssid).search(
query="artificial intelligence",
max_results=5,
filters=[And(Filter("category") == "sports")],
)
assert isinstance(result_empty, list)
assert len(result_empty) == 0
await client.v1.search_stores(ssid).documents(doc_name).delete()
finally:
await client.v1.search_stores(ssid).delete()
class TestDocuments:
@pytest.mark.asyncio
async def test_full_document_lifecycle(self):
client = Client()
ss = await client.v1.search_stores.semantic.create(
name=unique("doc-ss"),
embedding_model="luminous-base",
representation="asymmetric",
max_chunk_size_tokens=512,
chunk_overlap_tokens=128,
)
ssid = ss["id"]
try:
docs = await client.v1.search_stores(ssid).documents.list(page=1, size=5)
assert "total" in docs
assert "results" in docs
# CREATE OR UPDATE — note: schemaVersion must be "V1"
doc_name = unique("test-doc")
doc = (
await client.v1.search_stores(ssid)
.documents(doc_name)
.create_or_update(
schema_version="V1",
contents=[
{"modality": "text", "text": "Hello world. This is a test document."}
],
metadata={"source": "e2e-test"},
)
)
assert doc["name"] == doc_name
# GET metadata
got = await client.v1.search_stores(ssid).documents(doc_name).get()
assert got["name"] == doc_name
# GET content (returns list[ContentDTO])
content = await client.v1.search_stores(ssid).documents(doc_name).get_content()
assert isinstance(content, list)
assert len(content) > 0
# LIST with starts_with filter
filtered = await client.v1.search_stores(ssid).documents.list(
page=1, size=5, starts_with=PREFIX
)
assert "results" in filtered
# DELETE
await client.v1.search_stores(ssid).documents(doc_name).delete()
finally:
await client.v1.search_stores(ssid).delete()
@pytest.mark.asyncio
async def test_batch_documents(self):
client = Client()
ss = await client.v1.search_stores.semantic.create(
name=unique("batch-doc-ss"),
embedding_model="luminous-base",
representation="asymmetric",
max_chunk_size_tokens=512,
chunk_overlap_tokens=128,
)
ssid = ss["id"]
try:
name1 = unique("bdoc-1")
name2 = unique("bdoc-2")
await (
client.v1.search_stores(ssid)
.documents(name1)
.create_or_update(
schema_version="V1", contents=[{"modality": "text", "text": "Document one."}]
)
)
await (
client.v1.search_stores(ssid)
.documents(name2)
.create_or_update(
schema_version="V1", contents=[{"modality": "text", "text": "Document two."}]
)
)
# Batch GET
results = await client.v1.search_stores(ssid).documents(name1, name2).get()
assert len(results) == 2
# Batch DELETE
await client.v1.search_stores(ssid).documents(name1, name2).delete()
finally:
await client.v1.search_stores(ssid).delete()
@pytest.mark.asyncio
async def test_search_store_with_document_and_search(self):
"""End-to-end: create store, add doc, search, clean up."""
client = Client()
ss = await client.v1.search_stores.semantic.create(
name=unique("search-doc-ss"),
embedding_model="luminous-base",
representation="asymmetric",
max_chunk_size_tokens=512,
chunk_overlap_tokens=128,
)
ssid = ss["id"]
try:
doc_name = unique("searchable-doc")
await (
client.v1.search_stores(ssid)
.documents(doc_name)
.create_or_update(
schema_version="V1",
contents=[
{
"modality": "text",
"text": (
"The quick brown fox jumps over the lazy dog. "
"Machine learning is a subset of artificial intelligence."
),
}
],
)
)
# Search may fail on freshly created stores (embeddings not indexed yet)
try:
result = await client.v1.search_stores(ssid).search(
query="artificial intelligence", max_results=5
)
assert isinstance(result, list)
except httpx.HTTPStatusError:
pass # expected on freshly created stores
await client.v1.search_stores(ssid).documents(doc_name).delete()
finally:
await client.v1.search_stores(ssid).delete()