Skip to content

Commit 1458ef9

Browse files
committed
Merge 'feat/fix_readme' into 'master'
fix readme See merge request: !13
2 parents 397b530 + 63c08b8 commit 1458ef9

File tree

1 file changed

+97
-10
lines changed

1 file changed

+97
-10
lines changed

README.md

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ This package provides an idiomatic Python interface to the VikingDB v2 data-plan
44

55
### Key Features
66
- Simple client configuration with AK/SK signing (Volcano Engine V4) or API-key authentication.
7-
- Request envelope handling with typed request/response models covering collection, index, and embedding workflows.
7+
- **Vector Database**: Request envelope handling with typed request/response models covering collection, index, and embedding workflows.
8+
- **Memory Management**: Conversational memory APIs for managing user profiles, events, and session messages with semantic search capabilities.
89
- Pluggable retry strategy (exponential backoff with jitter) and per-request overrides (`RequestOptions`).
9-
- Executable example guides (`pytest` integration tests) that demonstrate connectivity, CRUD, search, analytics, and embedding scenarios against a real VikingDB environment.
10+
- Executable example guides (`pytest` integration tests and standalone scripts) that demonstrate connectivity, CRUD, search, analytics, embedding, and memory management scenarios against a real VikingDB environment.
1011

1112
### Installation
1213

@@ -20,6 +21,8 @@ pip install -e .
2021
2122
### Quickstart
2223

24+
#### Vector Database
25+
2326
```python
2427
from vikingdb import IAM
2528
from vikingdb.vector import UpsertDataRequest, VikingVector
@@ -51,7 +54,51 @@ search_response = index.search_by_random({"limit": 1})
5154
print("search hits:", len(search_response.result.data) if search_response.result else 0)
5255
```
5356

54-
### Example Guides (Pytest)
57+
#### Memory Management
58+
59+
```python
60+
from vikingdb import IAM
61+
from vikingdb.memory import VikingMem
62+
63+
auth = IAM(ak="<AK>", sk="<SK>")
64+
client = VikingMem(
65+
host="api-knowledgebase.mlp.cn-beijing.volces.com",
66+
region="cn-beijing",
67+
auth=auth,
68+
scheme="http",
69+
)
70+
71+
# Get collection
72+
collection = client.get_collection(
73+
collection_name="demo_collection",
74+
project_name="default"
75+
)
76+
77+
# Add session messages
78+
collection.add_session(
79+
session_id="session_001",
80+
messages=[
81+
{"role": "user", "content": "Hello, how is the weather today?"},
82+
{"role": "assistant", "content": "Today is sunny, perfect for going out."}
83+
],
84+
metadata={
85+
"default_user_id": "user_001",
86+
"default_assistant_id": "assistant_001",
87+
}
88+
)
89+
90+
# Search memories
91+
result = collection.search_memory(
92+
query="weather today",
93+
filter={"user_id": "user_001", "memory_type": ["event_v1"]},
94+
limit=10
95+
)
96+
print("search results:", result)
97+
```
98+
99+
### Example Guides
100+
101+
#### Vector Examples (Pytest)
55102

56103
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.
57104

@@ -86,21 +133,46 @@ The integration guides under `examples/vector` mirror the Go SDK walkthroughs (`
86133

87134
Each scenario writes temporary documents using unique session tags and cleans them up afterwards.
88135

136+
#### Memory Examples
137+
138+
The memory examples under `examples/memory` demonstrate the core workflows for managing conversational memories:
139+
140+
1. **01_init_client_and_collection.py**: Initialize the VikingMem client and get collection instances using either collection name + project name or resource ID.
141+
142+
2. **02_add_session.py**: Add session messages (user-assistant conversations) to the memory collection with metadata such as user ID, assistant ID, and timestamps.
143+
144+
3. **03_search_memory.py**: Search memories with various filters including:
145+
- User profile search
146+
- Event search by semantic query
147+
- Time range filtering for recent events
148+
149+
To run the memory examples:
150+
151+
```bash
152+
# Set environment variables
153+
export VIKINGDB_AK=your-access-key
154+
export VIKINGDB_SK=your-secret-key
155+
156+
# Run individual examples
157+
python examples/memory/01_init_client_and_collection.py
158+
python examples/memory/02_add_session.py
159+
python examples/memory/03_search_memory.py
160+
```
161+
89162
### Architecture Overview
90163

91164
- `vikingdb._client`, `vikingdb.auth`, `vikingdb.request_options`, and `vikingdb.vector.exceptions` form the shared runtime used by all present and future SDK domains (vector, memory, knowledge).
92-
- Domain-specific features live under dedicated namespaces such as `vikingdb.vector`, where the high-level `VikingVector` client composes the shared auth stack atop the shared client.
165+
- Domain-specific features live under dedicated namespaces such as `vikingdb.vector` and `vikingdb.memory`, where the high-level clients (`VikingVector`, `VikingMem`) compose the shared auth stack atop the shared client.
93166
- Vector request/response models now surface directly from `vikingdb.vector` (backed internally by `vikingdb/vector/models`).
94-
- Imports from the root package now focus on cross-cutting utilities (auth, config, request options), while application code should pull vector functionality from `vikingdb.vector` explicitly.
167+
- Memory APIs return plain dictionaries without object encapsulation, providing a lightweight interface for conversational memory management (session, profile, event operations).
168+
- Imports from the root package now focus on cross-cutting utilities (auth, config, request options), while application code should pull domain-specific functionality from `vikingdb.vector` or `vikingdb.memory` explicitly.
95169

96170
### Project Structure
97171

98172
```
99173
vikingdb/
100174
├── _client.py # Shared base client built on volcengine Service
101-
├── config.py # Shared client / retry configuration
102175
├── auth.py # Shared auth providers (IAM, API key)
103-
├── exceptions.py # Error hierarchy reused across domains
104176
├── request_options.py # Per-request overrides shared by all services
105177
├── version.py # Package metadata
106178
├── vector/ # Vector-specific clients and models
@@ -110,10 +182,25 @@ vikingdb/
110182
│ ├── embedding.py # Embedding operations
111183
│ ├── index.py # Index/search operations
112184
│ ├── client.py # Vector service wrapper and high-level client
185+
│ ├── exceptions.py # Vector-specific exceptions
113186
│ └── models/ # Vector request/response models (pydantic)
114-
115-
examples/vector/ # Integration guides (pytest)
116-
docs/python_sdk_design.md# Design notes and parity checklist
187+
├── memory/ # Memory-specific clients and models
188+
│ ├── __init__.py # High-level memory client and namespace exports
189+
│ ├── client.py # VikingMem service client
190+
│ ├── collection.py # Memory collection operations
191+
│ ├── types.py # Type definitions for memory operations
192+
│ └── exceptions.py # Memory-specific exceptions
193+
194+
examples/
195+
├── vector/ # Vector integration guides (pytest)
196+
│ ├── E1_connectivity_test.py
197+
│ ├── E2_collection_lifecycle_test.py
198+
│ ├── E3_*_test.py # Search and indexing examples
199+
│ └── ...
200+
└── memory/ # Memory usage examples
201+
├── 01_init_client_and_collection.py
202+
├── 02_add_session.py
203+
└── 03_search_memory.py
117204
```
118205

119206
### Contributing

0 commit comments

Comments
 (0)