vikingdb-python-sdk 0.1.9__tar.gz → 0.1.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vikingdb_python_sdk-0.1.9/vikingdb_python_sdk.egg-info → vikingdb_python_sdk-0.1.11}/PKG-INFO +5 -4
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/README.md +3 -3
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/pyproject.toml +1 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/__init__.py +2 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/_client.py +3 -3
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/auth.py +16 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/__init__.py +126 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/client.py +174 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/collection.py +263 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/exceptions.py +212 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/models/__init__.py +0 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/models/base.py +53 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/models/chat.py +49 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/models/doc.py +131 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/models/point.py +128 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/models/rerank.py +31 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/models/search.py +58 -0
- vikingdb_python_sdk-0.1.11/vikingdb/knowledge/models/service_chat.py +78 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/__init__.py +2 -1
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/base.py +2 -2
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/client.py +43 -2
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/collection.py +2 -2
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/index.py +2 -2
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/version.py +1 -1
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11/vikingdb_python_sdk.egg-info}/PKG-INFO +5 -4
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb_python_sdk.egg-info/SOURCES.txt +12 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb_python_sdk.egg-info/requires.txt +1 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/LICENSE.txt +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/setup.cfg +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/exceptions.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/memory/__init__.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/memory/client.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/memory/collection.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/memory/exceptions.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/memory/types.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/request_options.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/embedding.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/exceptions.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/models/__init__.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/models/base.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/models/collection.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/models/embedding.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/models/index.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/models/rerank.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb/vector/rerank.py +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb_python_sdk.egg-info/dependency_links.txt +0 -0
- {vikingdb_python_sdk-0.1.9 → vikingdb_python_sdk-0.1.11}/vikingdb_python_sdk.egg-info/top_level.txt +0 -0
{vikingdb_python_sdk-0.1.9/vikingdb_python_sdk.egg-info → vikingdb_python_sdk-0.1.11}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vikingdb-python-sdk
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.11
|
|
4
4
|
Summary: vikingdb Python SDK
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Documentation, https://github.com/volcengine/volc-vikingdb-python-sdk/README.md
|
|
@@ -20,6 +20,7 @@ License-File: LICENSE.txt
|
|
|
20
20
|
Requires-Dist: httpx>=0.24.1
|
|
21
21
|
Requires-Dist: requests>=2.28.1
|
|
22
22
|
Requires-Dist: pydantic>=2.5.3
|
|
23
|
+
Requires-Dist: typing_extensions>=4.9.0
|
|
23
24
|
Requires-Dist: urllib3>=1.21.1
|
|
24
25
|
Requires-Dist: volcengine>=1.0.0
|
|
25
26
|
Requires-Dist: aiohttp>=3.10.0
|
|
@@ -53,10 +54,10 @@ uv add vikingdb-python-sdk
|
|
|
53
54
|
```python
|
|
54
55
|
import os
|
|
55
56
|
from vikingdb import IAM
|
|
56
|
-
from vikingdb.vector import SearchByRandomRequest,
|
|
57
|
+
from vikingdb.vector import SearchByRandomRequest, VikingDB
|
|
57
58
|
|
|
58
59
|
auth = IAM(ak=os.environ["VIKINGDB_AK"], sk=os.environ["VIKINGDB_SK"])
|
|
59
|
-
client =
|
|
60
|
+
client = VikingDB(
|
|
60
61
|
host=os.environ["VIKINGDB_HOST"],
|
|
61
62
|
region=os.environ["VIKINGDB_REGION"],
|
|
62
63
|
auth=auth,
|
|
@@ -181,7 +182,7 @@ python examples/memory/03_search_memory.py
|
|
|
181
182
|
### Architecture Overview
|
|
182
183
|
|
|
183
184
|
- `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).
|
|
184
|
-
- Domain-specific features live under dedicated namespaces such as `vikingdb.vector` and `vikingdb.memory`, where the high-level clients (`
|
|
185
|
+
- Domain-specific features live under dedicated namespaces such as `vikingdb.vector` and `vikingdb.memory`, where the high-level clients (`VikingDB`, `VikingMem`) compose the shared auth stack atop the shared client.
|
|
185
186
|
- Vector request/response models now surface directly from `vikingdb.vector` (backed internally by `vikingdb/vector/models`).
|
|
186
187
|
- Memory APIs return plain dictionaries without object encapsulation, providing a lightweight interface for conversational memory management (session, profile, event operations).
|
|
187
188
|
- 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.
|
|
@@ -26,10 +26,10 @@ uv add vikingdb-python-sdk
|
|
|
26
26
|
```python
|
|
27
27
|
import os
|
|
28
28
|
from vikingdb import IAM
|
|
29
|
-
from vikingdb.vector import SearchByRandomRequest,
|
|
29
|
+
from vikingdb.vector import SearchByRandomRequest, VikingDB
|
|
30
30
|
|
|
31
31
|
auth = IAM(ak=os.environ["VIKINGDB_AK"], sk=os.environ["VIKINGDB_SK"])
|
|
32
|
-
client =
|
|
32
|
+
client = VikingDB(
|
|
33
33
|
host=os.environ["VIKINGDB_HOST"],
|
|
34
34
|
region=os.environ["VIKINGDB_REGION"],
|
|
35
35
|
auth=auth,
|
|
@@ -154,7 +154,7 @@ python examples/memory/03_search_memory.py
|
|
|
154
154
|
### Architecture Overview
|
|
155
155
|
|
|
156
156
|
- `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).
|
|
157
|
-
- Domain-specific features live under dedicated namespaces such as `vikingdb.vector` and `vikingdb.memory`, where the high-level clients (`
|
|
157
|
+
- Domain-specific features live under dedicated namespaces such as `vikingdb.vector` and `vikingdb.memory`, where the high-level clients (`VikingDB`, `VikingMem`) compose the shared auth stack atop the shared client.
|
|
158
158
|
- Vector request/response models now surface directly from `vikingdb.vector` (backed internally by `vikingdb/vector/models`).
|
|
159
159
|
- Memory APIs return plain dictionaries without object encapsulation, providing a lightweight interface for conversational memory management (session, profile, event operations).
|
|
160
160
|
- 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.
|
|
@@ -12,6 +12,7 @@ from .vector import (
|
|
|
12
12
|
EmbeddingClient,
|
|
13
13
|
IndexClient,
|
|
14
14
|
RerankClient,
|
|
15
|
+
VikingDB,
|
|
15
16
|
VikingVector,
|
|
16
17
|
)
|
|
17
18
|
from .memory import (
|
|
@@ -27,6 +28,7 @@ __all__ = [
|
|
|
27
28
|
"RerankClient",
|
|
28
29
|
"IndexClient",
|
|
29
30
|
"RequestOptions",
|
|
31
|
+
"VikingDB",
|
|
30
32
|
"VikingVector",
|
|
31
33
|
"vector",
|
|
32
34
|
"memory",
|
|
@@ -18,7 +18,7 @@ from volcengine.base.Request import Request
|
|
|
18
18
|
from volcengine.base.Service import Service
|
|
19
19
|
import requests
|
|
20
20
|
|
|
21
|
-
from .auth import Auth, IAM, APIKey
|
|
21
|
+
from .auth import Auth, IAM, APIKey, HeaderAuth
|
|
22
22
|
from .exceptions import (
|
|
23
23
|
DEFAULT_UNKNOWN_ERROR_CODE,
|
|
24
24
|
VikingAPIException,
|
|
@@ -56,10 +56,10 @@ class Client(Service, ABC):
|
|
|
56
56
|
# 判断auth是不是IAM 还是 APIKey类型
|
|
57
57
|
if isinstance(auth, IAM):
|
|
58
58
|
super().__init__(self.service_info, self.api_info)
|
|
59
|
-
elif isinstance(auth, APIKey):
|
|
59
|
+
elif isinstance(auth, (APIKey, HeaderAuth)):
|
|
60
60
|
self.session = requests.session()
|
|
61
61
|
else:
|
|
62
|
-
raise ValueError("auth must be IAM or
|
|
62
|
+
raise ValueError("auth must be IAM, APIKey or HeaderAuth type")
|
|
63
63
|
|
|
64
64
|
if sts_token:
|
|
65
65
|
self.set_session_token(session_token=sts_token)
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
8
|
from abc import ABC, abstractmethod
|
|
9
|
+
from typing import Mapping
|
|
9
10
|
from volcengine.Credentials import Credentials
|
|
10
11
|
from volcengine.auth.SignerV4 import SignerV4
|
|
11
12
|
|
|
@@ -66,3 +67,18 @@ class APIKey(Auth):
|
|
|
66
67
|
|
|
67
68
|
def sign_request(self, request) -> None:
|
|
68
69
|
request.headers["Authorization"] = f"Bearer {self.api_key}"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class HeaderAuth(Auth):
|
|
73
|
+
"""Header-based authentication provider."""
|
|
74
|
+
|
|
75
|
+
def __init__(self, headers: Mapping[str, str]):
|
|
76
|
+
self.headers = headers
|
|
77
|
+
|
|
78
|
+
def initialize(self, *, service: str, region: str):
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
def sign_request(self, request) -> None:
|
|
82
|
+
if self.headers:
|
|
83
|
+
for key, value in self.headers.items():
|
|
84
|
+
request.headers[key] = value
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# coding:utf-8
|
|
2
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from .client import VikingKnowledge
|
|
6
|
+
from .collection import KnowledgeCollection
|
|
7
|
+
from .exceptions import (
|
|
8
|
+
VikingKnowledgeException,
|
|
9
|
+
UnauthorizedException,
|
|
10
|
+
NoPermissionException,
|
|
11
|
+
InvalidRequestException,
|
|
12
|
+
CollectionExistException,
|
|
13
|
+
CollectionNotExistException,
|
|
14
|
+
OperationNotAllowedException,
|
|
15
|
+
IndexExistException,
|
|
16
|
+
IndexNotExistException,
|
|
17
|
+
QueryOpFailedException,
|
|
18
|
+
DataNotFoundException,
|
|
19
|
+
DelOpFailedException,
|
|
20
|
+
UpsertOpFailedException,
|
|
21
|
+
TokenMismatchException,
|
|
22
|
+
InvalidQueryVecException,
|
|
23
|
+
InvalidPrimaryKeyException,
|
|
24
|
+
InvalidPartitionException,
|
|
25
|
+
InvalidScalarCondException,
|
|
26
|
+
InvalidProxyServiceException,
|
|
27
|
+
IndexRecallException,
|
|
28
|
+
IndexFetchDataException,
|
|
29
|
+
IndexNotReadyException,
|
|
30
|
+
APINotImplementedException,
|
|
31
|
+
CalcEmbeddingFailedException,
|
|
32
|
+
ListEmbeddingModelsException,
|
|
33
|
+
InternalServerException,
|
|
34
|
+
QuotaLimiterException,
|
|
35
|
+
RerankException,
|
|
36
|
+
DocNotExistException,
|
|
37
|
+
DocIsFullException,
|
|
38
|
+
PointNotExistException,
|
|
39
|
+
)
|
|
40
|
+
from .models.base import CollectionMeta
|
|
41
|
+
from .models.doc import DocInfo, DocInfo, ListDocsResponse, AddDocRequest, AddDocV2Request, ListDocsRequest, DedupOptions, MetaItem, AddDocResponse, AddDocResponseData
|
|
42
|
+
from .models.point import (
|
|
43
|
+
PointInfo,
|
|
44
|
+
ListPointsResponse,
|
|
45
|
+
AddPointRequest,
|
|
46
|
+
UpdatePointRequest,
|
|
47
|
+
ListPointsRequest,
|
|
48
|
+
DeletePointRequest,
|
|
49
|
+
)
|
|
50
|
+
from .models.search import (
|
|
51
|
+
SearchCollectionRequest,
|
|
52
|
+
SearchResponse,
|
|
53
|
+
SearchKnowledgeResponse,
|
|
54
|
+
SearchKnowledgeRequest,
|
|
55
|
+
)
|
|
56
|
+
from .models.rerank import RerankDataItem, RerankResponse
|
|
57
|
+
from .models.service_chat import ServiceChatRequest, ServiceChatResponse
|
|
58
|
+
from .models.chat import (
|
|
59
|
+
ChatMessage,
|
|
60
|
+
ChatCompletionRequest,
|
|
61
|
+
ChatCompletionResponse,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
__all__ = [
|
|
65
|
+
"VikingKnowledge",
|
|
66
|
+
"KnowledgeCollection",
|
|
67
|
+
"VikingKnowledgeException",
|
|
68
|
+
"UnauthorizedException",
|
|
69
|
+
"NoPermissionException",
|
|
70
|
+
"InvalidRequestException",
|
|
71
|
+
"CollectionExistException",
|
|
72
|
+
"CollectionNotExistException",
|
|
73
|
+
"OperationNotAllowedException",
|
|
74
|
+
"IndexExistException",
|
|
75
|
+
"IndexNotExistException",
|
|
76
|
+
"QueryOpFailedException",
|
|
77
|
+
"DataNotFoundException",
|
|
78
|
+
"DelOpFailedException",
|
|
79
|
+
"UpsertOpFailedException",
|
|
80
|
+
"TokenMismatchException",
|
|
81
|
+
"InvalidQueryVecException",
|
|
82
|
+
"InvalidPrimaryKeyException",
|
|
83
|
+
"InvalidPartitionException",
|
|
84
|
+
"InvalidScalarCondException",
|
|
85
|
+
"InvalidProxyServiceException",
|
|
86
|
+
"IndexRecallException",
|
|
87
|
+
"IndexFetchDataException",
|
|
88
|
+
"IndexNotReadyException",
|
|
89
|
+
"APINotImplementedException",
|
|
90
|
+
"CalcEmbeddingFailedException",
|
|
91
|
+
"ListEmbeddingModelsException",
|
|
92
|
+
"InternalServerException",
|
|
93
|
+
"QuotaLimiterException",
|
|
94
|
+
"RerankException",
|
|
95
|
+
"DocNotExistException",
|
|
96
|
+
"DocIsFullException",
|
|
97
|
+
"PointNotExistException",
|
|
98
|
+
"CollectionMeta",
|
|
99
|
+
"DocInfo",
|
|
100
|
+
"DocInfo",
|
|
101
|
+
"ListDocsResponse",
|
|
102
|
+
"AddDocRequest",
|
|
103
|
+
"AddDocV2Request",
|
|
104
|
+
"AddDocResponse",
|
|
105
|
+
"AddDocResponseData",
|
|
106
|
+
"ListDocsRequest",
|
|
107
|
+
"PointInfo",
|
|
108
|
+
"DedupOptions",
|
|
109
|
+
"MetaItem",
|
|
110
|
+
"ListPointsResponse",
|
|
111
|
+
"AddPointRequest",
|
|
112
|
+
"UpdatePointRequest",
|
|
113
|
+
"ListPointsRequest",
|
|
114
|
+
"DeletePointRequest",
|
|
115
|
+
"SearchCollectionRequest",
|
|
116
|
+
"SearchResponse",
|
|
117
|
+
"SearchKnowledgeResponse",
|
|
118
|
+
"SearchKnowledgeRequest",
|
|
119
|
+
"RerankDataItem",
|
|
120
|
+
"RerankResponse",
|
|
121
|
+
"ServiceChatRequest",
|
|
122
|
+
"ServiceChatResponse",
|
|
123
|
+
"ChatMessage",
|
|
124
|
+
"ChatCompletionRequest",
|
|
125
|
+
"ChatCompletionResponse",
|
|
126
|
+
]
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# coding:utf-8
|
|
2
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
from typing import Mapping, Optional, Union, Sequence, cast
|
|
9
|
+
|
|
10
|
+
from volcengine.ApiInfo import ApiInfo
|
|
11
|
+
|
|
12
|
+
from .. import APIKey
|
|
13
|
+
from .._client import Client, _REQUEST_ID_HEADER
|
|
14
|
+
from ..auth import Auth
|
|
15
|
+
from ..exceptions import VikingException, promote_exception
|
|
16
|
+
from .exceptions import EXCEPTION_MAP, VikingKnowledgeException
|
|
17
|
+
from ..version import __version__
|
|
18
|
+
from .models.base import CollectionMeta, Model
|
|
19
|
+
from .models.rerank import RerankDataItem, RerankResponse
|
|
20
|
+
from .models.chat import ChatCompletionRequest, ChatCompletionResponse
|
|
21
|
+
from .models.service_chat import ServiceChatRequest, ServiceChatResponse
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
_DEFAULT_USER_AGENT = f"vikingdb-python-sdk/{__version__}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _get_common_viking_request_header():
|
|
28
|
+
header = {
|
|
29
|
+
"Accept": "application/json",
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
"User-Agent": _DEFAULT_USER_AGENT,
|
|
32
|
+
}
|
|
33
|
+
return header
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class VikingKnowledge(Client):
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
*,
|
|
40
|
+
host: str = "api-knowledgebase.mlp.cn-beijing.volces.com",
|
|
41
|
+
region: str = "cn-beijing",
|
|
42
|
+
auth: Auth,
|
|
43
|
+
sts_token: str = "",
|
|
44
|
+
scheme: str = "http",
|
|
45
|
+
timeout: int = 30,
|
|
46
|
+
):
|
|
47
|
+
super().__init__(
|
|
48
|
+
host=host,
|
|
49
|
+
region=region,
|
|
50
|
+
service="air",
|
|
51
|
+
auth=auth,
|
|
52
|
+
sts_token=sts_token,
|
|
53
|
+
scheme=scheme,
|
|
54
|
+
timeout=timeout,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def _build_api_info(self):
|
|
58
|
+
header = _get_common_viking_request_header()
|
|
59
|
+
return {
|
|
60
|
+
"SearchCollection": ApiInfo("POST", "/api/knowledge/collection/search", {}, {}, header),
|
|
61
|
+
"SearchKnowledge": ApiInfo("POST", "/api/knowledge/collection/search_knowledge", {}, {}, header),
|
|
62
|
+
"ServiceChat": ApiInfo("POST", "/api/knowledge/service/chat", {}, {}, header),
|
|
63
|
+
# Doc
|
|
64
|
+
"AddDoc": ApiInfo("POST", "/api/knowledge/doc/add", {}, {}, header),
|
|
65
|
+
"AddDocV2": ApiInfo("POST", "/api/knowledge/doc/v2/add", {}, {}, header),
|
|
66
|
+
"DeleteDoc": ApiInfo("POST", "/api/knowledge/doc/delete", {}, {}, header),
|
|
67
|
+
"GetDocInfo": ApiInfo("POST", "/api/knowledge/doc/info", {}, {}, header),
|
|
68
|
+
"ListDocs": ApiInfo("POST", "/api/knowledge/doc/list", {}, {}, header),
|
|
69
|
+
"UpdateDocMeta": ApiInfo("POST", "/api/knowledge/doc/update_meta", {}, {}, header),
|
|
70
|
+
"UpdateDoc": ApiInfo("POST", "/api/knowledge/doc/update", {}, {}, header),
|
|
71
|
+
# Point
|
|
72
|
+
"GetPointInfo": ApiInfo("POST", "/api/knowledge/point/info", {}, {}, header),
|
|
73
|
+
"ListPoints": ApiInfo("POST", "/api/knowledge/point/list", {}, {}, header),
|
|
74
|
+
"AddPoint": ApiInfo("POST", "/api/knowledge/point/add", {}, {}, header),
|
|
75
|
+
"UpdatePoint": ApiInfo("POST", "/api/knowledge/point/update", {}, {}, header),
|
|
76
|
+
"DeletePoint": ApiInfo("POST", "/api/knowledge/point/delete", {}, {}, header),
|
|
77
|
+
# Service
|
|
78
|
+
"Ping": ApiInfo("GET", "/ping", {}, {}, header),
|
|
79
|
+
"Rerank": ApiInfo("POST", "/api/knowledge/service/rerank", {}, {}, header),
|
|
80
|
+
# Chat
|
|
81
|
+
"ChatCompletion": ApiInfo("POST", "/api/knowledge/chat/completions", {}, {}, header),
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
def json_exception(self, api, params, body, headers=None, timeout=None):
|
|
85
|
+
try:
|
|
86
|
+
res = self._json(api, params, body, headers=headers, timeout=timeout)
|
|
87
|
+
except VikingException as exc:
|
|
88
|
+
raise promote_exception(exc, exception_map=EXCEPTION_MAP, default_cls=VikingKnowledgeException) from None
|
|
89
|
+
if res is None:
|
|
90
|
+
raise VikingKnowledgeException(1000028, "missed", "empty response due to unknown error", status_code=None)
|
|
91
|
+
return res
|
|
92
|
+
|
|
93
|
+
async def async_json_exception(self, api, params, body, headers=None, timeout=None):
|
|
94
|
+
try:
|
|
95
|
+
res = await self.async_json(api, params, body, headers=headers, timeout=timeout)
|
|
96
|
+
except VikingException as exc:
|
|
97
|
+
raise promote_exception(exc, exception_map=EXCEPTION_MAP, default_cls=VikingKnowledgeException) from None
|
|
98
|
+
if res is None:
|
|
99
|
+
raise VikingKnowledgeException(1000028, "missed", "empty response due to unknown error", status_code=None)
|
|
100
|
+
return res
|
|
101
|
+
|
|
102
|
+
def collection(
|
|
103
|
+
self,
|
|
104
|
+
*,
|
|
105
|
+
resource_id: Optional[str] = None,
|
|
106
|
+
collection_name: Optional[str] = None,
|
|
107
|
+
project_name: Optional[str] = None,
|
|
108
|
+
):
|
|
109
|
+
from .collection import KnowledgeCollection
|
|
110
|
+
|
|
111
|
+
meta = CollectionMeta(
|
|
112
|
+
resource_id=resource_id,
|
|
113
|
+
collection_name=collection_name,
|
|
114
|
+
project_name=project_name,
|
|
115
|
+
)
|
|
116
|
+
return KnowledgeCollection(self, meta)
|
|
117
|
+
|
|
118
|
+
def rerank(
|
|
119
|
+
self,
|
|
120
|
+
datas: Sequence[Union[RerankDataItem,Mapping[str, object]]],
|
|
121
|
+
*,
|
|
122
|
+
rerank_model: str = "Doubao-pro-4k-rerank",
|
|
123
|
+
rerank_instruction: Optional[str] = None,
|
|
124
|
+
endpoint_id: Optional[str] = None,
|
|
125
|
+
headers: Optional[Mapping[str, str]] = None,
|
|
126
|
+
timeout: Optional[int] = None,
|
|
127
|
+
) -> RerankResponse:
|
|
128
|
+
items = [
|
|
129
|
+
(d.model_dump(by_alias=True, exclude_none=True) if isinstance(d, RerankDataItem) else dict(d))
|
|
130
|
+
for d in datas
|
|
131
|
+
]
|
|
132
|
+
if len(items) > 50:
|
|
133
|
+
raise VikingKnowledgeException(1000028, "missed", "datas list too large", status_code=None)
|
|
134
|
+
payload: dict = {"datas": items, "rerank_model": rerank_model}
|
|
135
|
+
if rerank_instruction is not None:
|
|
136
|
+
payload["rerank_instruction"] = rerank_instruction
|
|
137
|
+
if endpoint_id is not None:
|
|
138
|
+
payload["endpoint_id"] = endpoint_id
|
|
139
|
+
res = self.json_exception("Rerank", {}, json.dumps(payload), headers=headers, timeout=timeout)
|
|
140
|
+
response = RerankResponse.parse_with(res)
|
|
141
|
+
return response
|
|
142
|
+
|
|
143
|
+
def chat_completion(
|
|
144
|
+
self,
|
|
145
|
+
request: Union[ChatCompletionRequest, Mapping[str, object]],
|
|
146
|
+
*,
|
|
147
|
+
headers: Optional[Mapping[str, str]] = None,
|
|
148
|
+
timeout: Optional[int] = None,
|
|
149
|
+
) -> ChatCompletionResponse:
|
|
150
|
+
payload = (
|
|
151
|
+
request.model_dump(by_alias=True, exclude_none=True) # type: ignore[attr-defined]
|
|
152
|
+
if isinstance(request, ChatCompletionRequest)
|
|
153
|
+
else dict(request)
|
|
154
|
+
)
|
|
155
|
+
res = self.json_exception("ChatCompletion", {}, json.dumps(payload), headers=headers, timeout=timeout)
|
|
156
|
+
response = ChatCompletionResponse.parse_with(res)
|
|
157
|
+
return response
|
|
158
|
+
|
|
159
|
+
def service_chat(
|
|
160
|
+
self,
|
|
161
|
+
request: Union[ServiceChatRequest, Mapping[str, object]],
|
|
162
|
+
*,
|
|
163
|
+
headers: Optional[Mapping[str, str]] = None,
|
|
164
|
+
timeout: Optional[int] = None,
|
|
165
|
+
) -> ServiceChatResponse:
|
|
166
|
+
payload = (
|
|
167
|
+
request.model_dump(by_alias=True, exclude_none=True) # type: ignore[attr-defined]
|
|
168
|
+
if isinstance(request, ServiceChatRequest)
|
|
169
|
+
else dict(request)
|
|
170
|
+
)
|
|
171
|
+
req_headers = dict(headers or {})
|
|
172
|
+
res = self.json_exception("ServiceChat", {}, json.dumps(payload), headers=req_headers, timeout=timeout)
|
|
173
|
+
response = ServiceChatResponse.parse_with(res)
|
|
174
|
+
return response
|