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.
Files changed (139) hide show
  1. knowledge2-0.4.0.dist-info/METADATA +556 -0
  2. knowledge2-0.4.0.dist-info/RECORD +139 -0
  3. knowledge2-0.4.0.dist-info/WHEEL +5 -0
  4. knowledge2-0.4.0.dist-info/top_level.txt +1 -0
  5. sdk/__init__.py +70 -0
  6. sdk/_async_base.py +525 -0
  7. sdk/_async_paging.py +57 -0
  8. sdk/_base.py +541 -0
  9. sdk/_logging.py +41 -0
  10. sdk/_paging.py +73 -0
  11. sdk/_preview.py +70 -0
  12. sdk/_raw_response.py +25 -0
  13. sdk/_request_options.py +51 -0
  14. sdk/_transport.py +144 -0
  15. sdk/_validation.py +25 -0
  16. sdk/_validation_response.py +36 -0
  17. sdk/_version.py +3 -0
  18. sdk/async_client.py +320 -0
  19. sdk/async_resources/__init__.py +45 -0
  20. sdk/async_resources/_mixin_base.py +42 -0
  21. sdk/async_resources/a2a.py +230 -0
  22. sdk/async_resources/agents.py +489 -0
  23. sdk/async_resources/audit.py +145 -0
  24. sdk/async_resources/auth.py +133 -0
  25. sdk/async_resources/console.py +409 -0
  26. sdk/async_resources/corpora.py +276 -0
  27. sdk/async_resources/deployments.py +106 -0
  28. sdk/async_resources/documents.py +592 -0
  29. sdk/async_resources/feeds.py +248 -0
  30. sdk/async_resources/indexes.py +208 -0
  31. sdk/async_resources/jobs.py +165 -0
  32. sdk/async_resources/metadata.py +48 -0
  33. sdk/async_resources/models.py +102 -0
  34. sdk/async_resources/onboarding.py +538 -0
  35. sdk/async_resources/orgs.py +37 -0
  36. sdk/async_resources/pipelines.py +523 -0
  37. sdk/async_resources/projects.py +90 -0
  38. sdk/async_resources/search.py +262 -0
  39. sdk/async_resources/training.py +357 -0
  40. sdk/async_resources/usage.py +91 -0
  41. sdk/client.py +417 -0
  42. sdk/config.py +182 -0
  43. sdk/errors.py +178 -0
  44. sdk/examples/auth_factory.py +34 -0
  45. sdk/examples/batch_operations.py +57 -0
  46. sdk/examples/document_upload.py +56 -0
  47. sdk/examples/e2e_lifecycle.py +213 -0
  48. sdk/examples/error_handling.py +61 -0
  49. sdk/examples/pagination.py +64 -0
  50. sdk/examples/quickstart.py +36 -0
  51. sdk/examples/request_options.py +44 -0
  52. sdk/examples/search.py +64 -0
  53. sdk/integrations/__init__.py +57 -0
  54. sdk/integrations/_client.py +101 -0
  55. sdk/integrations/langchain/__init__.py +6 -0
  56. sdk/integrations/langchain/retriever.py +166 -0
  57. sdk/integrations/langchain/tools.py +108 -0
  58. sdk/integrations/llamaindex/__init__.py +11 -0
  59. sdk/integrations/llamaindex/filters.py +78 -0
  60. sdk/integrations/llamaindex/retriever.py +162 -0
  61. sdk/integrations/llamaindex/tools.py +109 -0
  62. sdk/integrations/llamaindex/vector_store.py +320 -0
  63. sdk/models/__init__.py +18 -0
  64. sdk/models/_base.py +24 -0
  65. sdk/models/_registry.py +457 -0
  66. sdk/models/a2a.py +92 -0
  67. sdk/models/agents.py +109 -0
  68. sdk/models/audit.py +28 -0
  69. sdk/models/auth.py +49 -0
  70. sdk/models/chunks.py +20 -0
  71. sdk/models/common.py +14 -0
  72. sdk/models/console.py +103 -0
  73. sdk/models/corpora.py +48 -0
  74. sdk/models/deployments.py +13 -0
  75. sdk/models/documents.py +126 -0
  76. sdk/models/embeddings.py +24 -0
  77. sdk/models/evaluation.py +17 -0
  78. sdk/models/feedback.py +9 -0
  79. sdk/models/feeds.py +57 -0
  80. sdk/models/indexes.py +36 -0
  81. sdk/models/jobs.py +52 -0
  82. sdk/models/models.py +26 -0
  83. sdk/models/onboarding.py +323 -0
  84. sdk/models/orgs.py +11 -0
  85. sdk/models/pipelines.py +147 -0
  86. sdk/models/projects.py +19 -0
  87. sdk/models/search.py +149 -0
  88. sdk/models/training.py +57 -0
  89. sdk/models/usage.py +39 -0
  90. sdk/namespaces.py +386 -0
  91. sdk/py.typed +0 -0
  92. sdk/resources/__init__.py +45 -0
  93. sdk/resources/_mixin_base.py +40 -0
  94. sdk/resources/a2a.py +230 -0
  95. sdk/resources/agents.py +487 -0
  96. sdk/resources/audit.py +144 -0
  97. sdk/resources/auth.py +138 -0
  98. sdk/resources/console.py +411 -0
  99. sdk/resources/corpora.py +269 -0
  100. sdk/resources/deployments.py +105 -0
  101. sdk/resources/documents.py +597 -0
  102. sdk/resources/feeds.py +246 -0
  103. sdk/resources/indexes.py +210 -0
  104. sdk/resources/jobs.py +164 -0
  105. sdk/resources/metadata.py +53 -0
  106. sdk/resources/models.py +99 -0
  107. sdk/resources/onboarding.py +542 -0
  108. sdk/resources/orgs.py +35 -0
  109. sdk/resources/pipeline_builder.py +257 -0
  110. sdk/resources/pipelines.py +520 -0
  111. sdk/resources/projects.py +87 -0
  112. sdk/resources/search.py +277 -0
  113. sdk/resources/training.py +358 -0
  114. sdk/resources/usage.py +92 -0
  115. sdk/types/__init__.py +366 -0
  116. sdk/types/a2a.py +88 -0
  117. sdk/types/agents.py +133 -0
  118. sdk/types/audit.py +26 -0
  119. sdk/types/auth.py +45 -0
  120. sdk/types/chunks.py +18 -0
  121. sdk/types/common.py +10 -0
  122. sdk/types/console.py +99 -0
  123. sdk/types/corpora.py +42 -0
  124. sdk/types/deployments.py +11 -0
  125. sdk/types/documents.py +104 -0
  126. sdk/types/embeddings.py +22 -0
  127. sdk/types/evaluation.py +15 -0
  128. sdk/types/feedback.py +7 -0
  129. sdk/types/feeds.py +61 -0
  130. sdk/types/indexes.py +30 -0
  131. sdk/types/jobs.py +50 -0
  132. sdk/types/models.py +22 -0
  133. sdk/types/onboarding.py +395 -0
  134. sdk/types/orgs.py +9 -0
  135. sdk/types/pipelines.py +177 -0
  136. sdk/types/projects.py +14 -0
  137. sdk/types/search.py +116 -0
  138. sdk/types/training.py +55 -0
  139. 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")