Skip to content

Commit 9e4105d

Browse files
committed
Merge 'fix/tests' into 'main'
fix: tests, version, readme See merge request: !18
2 parents 4dea7e3 + d5a9dc4 commit 9e4105d

File tree

4 files changed

+39
-66
lines changed

4 files changed

+39
-66
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ print("search results:", result)
8888

8989
### Example Guides
9090

91-
#### Vector Examples (Pytest)
91+
#### Vector Examples
9292

93-
The integration guides under `examples/vector` mirror the Go SDK walkthroughs (`E1``E5`). Each test connects to a live VikingDB environment and exercises a specific workflow.
93+
The integration guides under `examples/vector` mirror the Go SDK walkthroughs (`1``6`). Each test connects to a live VikingDB environment and exercises a specific workflow.
9494

9595
1. Set the required environment variables (or create a `.env` file in the project root):
9696

@@ -114,13 +114,13 @@ The integration guides under `examples/vector` mirror the Go SDK walkthroughs (`
114114
2. Install pytest (if not already available):
115115

116116
```bash
117-
pip install pytest
117+
uv add --dev pytest
118118
```
119119

120120
3. Execute the guides:
121121

122122
```bash
123-
pytest examples/vector -k guide
123+
uv run pytest examples/vector -k scenario
124124
```
125125

126126
Each scenario writes temporary documents using unique session tags and cleans them up afterwards.
@@ -185,9 +185,9 @@ vikingdb/
185185
186186
examples/
187187
├── vector/ # Vector integration guides (pytest)
188-
│ ├── E1_connectivity_test.py
189-
│ ├── E2_collection_lifecycle_test.py
190-
│ ├── E3_*_test.py # Search and indexing examples
188+
│ ├── 1_connectivity_test.py
189+
│ ├── 2_collection_lifecycle_test.py
190+
│ ├── 3_*_test.py # Search and indexing examples
191191
│ └── ...
192192
└── memory/ # Memory usage examples
193193
├── 01_init_client_and_collection.py

examples/vector/6_exception_handling.py

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,61 +15,32 @@
1515

1616
from __future__ import annotations
1717

18-
import sys
18+
import os
1919

2020
from vikingdb import IAM
21-
from vikingdb.vector import VikingVector
22-
from vikingdb.vector.exceptions import VikingVectorException, VikingConnectionException
21+
from vikingdb.vector import SearchByRandomRequest, VikingVector
2322

24-
from .test_helper import EnvConfig, load_config
2523

26-
27-
def _build_vector_client(*, host_override: str | None = None, timeout: int | None = None) -> tuple[EnvConfig, VikingVector]:
28-
"""Create a VikingVector client using the shared guide configuration."""
29-
config = load_config()
30-
auth = IAM(ak=config.access_key, sk=config.secret_key)
24+
def main() -> None:
25+
"""Connectivity quickstart mirroring the snippet test."""
26+
auth = IAM(
27+
ak=os.environ["VIKINGDB_AK"],
28+
sk=os.environ["VIKINGDB_SK"],
29+
)
3130
client = VikingVector(
32-
host=host_override if host_override is not None else config.host,
33-
region=config.region,
34-
scheme=config.scheme,
31+
host=os.environ["VIKINGDB_HOST"],
32+
region=os.environ["VIKINGDB_REGION"],
3533
auth=auth,
36-
timeout=timeout if timeout is not None else 30,
34+
scheme="https",
35+
timeout=30,
36+
)
37+
index_client = client.index(
38+
collection_name="unknown",
39+
index_name="unknown",
3740
)
38-
return config, client
39-
40-
41-
def demo_collection_not_exist() -> None:
42-
"""Attempt to fetch from a non-existent collection to trigger an SDK exception."""
43-
try:
44-
config, client = _build_vector_client()
45-
missing_collection = f"{config.collection}-missing"
46-
collection_client = client.collection(
47-
collection_name=missing_collection,
48-
project_name=config.project_name,
49-
resource_id=config.resource_id,
50-
)
51-
# Intentionally request a fake ID
52-
collection_client.fetch({"ids": ["non-existent-id"]})
53-
except VikingVectorException as e:
54-
print(f"Caught VikingVectorException: code={getattr(e, 'code', None)} message={e}")
55-
56-
57-
def demo_wrong_host_network_error() -> None:
58-
"""Use an invalid host to demonstrate a network connection error."""
59-
try:
60-
_build_vector_client(host_override="in-v-alid.io", timeout=1)
61-
except VikingConnectionException as e:
62-
print(f"Caught VikingConnectionException: message={e}")
63-
64-
6541

66-
def main() -> int:
67-
print("-- Scenario 6: Exception handling demos --")
68-
demo_collection_not_exist()
69-
demo_wrong_host_network_error()
70-
print("-- Done --")
71-
return 0
42+
index_client.search_by_random(SearchByRandomRequest(limit=1))
7243

7344

7445
if __name__ == "__main__":
75-
raise SystemExit(main())
46+
main()

examples/vector/viking_test.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,26 @@
2828
VikingVector,
2929
)
3030

31-
from .test_helper import (
32-
Clients,
33-
EnvConfig,
34-
DEFAULT_REGION,
35-
EMBEDDING_MODEL_NAME,
36-
TEXT_COLLECTION,
37-
TEXT_INDEX,
31+
# Ensure local helper can be imported when running via pytest path
32+
import sys
33+
from pathlib import Path
34+
sys.path.insert(0, str(Path(__file__).parent))
35+
36+
from test_helper import (
3837
VECTOR_COLLECTION,
3938
VECTOR_INDEX,
40-
require_env_vars,
4139
load_config,
42-
build_clients,
4340
embed_dense_vectors,
44-
StoryChapter,
4541
build_story_chapters,
4642
chapters_to_upsert,
4743
assign_chapter_ids_via_search,
48-
search_chapter_by_narrative,
44+
new_session_tag,
45+
build_request_options,
46+
cleanup_chapters,
47+
bool_and_filters,
48+
session_paragraph_bounds,
49+
score_at_least_filter,
50+
assert_keyword_hit_titles,
4951
)
5052

5153

vikingdb/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
__version__ = '0.1.1'
4+
__version__ = '0.1.2'

0 commit comments

Comments
 (0)