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,276 @@
1
+ """Async corpus resource mixin for the Knowledge2 SDK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from sdk._async_paging import AsyncPager
8
+ from sdk._paging import Page
9
+ from sdk._request_options import RequestOptions
10
+ from sdk._validation import require_str
11
+ from sdk.async_resources._mixin_base import AsyncRequesterMixin
12
+ from sdk.errors import ConfirmationRequiredError
13
+ from sdk.types import (
14
+ CorpusDeleteResponse,
15
+ CorpusResponse,
16
+ CorpusStatusResponse,
17
+ )
18
+
19
+
20
+ class AsyncCorporaMixin(AsyncRequesterMixin):
21
+ async def create_corpus(
22
+ self,
23
+ project_id: str,
24
+ name: str,
25
+ description: str | None = None,
26
+ request_options: RequestOptions | None = None,
27
+ ) -> CorpusResponse:
28
+ """Create a new corpus within a project.
29
+
30
+ Args:
31
+ project_id: The project that will own the corpus.
32
+ name: Human-readable name for the corpus.
33
+ description: Optional description of the corpus contents.
34
+
35
+ Returns:
36
+ The newly created corpus record.
37
+
38
+ Raises:
39
+ Knowledge2Error: If the API request fails.
40
+ """
41
+ project_id = require_str(project_id, "project_id")
42
+ payload: dict[str, Any] = {"project_id": project_id, "name": name}
43
+ if description is not None:
44
+ payload["description"] = description
45
+ data = await self._request(
46
+ "POST", "/v1/corpora", json=payload, request_options=request_options
47
+ )
48
+ return self._maybe_validate(data, "CorpusResponse")
49
+
50
+ async def list_corpora(
51
+ self,
52
+ limit: int = 100,
53
+ offset: int = 0,
54
+ request_options: RequestOptions | None = None,
55
+ ) -> Page[dict[str, Any]]:
56
+ """List corpora accessible to the current credentials.
57
+
58
+ Args:
59
+ limit: Maximum number of corpora to return per page.
60
+ offset: Number of corpora to skip for pagination.
61
+
62
+ Returns:
63
+ A Page containing corpus records with pagination metadata.
64
+
65
+ Raises:
66
+ Knowledge2Error: If the API request fails.
67
+ """
68
+ return await self._list_page(
69
+ "GET", "/v1/corpora", items_key="corpora", limit=limit, offset=offset
70
+ )
71
+
72
+ def iter_corpora(
73
+ self,
74
+ *,
75
+ limit: int = 100,
76
+ request_options: RequestOptions | None = None,
77
+ ) -> AsyncPager[dict[str, Any]]:
78
+ """Lazily paginate corpora, yielding individual corpus items.
79
+
80
+ Args:
81
+ limit: Page size used for each underlying API request.
82
+
83
+ Yields:
84
+ Individual corpus response dicts.
85
+
86
+ Raises:
87
+ Knowledge2Error: If any underlying API request fails.
88
+ """
89
+ return self._paginate(
90
+ "GET",
91
+ "/v1/corpora",
92
+ items_key="corpora",
93
+ limit=limit,
94
+ )
95
+
96
+ async def get_corpus(
97
+ self,
98
+ corpus_id: str,
99
+ request_options: RequestOptions | None = None,
100
+ ) -> CorpusResponse:
101
+ """Retrieve a single corpus by ID.
102
+
103
+ Args:
104
+ corpus_id: Unique identifier of the corpus.
105
+
106
+ Returns:
107
+ The corpus record.
108
+
109
+ Raises:
110
+ NotFoundError: If the corpus does not exist.
111
+ Knowledge2Error: If the API request fails.
112
+ """
113
+ corpus_id = require_str(corpus_id, "corpus_id")
114
+ data = await self._request(
115
+ "GET", f"/v1/corpora/{corpus_id}", request_options=request_options
116
+ )
117
+ return self._maybe_validate(data, "CorpusResponse")
118
+
119
+ async def get_corpus_status(
120
+ self,
121
+ corpus_id: str,
122
+ request_options: RequestOptions | None = None,
123
+ ) -> CorpusStatusResponse:
124
+ """Retrieve the ingestion and indexing status of a corpus.
125
+
126
+ Args:
127
+ corpus_id: Unique identifier of the corpus.
128
+
129
+ Returns:
130
+ Status information including document counts and index state.
131
+
132
+ Raises:
133
+ NotFoundError: If the corpus does not exist.
134
+ Knowledge2Error: If the API request fails.
135
+ """
136
+ corpus_id = require_str(corpus_id, "corpus_id")
137
+ data = await self._request(
138
+ "GET", f"/v1/corpora/{corpus_id}/status", request_options=request_options
139
+ )
140
+ return self._maybe_validate(data, "CorpusStatusResponse")
141
+
142
+ async def update_corpus(
143
+ self,
144
+ corpus_id: str,
145
+ *,
146
+ name: str | None = None,
147
+ description: str | None = None,
148
+ chunking_config: dict[str, Any] | None = None,
149
+ graph_rag_policy: dict[str, Any] | None = None,
150
+ request_options: RequestOptions | None = None,
151
+ ) -> CorpusResponse:
152
+ """Update corpus settings.
153
+
154
+ Args:
155
+ corpus_id: ID of the corpus to update
156
+ name: New name for the corpus
157
+ description: New description for the corpus
158
+ chunking_config: Default chunking configuration for documents in this corpus.
159
+ graph_rag_policy: Optional corpus-level GraphRAG defaults that override
160
+ project-level settings when present.
161
+
162
+ Returns:
163
+ Updated corpus response
164
+ """
165
+ corpus_id = require_str(corpus_id, "corpus_id")
166
+ payload: dict[str, Any] = {}
167
+ if name is not None:
168
+ payload["name"] = name
169
+ if description is not None:
170
+ payload["description"] = description
171
+ if chunking_config is not None:
172
+ payload["chunking_config"] = chunking_config
173
+ if graph_rag_policy is not None:
174
+ payload["graph_rag_policy"] = graph_rag_policy
175
+ data = await self._request(
176
+ "PATCH", f"/v1/corpora/{corpus_id}", json=payload, request_options=request_options
177
+ )
178
+ return self._maybe_validate(data, "CorpusResponse")
179
+
180
+ async def delete_corpus(
181
+ self,
182
+ corpus_id: str,
183
+ *,
184
+ confirm: bool = False,
185
+ force: bool = False,
186
+ request_options: RequestOptions | None = None,
187
+ ) -> CorpusDeleteResponse:
188
+ """Delete a corpus and its associated data.
189
+
190
+ This is an irreversible operation. You must pass ``confirm=True``
191
+ to acknowledge this and proceed.
192
+
193
+ Args:
194
+ corpus_id: Unique identifier of the corpus to delete.
195
+ confirm: Safety guard -- must be ``True`` to execute the
196
+ deletion. Raises ``ConfirmationRequiredError`` when ``False``.
197
+ force: If ``True``, purge dependent corpus resources during
198
+ deletion.
199
+
200
+ Returns:
201
+ Confirmation of the deletion.
202
+
203
+ Raises:
204
+ ConfirmationRequiredError: If *confirm* is not ``True``.
205
+ NotFoundError: If the corpus does not exist.
206
+ ConflictError: If *force* is ``False`` and the corpus has
207
+ active resources.
208
+ Knowledge2Error: If the API request fails.
209
+ """
210
+ corpus_id = require_str(corpus_id, "corpus_id")
211
+ if not confirm:
212
+ raise ConfirmationRequiredError("corpus", corpus_id)
213
+ data = await self._request(
214
+ "DELETE",
215
+ f"/v1/corpora/{corpus_id}",
216
+ params={"force": force},
217
+ request_options=request_options,
218
+ )
219
+ return self._maybe_validate(data, "CorpusDeleteResponse")
220
+
221
+ async def list_corpus_models(
222
+ self,
223
+ corpus_id: str,
224
+ limit: int = 100,
225
+ offset: int = 0,
226
+ request_options: RequestOptions | None = None,
227
+ ) -> Page[dict[str, Any]]:
228
+ """List models associated with a corpus.
229
+
230
+ Args:
231
+ corpus_id: Unique identifier of the corpus.
232
+ limit: Maximum number of models to return per page.
233
+ offset: Number of models to skip for pagination.
234
+
235
+ Returns:
236
+ A Page containing model records for the corpus with pagination metadata.
237
+
238
+ Raises:
239
+ NotFoundError: If the corpus does not exist.
240
+ Knowledge2Error: If the API request fails.
241
+ """
242
+ corpus_id = require_str(corpus_id, "corpus_id")
243
+ return await self._list_page(
244
+ "GET",
245
+ f"/v1/corpora/{corpus_id}/models",
246
+ items_key="models",
247
+ limit=limit,
248
+ offset=offset,
249
+ )
250
+
251
+ def iter_corpus_models(
252
+ self,
253
+ corpus_id: str,
254
+ *,
255
+ limit: int = 100,
256
+ request_options: RequestOptions | None = None,
257
+ ) -> AsyncPager[dict[str, Any]]:
258
+ """Lazily paginate corpus models, yielding individual model items.
259
+
260
+ Args:
261
+ corpus_id: Unique identifier of the corpus.
262
+ limit: Page size used for each underlying API request.
263
+
264
+ Yields:
265
+ Individual model dicts.
266
+
267
+ Raises:
268
+ Knowledge2Error: If any underlying API request fails.
269
+ """
270
+ corpus_id = require_str(corpus_id, "corpus_id")
271
+ return self._paginate(
272
+ "GET",
273
+ f"/v1/corpora/{corpus_id}/models",
274
+ items_key="models",
275
+ limit=limit,
276
+ )
@@ -0,0 +1,106 @@
1
+ """Async deployment resource mixin for the Knowledge2 SDK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from sdk._async_paging import AsyncPager
8
+ from sdk._paging import Page
9
+ from sdk._request_options import RequestOptions
10
+ from sdk._validation import require_str
11
+ from sdk.async_resources._mixin_base import AsyncRequesterMixin
12
+ from sdk.types import DeploymentResponse
13
+
14
+
15
+ class AsyncDeploymentsMixin(AsyncRequesterMixin):
16
+ async def create_deployment(
17
+ self,
18
+ corpus_id: str,
19
+ model_id: str,
20
+ *,
21
+ traffic_pct: int = 100,
22
+ reindex: bool = True,
23
+ request_options: RequestOptions | None = None,
24
+ ) -> DeploymentResponse:
25
+ """Deploy a tuned model to a corpus for serving retrieval traffic.
26
+
27
+ Args:
28
+ corpus_id: The corpus to deploy the model to.
29
+ model_id: The tuned model to deploy.
30
+ traffic_pct: Percentage of retrieval traffic to route through
31
+ this deployment (0-100).
32
+ reindex: Whether to trigger a re-index after deployment.
33
+
34
+ Returns:
35
+ The created deployment record.
36
+
37
+ Raises:
38
+ NotFoundError: If the corpus or model does not exist.
39
+ Knowledge2Error: If the API request fails.
40
+ """
41
+ corpus_id = require_str(corpus_id, "corpus_id")
42
+ model_id = require_str(model_id, "model_id")
43
+ payload = {"model_id": model_id, "traffic_pct": traffic_pct, "reindex": reindex}
44
+ data = await self._request(
45
+ "POST",
46
+ f"/v1/corpora/{corpus_id}/deployments",
47
+ json=payload,
48
+ request_options=request_options,
49
+ )
50
+ return self._maybe_validate(data, "DeploymentResponse")
51
+
52
+ async def list_deployments(
53
+ self,
54
+ corpus_id: str,
55
+ limit: int = 100,
56
+ offset: int = 0,
57
+ request_options: RequestOptions | None = None,
58
+ ) -> Page[dict[str, Any]]:
59
+ """List deployments for a corpus.
60
+
61
+ Args:
62
+ corpus_id: The corpus whose deployments to list.
63
+ limit: Maximum number of deployments to return per page.
64
+ offset: Number of deployments to skip for pagination.
65
+
66
+ Returns:
67
+ A Page containing deployment records with pagination metadata.
68
+
69
+ Raises:
70
+ Knowledge2Error: If the API request fails.
71
+ """
72
+ corpus_id = require_str(corpus_id, "corpus_id")
73
+ return await self._list_page(
74
+ "GET",
75
+ f"/v1/corpora/{corpus_id}/deployments",
76
+ items_key="items",
77
+ limit=limit,
78
+ offset=offset,
79
+ )
80
+
81
+ def iter_deployments(
82
+ self,
83
+ corpus_id: str,
84
+ *,
85
+ limit: int = 100,
86
+ request_options: RequestOptions | None = None,
87
+ ) -> AsyncPager[dict[str, Any]]:
88
+ """Iterate over deployments, automatically paginating.
89
+
90
+ Args:
91
+ corpus_id: The corpus whose deployments to iterate.
92
+ limit: Page size used for each underlying API request.
93
+
94
+ Yields:
95
+ Individual deployment dicts.
96
+
97
+ Raises:
98
+ Knowledge2Error: If any underlying API request fails.
99
+ """
100
+ corpus_id = require_str(corpus_id, "corpus_id")
101
+ return self._paginate(
102
+ "GET",
103
+ f"/v1/corpora/{corpus_id}/deployments",
104
+ items_key="items",
105
+ limit=limit,
106
+ )