knowledge2 0.4.0__py3-none-any.whl
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.
- knowledge2-0.4.0.dist-info/METADATA +556 -0
- knowledge2-0.4.0.dist-info/RECORD +139 -0
- knowledge2-0.4.0.dist-info/WHEEL +5 -0
- knowledge2-0.4.0.dist-info/top_level.txt +1 -0
- sdk/__init__.py +70 -0
- sdk/_async_base.py +525 -0
- sdk/_async_paging.py +57 -0
- sdk/_base.py +541 -0
- sdk/_logging.py +41 -0
- sdk/_paging.py +73 -0
- sdk/_preview.py +70 -0
- sdk/_raw_response.py +25 -0
- sdk/_request_options.py +51 -0
- sdk/_transport.py +144 -0
- sdk/_validation.py +25 -0
- sdk/_validation_response.py +36 -0
- sdk/_version.py +3 -0
- sdk/async_client.py +320 -0
- sdk/async_resources/__init__.py +45 -0
- sdk/async_resources/_mixin_base.py +42 -0
- sdk/async_resources/a2a.py +230 -0
- sdk/async_resources/agents.py +489 -0
- sdk/async_resources/audit.py +145 -0
- sdk/async_resources/auth.py +133 -0
- sdk/async_resources/console.py +409 -0
- sdk/async_resources/corpora.py +276 -0
- sdk/async_resources/deployments.py +106 -0
- sdk/async_resources/documents.py +592 -0
- sdk/async_resources/feeds.py +248 -0
- sdk/async_resources/indexes.py +208 -0
- sdk/async_resources/jobs.py +165 -0
- sdk/async_resources/metadata.py +48 -0
- sdk/async_resources/models.py +102 -0
- sdk/async_resources/onboarding.py +538 -0
- sdk/async_resources/orgs.py +37 -0
- sdk/async_resources/pipelines.py +523 -0
- sdk/async_resources/projects.py +90 -0
- sdk/async_resources/search.py +262 -0
- sdk/async_resources/training.py +357 -0
- sdk/async_resources/usage.py +91 -0
- sdk/client.py +417 -0
- sdk/config.py +182 -0
- sdk/errors.py +178 -0
- sdk/examples/auth_factory.py +34 -0
- sdk/examples/batch_operations.py +57 -0
- sdk/examples/document_upload.py +56 -0
- sdk/examples/e2e_lifecycle.py +213 -0
- sdk/examples/error_handling.py +61 -0
- sdk/examples/pagination.py +64 -0
- sdk/examples/quickstart.py +36 -0
- sdk/examples/request_options.py +44 -0
- sdk/examples/search.py +64 -0
- sdk/integrations/__init__.py +57 -0
- sdk/integrations/_client.py +101 -0
- sdk/integrations/langchain/__init__.py +6 -0
- sdk/integrations/langchain/retriever.py +166 -0
- sdk/integrations/langchain/tools.py +108 -0
- sdk/integrations/llamaindex/__init__.py +11 -0
- sdk/integrations/llamaindex/filters.py +78 -0
- sdk/integrations/llamaindex/retriever.py +162 -0
- sdk/integrations/llamaindex/tools.py +109 -0
- sdk/integrations/llamaindex/vector_store.py +320 -0
- sdk/models/__init__.py +18 -0
- sdk/models/_base.py +24 -0
- sdk/models/_registry.py +457 -0
- sdk/models/a2a.py +92 -0
- sdk/models/agents.py +109 -0
- sdk/models/audit.py +28 -0
- sdk/models/auth.py +49 -0
- sdk/models/chunks.py +20 -0
- sdk/models/common.py +14 -0
- sdk/models/console.py +103 -0
- sdk/models/corpora.py +48 -0
- sdk/models/deployments.py +13 -0
- sdk/models/documents.py +126 -0
- sdk/models/embeddings.py +24 -0
- sdk/models/evaluation.py +17 -0
- sdk/models/feedback.py +9 -0
- sdk/models/feeds.py +57 -0
- sdk/models/indexes.py +36 -0
- sdk/models/jobs.py +52 -0
- sdk/models/models.py +26 -0
- sdk/models/onboarding.py +323 -0
- sdk/models/orgs.py +11 -0
- sdk/models/pipelines.py +147 -0
- sdk/models/projects.py +19 -0
- sdk/models/search.py +149 -0
- sdk/models/training.py +57 -0
- sdk/models/usage.py +39 -0
- sdk/namespaces.py +386 -0
- sdk/py.typed +0 -0
- sdk/resources/__init__.py +45 -0
- sdk/resources/_mixin_base.py +40 -0
- sdk/resources/a2a.py +230 -0
- sdk/resources/agents.py +487 -0
- sdk/resources/audit.py +144 -0
- sdk/resources/auth.py +138 -0
- sdk/resources/console.py +411 -0
- sdk/resources/corpora.py +269 -0
- sdk/resources/deployments.py +105 -0
- sdk/resources/documents.py +597 -0
- sdk/resources/feeds.py +246 -0
- sdk/resources/indexes.py +210 -0
- sdk/resources/jobs.py +164 -0
- sdk/resources/metadata.py +53 -0
- sdk/resources/models.py +99 -0
- sdk/resources/onboarding.py +542 -0
- sdk/resources/orgs.py +35 -0
- sdk/resources/pipeline_builder.py +257 -0
- sdk/resources/pipelines.py +520 -0
- sdk/resources/projects.py +87 -0
- sdk/resources/search.py +277 -0
- sdk/resources/training.py +358 -0
- sdk/resources/usage.py +92 -0
- sdk/types/__init__.py +366 -0
- sdk/types/a2a.py +88 -0
- sdk/types/agents.py +133 -0
- sdk/types/audit.py +26 -0
- sdk/types/auth.py +45 -0
- sdk/types/chunks.py +18 -0
- sdk/types/common.py +10 -0
- sdk/types/console.py +99 -0
- sdk/types/corpora.py +42 -0
- sdk/types/deployments.py +11 -0
- sdk/types/documents.py +104 -0
- sdk/types/embeddings.py +22 -0
- sdk/types/evaluation.py +15 -0
- sdk/types/feedback.py +7 -0
- sdk/types/feeds.py +61 -0
- sdk/types/indexes.py +30 -0
- sdk/types/jobs.py +50 -0
- sdk/types/models.py +22 -0
- sdk/types/onboarding.py +395 -0
- sdk/types/orgs.py +9 -0
- sdk/types/pipelines.py +177 -0
- sdk/types/projects.py +14 -0
- sdk/types/search.py +116 -0
- sdk/types/training.py +55 -0
- sdk/types/usage.py +37 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .a2a import AsyncA2AMixin
|
|
4
|
+
from .agents import AsyncAgentsMixin
|
|
5
|
+
from .audit import AsyncAuditMixin
|
|
6
|
+
from .auth import AsyncAuthMixin
|
|
7
|
+
from .console import AsyncConsoleMixin
|
|
8
|
+
from .corpora import AsyncCorporaMixin
|
|
9
|
+
from .deployments import AsyncDeploymentsMixin
|
|
10
|
+
from .documents import AsyncDocumentsMixin
|
|
11
|
+
from .feeds import AsyncFeedsMixin
|
|
12
|
+
from .indexes import AsyncIndexesMixin
|
|
13
|
+
from .jobs import AsyncJobsMixin
|
|
14
|
+
from .metadata import AsyncMetadataMixin
|
|
15
|
+
from .models import AsyncModelsMixin
|
|
16
|
+
from .onboarding import AsyncOnboardingMixin
|
|
17
|
+
from .orgs import AsyncOrgsMixin
|
|
18
|
+
from .pipelines import AsyncPipelinesMixin
|
|
19
|
+
from .projects import AsyncProjectsMixin
|
|
20
|
+
from .search import AsyncSearchMixin
|
|
21
|
+
from .training import AsyncTrainingMixin
|
|
22
|
+
from .usage import AsyncUsageMixin
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"AsyncA2AMixin",
|
|
26
|
+
"AsyncAgentsMixin",
|
|
27
|
+
"AsyncAuditMixin",
|
|
28
|
+
"AsyncAuthMixin",
|
|
29
|
+
"AsyncConsoleMixin",
|
|
30
|
+
"AsyncCorporaMixin",
|
|
31
|
+
"AsyncDeploymentsMixin",
|
|
32
|
+
"AsyncDocumentsMixin",
|
|
33
|
+
"AsyncFeedsMixin",
|
|
34
|
+
"AsyncIndexesMixin",
|
|
35
|
+
"AsyncJobsMixin",
|
|
36
|
+
"AsyncMetadataMixin",
|
|
37
|
+
"AsyncModelsMixin",
|
|
38
|
+
"AsyncOnboardingMixin",
|
|
39
|
+
"AsyncOrgsMixin",
|
|
40
|
+
"AsyncPipelinesMixin",
|
|
41
|
+
"AsyncProjectsMixin",
|
|
42
|
+
"AsyncSearchMixin",
|
|
43
|
+
"AsyncTrainingMixin",
|
|
44
|
+
"AsyncUsageMixin",
|
|
45
|
+
]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Awaitable
|
|
4
|
+
from typing import Any, Protocol, runtime_checkable
|
|
5
|
+
|
|
6
|
+
from sdk._async_paging import AsyncPager
|
|
7
|
+
from sdk._paging import Page
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@runtime_checkable
|
|
11
|
+
class AsyncRequesterMixin(Protocol):
|
|
12
|
+
async def _request(self, method: str, path: str, **kwargs: Any) -> Any: ...
|
|
13
|
+
|
|
14
|
+
def _maybe_validate(self, data: Any, model_name: str) -> Any: ...
|
|
15
|
+
|
|
16
|
+
@staticmethod
|
|
17
|
+
def _idempotency_headers(idempotency_key: str | None) -> dict[str, str]: ...
|
|
18
|
+
|
|
19
|
+
async def _wait_for_job(
|
|
20
|
+
self, job_id: str, *, poll_s: int = 5, timeout_s: float | None = None
|
|
21
|
+
) -> dict[str, Any]: ...
|
|
22
|
+
|
|
23
|
+
async def _list_page(
|
|
24
|
+
self,
|
|
25
|
+
method: str,
|
|
26
|
+
path: str,
|
|
27
|
+
*,
|
|
28
|
+
items_key: str,
|
|
29
|
+
params: dict[str, Any] | None = None,
|
|
30
|
+
limit: int = 100,
|
|
31
|
+
offset: int = 0,
|
|
32
|
+
) -> Page[dict[str, Any]]: ...
|
|
33
|
+
|
|
34
|
+
def _paginate(
|
|
35
|
+
self,
|
|
36
|
+
method: str,
|
|
37
|
+
path: str,
|
|
38
|
+
*,
|
|
39
|
+
items_key: str,
|
|
40
|
+
params: dict[str, Any] | None = None,
|
|
41
|
+
limit: int = 100,
|
|
42
|
+
) -> AsyncPager[dict[str, Any]]: ...
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import uuid
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from sdk._preview import preview_resource
|
|
7
|
+
from sdk._request_options import RequestOptions
|
|
8
|
+
from sdk._validation import require_str
|
|
9
|
+
from sdk.async_resources._mixin_base import AsyncRequesterMixin
|
|
10
|
+
from sdk.types import (
|
|
11
|
+
A2AAgentCardResponse,
|
|
12
|
+
A2AJsonRpcResponse,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@preview_resource
|
|
17
|
+
class AsyncA2AMixin(AsyncRequesterMixin):
|
|
18
|
+
"""Async SDK mixin for the K2 A2A (Agent-to-Agent) protocol adapter."""
|
|
19
|
+
|
|
20
|
+
async def a2a_get_agent_card(
|
|
21
|
+
self,
|
|
22
|
+
corpus_id: str,
|
|
23
|
+
request_options: RequestOptions | None = None,
|
|
24
|
+
) -> A2AAgentCardResponse:
|
|
25
|
+
"""Fetch the A2A Agent Card for a corpus."""
|
|
26
|
+
corpus_id = require_str(corpus_id, "corpus_id")
|
|
27
|
+
data = await self._request(
|
|
28
|
+
"GET",
|
|
29
|
+
f"/a2a/v1/agents/{corpus_id}/.well-known/agent.json",
|
|
30
|
+
request_options=request_options,
|
|
31
|
+
)
|
|
32
|
+
return self._maybe_validate(data, "A2AAgentCardResponse")
|
|
33
|
+
|
|
34
|
+
async def a2a_send_message(
|
|
35
|
+
self,
|
|
36
|
+
corpus_id: str,
|
|
37
|
+
*,
|
|
38
|
+
operation: str,
|
|
39
|
+
text: str | None = None,
|
|
40
|
+
data: dict[str, Any] | None = None,
|
|
41
|
+
message_id: str | None = None,
|
|
42
|
+
context_id: str | None = None,
|
|
43
|
+
metadata: dict[str, Any] | None = None,
|
|
44
|
+
configuration: dict[str, Any] | None = None,
|
|
45
|
+
request_options: RequestOptions | None = None,
|
|
46
|
+
) -> A2AJsonRpcResponse:
|
|
47
|
+
"""Send an A2A message/send request to a corpus agent.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
corpus_id: Target corpus ID.
|
|
51
|
+
operation: K2 operation (retrieve, answer, ingest.urls, ingest.text_batch).
|
|
52
|
+
text: Query text (required for retrieve/answer).
|
|
53
|
+
data: Structured data (search config, URLs, documents, etc.).
|
|
54
|
+
message_id: Optional message ID (auto-generated if omitted).
|
|
55
|
+
context_id: Optional context/session ID.
|
|
56
|
+
metadata: Additional metadata merged with operation.
|
|
57
|
+
configuration: Optional A2A configuration passed through to the agent.
|
|
58
|
+
"""
|
|
59
|
+
corpus_id = require_str(corpus_id, "corpus_id")
|
|
60
|
+
parts: list[dict[str, Any]] = []
|
|
61
|
+
if text is not None:
|
|
62
|
+
parts.append({"kind": "text", "text": text})
|
|
63
|
+
if data is not None:
|
|
64
|
+
parts.append({"kind": "data", "data": data})
|
|
65
|
+
|
|
66
|
+
msg_meta: dict[str, Any] = dict(metadata or {})
|
|
67
|
+
# Keep operation authoritative even if metadata contains an `operation` key.
|
|
68
|
+
msg_meta["operation"] = operation
|
|
69
|
+
|
|
70
|
+
message: dict[str, Any] = {
|
|
71
|
+
"messageId": message_id or str(uuid.uuid4()),
|
|
72
|
+
"role": "user",
|
|
73
|
+
"parts": parts,
|
|
74
|
+
"metadata": msg_meta,
|
|
75
|
+
}
|
|
76
|
+
if context_id is not None:
|
|
77
|
+
message["contextId"] = context_id
|
|
78
|
+
|
|
79
|
+
params: dict[str, Any] = {"message": message}
|
|
80
|
+
if configuration is not None:
|
|
81
|
+
params["configuration"] = configuration
|
|
82
|
+
|
|
83
|
+
body = {
|
|
84
|
+
"jsonrpc": "2.0",
|
|
85
|
+
"id": str(uuid.uuid4()),
|
|
86
|
+
"method": "message/send",
|
|
87
|
+
"params": params,
|
|
88
|
+
}
|
|
89
|
+
resp = await self._request(
|
|
90
|
+
"POST", f"/a2a/v1/agents/{corpus_id}", json=body, request_options=request_options
|
|
91
|
+
)
|
|
92
|
+
return self._maybe_validate(resp, "A2AJsonRpcResponse")
|
|
93
|
+
|
|
94
|
+
async def a2a_retrieve(
|
|
95
|
+
self,
|
|
96
|
+
corpus_id: str,
|
|
97
|
+
query: str,
|
|
98
|
+
*,
|
|
99
|
+
top_k: int = 10,
|
|
100
|
+
filters: dict[str, Any] | None = None,
|
|
101
|
+
hybrid: dict[str, Any] | None = None,
|
|
102
|
+
rerank: dict[str, Any] | None = None,
|
|
103
|
+
return_config: dict[str, Any] | None = None,
|
|
104
|
+
request_options: RequestOptions | None = None,
|
|
105
|
+
) -> A2AJsonRpcResponse:
|
|
106
|
+
"""Convenience wrapper for the A2A 'retrieve' operation."""
|
|
107
|
+
corpus_id = require_str(corpus_id, "corpus_id")
|
|
108
|
+
data: dict[str, Any] = {"top_k": top_k}
|
|
109
|
+
if filters is not None:
|
|
110
|
+
data["filters"] = filters
|
|
111
|
+
if hybrid is not None:
|
|
112
|
+
data["hybrid"] = hybrid
|
|
113
|
+
if rerank is not None:
|
|
114
|
+
data["rerank"] = rerank
|
|
115
|
+
if return_config is not None:
|
|
116
|
+
data["return"] = return_config
|
|
117
|
+
return await self.a2a_send_message(
|
|
118
|
+
corpus_id, operation="retrieve", text=query, data=data, request_options=request_options
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
async def a2a_answer(
|
|
122
|
+
self,
|
|
123
|
+
corpus_id: str,
|
|
124
|
+
query: str,
|
|
125
|
+
*,
|
|
126
|
+
top_k: int = 10,
|
|
127
|
+
filters: dict[str, Any] | None = None,
|
|
128
|
+
hybrid: dict[str, Any] | None = None,
|
|
129
|
+
rerank: dict[str, Any] | None = None,
|
|
130
|
+
generation: dict[str, Any] | None = None,
|
|
131
|
+
request_options: RequestOptions | None = None,
|
|
132
|
+
) -> A2AJsonRpcResponse:
|
|
133
|
+
"""Convenience wrapper for the A2A 'answer' operation."""
|
|
134
|
+
corpus_id = require_str(corpus_id, "corpus_id")
|
|
135
|
+
data: dict[str, Any] = {"top_k": top_k}
|
|
136
|
+
if filters is not None:
|
|
137
|
+
data["filters"] = filters
|
|
138
|
+
if hybrid is not None:
|
|
139
|
+
data["hybrid"] = hybrid
|
|
140
|
+
if rerank is not None:
|
|
141
|
+
data["rerank"] = rerank
|
|
142
|
+
if generation is not None:
|
|
143
|
+
data["generation"] = generation
|
|
144
|
+
return await self.a2a_send_message(
|
|
145
|
+
corpus_id, operation="answer", text=query, data=data, request_options=request_options
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
async def a2a_ingest_urls(
|
|
149
|
+
self,
|
|
150
|
+
corpus_id: str,
|
|
151
|
+
urls: list[str | dict[str, Any]],
|
|
152
|
+
*,
|
|
153
|
+
auto_index: bool | None = None,
|
|
154
|
+
message_id: str | None = None,
|
|
155
|
+
request_options: RequestOptions | None = None,
|
|
156
|
+
) -> A2AJsonRpcResponse:
|
|
157
|
+
"""Convenience wrapper for the A2A 'ingest.urls' operation."""
|
|
158
|
+
corpus_id = require_str(corpus_id, "corpus_id")
|
|
159
|
+
data: dict[str, Any] = {"urls": urls}
|
|
160
|
+
if auto_index is not None:
|
|
161
|
+
data["auto_index"] = auto_index
|
|
162
|
+
return await self.a2a_send_message(
|
|
163
|
+
corpus_id,
|
|
164
|
+
operation="ingest.urls",
|
|
165
|
+
data=data,
|
|
166
|
+
message_id=message_id,
|
|
167
|
+
request_options=request_options,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
async def a2a_ingest_text_batch(
|
|
171
|
+
self,
|
|
172
|
+
corpus_id: str,
|
|
173
|
+
documents: list[dict[str, Any]],
|
|
174
|
+
*,
|
|
175
|
+
auto_index: bool | None = None,
|
|
176
|
+
message_id: str | None = None,
|
|
177
|
+
request_options: RequestOptions | None = None,
|
|
178
|
+
) -> A2AJsonRpcResponse:
|
|
179
|
+
"""Convenience wrapper for the A2A 'ingest.text_batch' operation."""
|
|
180
|
+
corpus_id = require_str(corpus_id, "corpus_id")
|
|
181
|
+
data: dict[str, Any] = {"documents": documents}
|
|
182
|
+
if auto_index is not None:
|
|
183
|
+
data["auto_index"] = auto_index
|
|
184
|
+
return await self.a2a_send_message(
|
|
185
|
+
corpus_id,
|
|
186
|
+
operation="ingest.text_batch",
|
|
187
|
+
data=data,
|
|
188
|
+
message_id=message_id,
|
|
189
|
+
request_options=request_options,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
async def a2a_get_task(
|
|
193
|
+
self,
|
|
194
|
+
corpus_id: str,
|
|
195
|
+
task_id: str,
|
|
196
|
+
request_options: RequestOptions | None = None,
|
|
197
|
+
) -> A2AJsonRpcResponse:
|
|
198
|
+
"""Get the status of an async A2A task (maps to tasks/get)."""
|
|
199
|
+
corpus_id = require_str(corpus_id, "corpus_id")
|
|
200
|
+
task_id = require_str(task_id, "task_id")
|
|
201
|
+
body = {
|
|
202
|
+
"jsonrpc": "2.0",
|
|
203
|
+
"id": str(uuid.uuid4()),
|
|
204
|
+
"method": "tasks/get",
|
|
205
|
+
"params": {"id": task_id},
|
|
206
|
+
}
|
|
207
|
+
resp = await self._request(
|
|
208
|
+
"POST", f"/a2a/v1/agents/{corpus_id}", json=body, request_options=request_options
|
|
209
|
+
)
|
|
210
|
+
return self._maybe_validate(resp, "A2AJsonRpcResponse")
|
|
211
|
+
|
|
212
|
+
async def a2a_cancel_task(
|
|
213
|
+
self,
|
|
214
|
+
corpus_id: str,
|
|
215
|
+
task_id: str,
|
|
216
|
+
request_options: RequestOptions | None = None,
|
|
217
|
+
) -> A2AJsonRpcResponse:
|
|
218
|
+
"""Cancel an async A2A task (maps to tasks/cancel)."""
|
|
219
|
+
corpus_id = require_str(corpus_id, "corpus_id")
|
|
220
|
+
task_id = require_str(task_id, "task_id")
|
|
221
|
+
body = {
|
|
222
|
+
"jsonrpc": "2.0",
|
|
223
|
+
"id": str(uuid.uuid4()),
|
|
224
|
+
"method": "tasks/cancel",
|
|
225
|
+
"params": {"id": task_id},
|
|
226
|
+
}
|
|
227
|
+
resp = await self._request(
|
|
228
|
+
"POST", f"/a2a/v1/agents/{corpus_id}", json=body, request_options=request_options
|
|
229
|
+
)
|
|
230
|
+
return self._maybe_validate(resp, "A2AJsonRpcResponse")
|