aid-runtime-python 0.1.136__tar.gz → 0.1.138__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.
Files changed (116) hide show
  1. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/PKG-INFO +1 -1
  2. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/pyproject.toml +1 -1
  3. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/__init__.py +11 -1
  4. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/__init__.py +8 -0
  5. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/knowledge_base.py +331 -13
  6. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
  7. aid_runtime_python-0.1.138/tests/test_retrieval_knowledge_base.py +558 -0
  8. aid_runtime_python-0.1.136/tests/test_retrieval_knowledge_base.py +0 -266
  9. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/README.md +0 -0
  10. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/setup.cfg +0 -0
  11. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/__init__.py +0 -0
  12. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/chat_model.py +0 -0
  13. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/deep_agents.py +0 -0
  14. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/engine.py +0 -0
  15. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/guardrails.py +0 -0
  16. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/ir.py +0 -0
  17. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/loop.py +0 -0
  18. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/managed.py +0 -0
  19. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/memory.py +0 -0
  20. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/policy.py +0 -0
  21. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/agents/state.py +0 -0
  22. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/cache.py +0 -0
  23. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/concurrency.py +0 -0
  24. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/control.py +0 -0
  25. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/cost.py +0 -0
  26. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/decisions.py +0 -0
  27. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/errors.py +0 -0
  28. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/evals/__init__.py +0 -0
  29. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/evals/dataset.py +0 -0
  30. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/evals/gate.py +0 -0
  31. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/evals/metrics.py +0 -0
  32. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/evals/predicate.py +0 -0
  33. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/evals/runner.py +0 -0
  34. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/gateway.py +0 -0
  35. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/local_trace.py +0 -0
  36. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/pipeline.py +0 -0
  37. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/prompts.py +0 -0
  38. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/__init__.py +0 -0
  39. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/anthropic.py +0 -0
  40. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/base.py +0 -0
  41. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/bedrock.py +0 -0
  42. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/fake.py +0 -0
  43. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/gemini.py +0 -0
  44. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/gemini_wire.py +0 -0
  45. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/http.py +0 -0
  46. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/providers/vertex.py +0 -0
  47. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/py.typed +0 -0
  48. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/chunking.py +0 -0
  49. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/citations.py +0 -0
  50. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/connectors.py +0 -0
  51. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/embedding.py +0 -0
  52. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/filters.py +0 -0
  53. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/gate.py +0 -0
  54. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/hybrid.py +0 -0
  55. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/metrics.py +0 -0
  56. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/pgvector.py +0 -0
  57. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/rerank.py +0 -0
  58. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/retriever.py +0 -0
  59. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/stores.py +0 -0
  60. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/retrieval/types.py +0 -0
  61. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/steps.py +0 -0
  62. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/structured.py +0 -0
  63. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/tools.py +0 -0
  64. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/tracing.py +0 -0
  65. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime/types.py +0 -0
  66. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime_python.egg-info/SOURCES.txt +0 -0
  67. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
  68. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime_python.egg-info/requires.txt +0 -0
  69. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
  70. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_agents_budget.py +0 -0
  71. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_agents_deep_agents.py +0 -0
  72. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_agents_hitl.py +0 -0
  73. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_agents_loop.py +0 -0
  74. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_agents_memory.py +0 -0
  75. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_anthropic_provider.py +0 -0
  76. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_bedrock_provider.py +0 -0
  77. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_cache.py +0 -0
  78. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_concurrency.py +0 -0
  79. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_control.py +0 -0
  80. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_cost.py +0 -0
  81. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_dataset.py +0 -0
  82. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_decisions.py +0 -0
  83. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_evals.py +0 -0
  84. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_evals_assert_gate.py +0 -0
  85. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_evals_decision.py +0 -0
  86. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_evals_gate.py +0 -0
  87. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_evals_predicate.py +0 -0
  88. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_gateway.py +0 -0
  89. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_gemini_provider.py +0 -0
  90. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_guardrails.py +0 -0
  91. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_guardrails_managed.py +0 -0
  92. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_guardrails_model_armor.py +0 -0
  93. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_http_provider.py +0 -0
  94. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_local_trace.py +0 -0
  95. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_package.py +0 -0
  96. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_pipeline.py +0 -0
  97. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_prompts.py +0 -0
  98. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_chunking.py +0 -0
  99. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_citations.py +0 -0
  100. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_connectors.py +0 -0
  101. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_embedding.py +0 -0
  102. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_filters.py +0 -0
  103. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_gate.py +0 -0
  104. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_hybrid.py +0 -0
  105. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_metrics.py +0 -0
  106. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_rerank.py +0 -0
  107. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_stores.py +0 -0
  108. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_retrieval_types.py +0 -0
  109. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_steps.py +0 -0
  110. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_streaming.py +0 -0
  111. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_structured.py +0 -0
  112. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_tool_permissions.py +0 -0
  113. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_tools.py +0 -0
  114. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_tracing.py +0 -0
  115. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_types.py +0 -0
  116. {aid_runtime_python-0.1.136 → aid_runtime_python-0.1.138}/tests/test_vertex_provider.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.136
3
+ Version: 0.1.138
4
4
  Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
5
5
  Author: The AID Framework authors
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aid-runtime-python"
7
- version = "0.1.136"
7
+ version = "0.1.138"
8
8
  description = "The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -178,6 +178,7 @@ from aid_runtime.providers import (
178
178
  )
179
179
  from aid_runtime.retrieval import (
180
180
  DEFAULT_CANDIDATE_FACTOR,
181
+ DEFAULT_SYNC_TIMEOUT_SECONDS,
181
182
  Chunk,
182
183
  Chunker,
183
184
  ChunkingSpec,
@@ -234,6 +235,8 @@ from aid_runtime.retrieval import (
234
235
  SourceSpec,
235
236
  StoreKind,
236
237
  StoreRecord,
238
+ SyncResult,
239
+ SyncSupport,
237
240
  VectorStore,
238
241
  VectorStoreSpec,
239
242
  assemble_context,
@@ -248,6 +251,7 @@ from aid_runtime.retrieval import (
248
251
  embedder_for,
249
252
  estimate_tokens,
250
253
  fuse,
254
+ knowledge_base_client_for,
251
255
  lexical_ranking,
252
256
  lexical_score,
253
257
  open_connector,
@@ -257,6 +261,7 @@ from aid_runtime.retrieval import (
257
261
  retrieval_metrics,
258
262
  rrf_score,
259
263
  similarity,
264
+ sync_support,
260
265
  tokenize,
261
266
  )
262
267
  from aid_runtime.steps import (
@@ -310,7 +315,7 @@ from aid_runtime.types import (
310
315
  )
311
316
 
312
317
  #: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
313
- __version__ = "0.1.136"
318
+ __version__ = "0.1.138"
314
319
 
315
320
  __all__ = [
316
321
  "ANTHROPIC_VERSION",
@@ -320,6 +325,7 @@ __all__ = [
320
325
  "DEFAULT_BASE_URL",
321
326
  "DEFAULT_CANDIDATE_FACTOR",
322
327
  "DEFAULT_GEMINI_BASE_URL",
328
+ "DEFAULT_SYNC_TIMEOUT_SECONDS",
323
329
  "DEFAULT_TYPESAFE_BASE_URL",
324
330
  "DEFAULT_VERTEX_LOCATION",
325
331
  "DEPTH_KEY",
@@ -496,6 +502,8 @@ __all__ = [
496
502
  "StoreRecord",
497
503
  "StreamChunk",
498
504
  "StructuredOutputError",
505
+ "SyncResult",
506
+ "SyncSupport",
499
507
  "ThreadMemory",
500
508
  "Threshold",
501
509
  "TokenUsage",
@@ -547,6 +555,7 @@ __all__ = [
547
555
  "generate_step",
548
556
  "get_tracer",
549
557
  "is_reproducible_model",
558
+ "knowledge_base_client_for",
550
559
  "lexical_ranking",
551
560
  "lexical_score",
552
561
  "llm_span",
@@ -575,6 +584,7 @@ __all__ = [
575
584
  "run_evaluation",
576
585
  "run_structured",
577
586
  "similarity",
587
+ "sync_support",
578
588
  "tokenize",
579
589
  "tool_step",
580
590
  "z_critical",
@@ -76,15 +76,19 @@ from aid_runtime.retrieval.hybrid import (
76
76
  tokenize,
77
77
  )
78
78
  from aid_runtime.retrieval.knowledge_base import (
79
+ DEFAULT_SYNC_TIMEOUT_SECONDS,
79
80
  FIXTURE_ENV,
80
81
  BedrockKnowledgeBaseClient,
81
82
  FixtureKnowledgeBaseClient,
82
83
  KnowledgeBaseClient,
83
84
  KnowledgeChunk,
84
85
  KnowledgeResult,
86
+ SyncResult,
87
+ SyncSupport,
85
88
  VertexKnowledgeBaseClient,
86
89
  knowledge_base_client_for,
87
90
  knowledge_base_env_id,
91
+ sync_support,
88
92
  )
89
93
  from aid_runtime.retrieval.metrics import (
90
94
  CitationGrounding,
@@ -141,6 +145,7 @@ from aid_runtime.retrieval.types import (
141
145
 
142
146
  __all__ = [
143
147
  "DEFAULT_CANDIDATE_FACTOR",
148
+ "DEFAULT_SYNC_TIMEOUT_SECONDS",
144
149
  "FILTER_OPERATORS",
145
150
  "FIXTURE_ENV",
146
151
  "BedrockEmbedder",
@@ -209,6 +214,8 @@ __all__ = [
209
214
  "SourceSpec",
210
215
  "StoreKind",
211
216
  "StoreRecord",
217
+ "SyncResult",
218
+ "SyncSupport",
212
219
  "VectorStore",
213
220
  "VectorStoreSpec",
214
221
  "VertexEmbedder",
@@ -240,5 +247,6 @@ __all__ = [
240
247
  "retrieval_metrics",
241
248
  "rrf_score",
242
249
  "similarity",
250
+ "sync_support",
243
251
  "tokenize",
244
252
  ]
@@ -26,6 +26,16 @@ operation the caller holds, not a property of the corpus -- so there the guarant
26
26
  from the fixture client and from the deployment gating traffic on the import. That
27
27
  limitation is stated rather than hidden behind a poll that could never return false.
28
28
 
29
+ **Sync is what a managed retriever has instead of ingest.** A local retriever is filled by
30
+ an ingest module this runtime runs; a managed one is filled by the engine, so the only
31
+ operation left is asking the engine to do it. :meth:`BedrockKnowledgeBaseClient.sync`
32
+ starts the base's ingestion job and, when told to wait, polls the same job summary the
33
+ readiness check reads. It reports the job -- id, status and the engine's own failure
34
+ reason -- rather than a bare success, because a ``FAILED`` job folded into "ok" is the
35
+ same lie as an unindexed corpus answering every query with nothing. :func:`sync_support`
36
+ answers the prior question, *can this engine be asked at all*, so a caller can refuse
37
+ before it starts anything rather than after.
38
+
29
39
  **Filters are refused, not dropped.** The spec carries filter expressions as opaque
30
40
  strings, and the two engines disagree about what a string means. Bedrock's ``Retrieve``
31
41
  takes a structured filter document; Vertex's takes an expression in its own language.
@@ -68,15 +78,19 @@ from aid_runtime.providers.vertex import (
68
78
  from aid_runtime.retrieval.types import KnowledgeBaseEngine, KnowledgeBaseSpec
69
79
 
70
80
  __all__ = [
81
+ "DEFAULT_SYNC_TIMEOUT_SECONDS",
71
82
  "FIXTURE_ENV",
72
83
  "BedrockKnowledgeBaseClient",
73
84
  "FixtureKnowledgeBaseClient",
74
85
  "KnowledgeBaseClient",
75
86
  "KnowledgeChunk",
76
87
  "KnowledgeResult",
88
+ "SyncResult",
89
+ "SyncSupport",
77
90
  "VertexKnowledgeBaseClient",
78
91
  "knowledge_base_client_for",
79
92
  "knowledge_base_env_id",
93
+ "sync_support",
80
94
  ]
81
95
 
82
96
  #: Names a JSON file the fixture client serves results from. Set by ``aid dev`` and by a
@@ -93,6 +107,106 @@ _MAX_ERROR_BODY = 500
93
107
  #: is sorted by key, which this literal already is, so it can be signed and sent as one.
94
108
  _LATEST_JOB_QUERY = "maxResults=1&sortOrder=DESCENDING"
95
109
 
110
+ #: How long ``sync(wait=True)`` waits for a job before giving up. An ingestion of a small
111
+ #: corpus finishes in minutes; the ceiling exists so that a job wedged in the engine fails
112
+ #: the command instead of hanging it, and it is a parameter rather than a constant because
113
+ #: a large corpus legitimately needs a longer one.
114
+ DEFAULT_SYNC_TIMEOUT_SECONDS = 900.0
115
+
116
+ #: How often ``sync(wait=True)`` re-reads the job summary.
117
+ DEFAULT_SYNC_POLL_SECONDS = 2.0
118
+
119
+ _SYNC_COMPLETE = "COMPLETE"
120
+
121
+ #: Statuses that already are the job's verdict, so waiting for one more poll can only lose
122
+ #: it. ``STOPPED`` is here because Bedrock treats it as terminal and never resumes on its own.
123
+ _SYNC_FAILED_STATUSES = frozenset({"FAILED", "STOPPED"})
124
+
125
+ #: The engines with an ingestion job a caller can start, and the sentence that says why the
126
+ #: others have none. A missing entry means syncable; `_SYNC_REFUSALS` below states the
127
+ #: engine-specific reason rather than a generic "not supported", which would leave a reader
128
+ #: with nothing to do about it.
129
+ _SYNC_REFUSALS: Mapping[str, str] = {
130
+ "vertex-rag": (
131
+ "A vertex-rag corpus is filled by an import the caller holds rather than by an "
132
+ "ingestion job the corpus owns, so there is no job to start; re-run the "
133
+ "deployment's import instead."
134
+ ),
135
+ }
136
+
137
+
138
+ @dataclass(frozen=True, slots=True)
139
+ class SyncSupport:
140
+ """Whether one engine can be asked to ingest, and the sentence when it cannot.
141
+
142
+ ``engine`` echoes what was asked for, normalised when the runtime knows it, so a caller
143
+ that passed an alias still hears back the spelling the runtime resolved. ``reason`` is a
144
+ standalone sentence: the CLI prints it verbatim as the hint on its refusal, and the
145
+ hosted clients raise it after "cannot be synced.".
146
+ """
147
+
148
+ engine: str
149
+ supported: bool
150
+ reason: str | None = None
151
+
152
+ def as_dict(self) -> dict[str, Any]:
153
+ """The JSON shape a caller that cannot import this module reads."""
154
+ return {"engine": self.engine, "supported": self.supported, "reason": self.reason}
155
+
156
+
157
+ def sync_support(engine: str) -> SyncSupport:
158
+ """Whether a base on ``engine`` has an ingestion job this runtime can start.
159
+
160
+ The answer lives here rather than in the caller because "does this provider support
161
+ ingestion" is a fact about the provider, and a caller that restated it would be a second
162
+ copy of the engine table -- the copy that goes stale the day a provider changes.
163
+ """
164
+ try:
165
+ resolved = KnowledgeBaseEngine(engine)
166
+ except ValueError:
167
+ return SyncSupport(
168
+ engine=engine,
169
+ supported=False,
170
+ reason=(
171
+ f"No engine named {engine!r} is known to this runtime, so nothing can be "
172
+ "asked to ingest."
173
+ ),
174
+ )
175
+ reason = _SYNC_REFUSALS.get(resolved.value)
176
+ return SyncSupport(engine=resolved.value, supported=reason is None, reason=reason)
177
+
178
+
179
+ @dataclass(frozen=True, slots=True)
180
+ class SyncResult:
181
+ """What one ``sync`` started, and -- when it waited -- how that job ended.
182
+
183
+ ``status`` is the engine's own word for the job, never translated: ``COMPLETE`` and
184
+ ``FAILED`` mean what Bedrock says they mean, and a caller that has never seen a status
185
+ before can still report it honestly. ``waited`` distinguishes "the job was started" from
186
+ "the job is finished", which are different claims and must not be collapsed, and
187
+ ``failure_reason`` carries the engine's explanation rather than this runtime's summary.
188
+ """
189
+
190
+ knowledge_base_id: str
191
+ data_source_id: str
192
+ job_id: str
193
+ status: str
194
+ waited: bool = False
195
+ failure_reason: str | None = None
196
+
197
+ @property
198
+ def ok(self) -> bool:
199
+ """Whether the job is worth reporting as a success.
200
+
201
+ A started job is a success when the caller did not ask to wait: the request was to
202
+ begin an ingestion, and it did. A job the engine has already failed is never one,
203
+ waited for or not -- the status is the engine's verdict and is not this side's to
204
+ overrule.
205
+ """
206
+ if self.status in _SYNC_FAILED_STATUSES:
207
+ return False
208
+ return not self.waited or self.status == _SYNC_COMPLETE
209
+
96
210
 
97
211
  @dataclass(frozen=True, slots=True)
98
212
  class KnowledgeChunk:
@@ -167,6 +281,16 @@ class KnowledgeBaseClient(Protocol):
167
281
  ) -> KnowledgeResult:
168
282
  """One retrieve against the base, with the filters the caller asked for."""
169
283
 
284
+ async def sync(
285
+ self,
286
+ base: KnowledgeBaseSpec,
287
+ *,
288
+ wait: bool = False,
289
+ timeout_seconds: float = DEFAULT_SYNC_TIMEOUT_SECONDS,
290
+ poll_seconds: float = DEFAULT_SYNC_POLL_SECONDS,
291
+ ) -> SyncResult:
292
+ """Start an ingestion job, and -- under ``wait`` -- report how it ended."""
293
+
170
294
  async def aclose(self) -> None:
171
295
  """Release whatever the client holds open."""
172
296
 
@@ -313,19 +437,119 @@ class BedrockKnowledgeBaseClient(_HttpKnowledgeBaseClient):
313
437
  cost_usd=base.retrieve_cost_per_query_usd,
314
438
  )
315
439
 
440
+ async def sync(
441
+ self,
442
+ base: KnowledgeBaseSpec,
443
+ *,
444
+ wait: bool = False,
445
+ timeout_seconds: float = DEFAULT_SYNC_TIMEOUT_SECONDS,
446
+ poll_seconds: float = DEFAULT_SYNC_POLL_SECONDS,
447
+ ) -> SyncResult:
448
+ """Start the base's ingestion job, and under ``wait`` report how it ends.
449
+
450
+ The job is the engine's, not this process's: ``StartIngestionJob`` returns as soon as
451
+ the work is queued, so a return without ``wait`` says "an ingestion began", never
452
+ "the corpus is ready". Waiting polls the same summary the readiness check reads, and
453
+ stops on the engine's own terminal statuses rather than on a prediction of how long
454
+ indexing takes; a failed wait then reads the job itself, because the summary carries
455
+ no failure reason.
456
+
457
+ Starting a job invalidates the cached readiness either way: a base that was
458
+ ``COMPLETE`` a minute ago is being rebuilt now, and a retrieve that trusted the old
459
+ answer would search a corpus that is briefly empty.
460
+ """
461
+ knowledge_base_id = self._resolve(base)
462
+ data_source_id = await self._first_data_source(knowledge_base_id)
463
+ url = self._jobs_url(knowledge_base_id, data_source_id)
464
+ # `StartIngestionJob` has no body this runtime has anything to say in, but the
465
+ # request is still signed over a payload, so `{}` keeps one signing path instead of
466
+ # growing a third shape for an empty body.
467
+ body = await self._post(url, "{}")
468
+ started = _job_result(
469
+ self._json(body).get("ingestionJob"),
470
+ knowledge_base_id=knowledge_base_id,
471
+ data_source_id=data_source_id,
472
+ )
473
+ if started is None:
474
+ raise ProviderResponseError(
475
+ "the knowledge base acknowledged the start without an ingestion job", body
476
+ )
477
+ self._ready.discard(knowledge_base_id)
478
+ if not wait:
479
+ return started
480
+ return await self._await_job(
481
+ started,
482
+ url,
483
+ timeout_seconds=timeout_seconds,
484
+ poll_seconds=poll_seconds,
485
+ )
486
+
487
+ async def _await_job(
488
+ self,
489
+ started: SyncResult,
490
+ url: str,
491
+ *,
492
+ timeout_seconds: float,
493
+ poll_seconds: float,
494
+ ) -> SyncResult:
495
+ loop = asyncio.get_running_loop()
496
+ deadline = loop.time() + timeout_seconds
497
+ current = started
498
+ while current.status != _SYNC_COMPLETE and current.status not in _SYNC_FAILED_STATUSES:
499
+ if loop.time() >= deadline:
500
+ raise ProviderError(
501
+ f"ingestion job {started.job_id} on knowledge base "
502
+ f"{started.knowledge_base_id!r} was still {current.status} after "
503
+ f"{timeout_seconds:g}s; the job keeps running inside the engine, where a "
504
+ "later status read still sees it"
505
+ )
506
+ await asyncio.sleep(poll_seconds)
507
+ body = await self._get(url, query=_LATEST_JOB_QUERY)
508
+ latest = _job_result(
509
+ self._json(body).get("ingestionJobSummaries"),
510
+ knowledge_base_id=started.knowledge_base_id,
511
+ data_source_id=started.data_source_id,
512
+ waited=True,
513
+ )
514
+ if latest is None:
515
+ raise ProviderResponseError(
516
+ f"no ingestion job for knowledge base {started.knowledge_base_id!r} "
517
+ "while one was being waited for",
518
+ body,
519
+ )
520
+ current = latest
521
+ if current.status == _SYNC_COMPLETE:
522
+ # The wait ended on the one status the readiness check accepts, so recording it
523
+ # saves the next retrieve a round trip without ever asserting more than AWS said.
524
+ self._ready.add(started.knowledge_base_id)
525
+ elif current.status in _SYNC_FAILED_STATUSES:
526
+ # The poll reads the summary list, whose element type has no `failureReasons`,
527
+ # so a failed wait spends one more request to learn why instead of reporting a
528
+ # failure it cannot explain.
529
+ current = await self._failure_detail(current, url)
530
+ return current
531
+
532
+ async def _failure_detail(self, job: SyncResult, url: str) -> SyncResult:
533
+ """The failed job's own record, where the engine states why it failed."""
534
+ body = await self._get(f"{url}/{rfc3986(job.job_id)}")
535
+ detailed = _job_result(
536
+ self._json(body).get("ingestionJob"),
537
+ knowledge_base_id=job.knowledge_base_id,
538
+ data_source_id=job.data_source_id,
539
+ waited=True,
540
+ )
541
+ return detailed if detailed is not None else job
542
+
316
543
  async def _ensure_ingested(self, knowledge_base_id: str) -> None:
317
544
  if knowledge_base_id in self._ready:
318
545
  return
319
546
  data_source = await self._first_data_source(knowledge_base_id)
320
547
  body = await self._get(
321
- self._url(
322
- knowledge_base_id,
323
- f"datasources/{rfc3986(data_source)}/ingestionjobs",
324
- ),
325
- query=_LATEST_JOB_QUERY,
548
+ self._jobs_url(knowledge_base_id, data_source), query=_LATEST_JOB_QUERY
326
549
  )
327
- status = _first_status(self._json(body).get("ingestionJobSummaries"))
328
- if status != "COMPLETE":
550
+ job = _first_ingestion_job(self._json(body).get("ingestionJobSummaries"))
551
+ status = job.get("status") if job is not None else None
552
+ if status != _SYNC_COMPLETE:
329
553
  raise ConfigurationError(
330
554
  f"knowledge base {knowledge_base_id!r} has no completed ingestion job "
331
555
  f"(latest status: {status or 'none'}); the corpus is empty until one "
@@ -353,6 +577,13 @@ class BedrockKnowledgeBaseClient(_HttpKnowledgeBaseClient):
353
577
  base = self._base_url or f"https://{_BEDROCK_SERVICE}.{region}.amazonaws.com"
354
578
  return f"{base}/knowledgebases/{rfc3986(knowledge_base_id)}/{suffix}"
355
579
 
580
+ def _jobs_url(self, knowledge_base_id: str, data_source_id: str) -> str:
581
+ """The one ingestion-job collection: read for the latest job, posted to start one."""
582
+ return self._url(
583
+ knowledge_base_id,
584
+ f"datasources/{rfc3986(data_source_id)}/ingestionjobs",
585
+ )
586
+
356
587
  async def _get(self, url: str, *, query: str = "") -> str:
357
588
  headers = sigv4_headers(
358
589
  url=url,
@@ -378,17 +609,64 @@ class BedrockKnowledgeBaseClient(_HttpKnowledgeBaseClient):
378
609
  return await self._send("POST", url, body=payload, headers=headers)
379
610
 
380
611
 
381
- def _first_status(summaries: Any) -> str | None:
382
- if not isinstance(summaries, Sequence) or isinstance(summaries, (str, bytes)):
612
+ def _first_ingestion_job(value: Any) -> Mapping[str, Any] | None:
613
+ """One job record, from either shape the engine returns it in.
614
+
615
+ ``StartIngestionJob`` and ``GetIngestionJob`` answer with ``ingestionJob``; the list
616
+ answers with ``ingestionJobSummaries``. One reader serves both for the fields it reads,
617
+ the job id and the status. It does not serve both for ``failureReasons``: the summary
618
+ element type has no such member, so the reason is only readable from the job itself.
619
+ """
620
+ if isinstance(value, Mapping):
621
+ return value
622
+ if not isinstance(value, Sequence) or isinstance(value, (str, bytes)):
383
623
  return None
384
- for entry in summaries:
624
+ for entry in value:
385
625
  if isinstance(entry, Mapping):
386
- status = entry.get("status")
387
- if isinstance(status, str):
388
- return status
626
+ return entry
627
+ return None
628
+
629
+
630
+ def _failure_reason(value: Any) -> str | None:
631
+ """The engine's own explanation for a failed job, or ``None`` when it gave none.
632
+
633
+ ``IngestionJob.failureReasons`` is an array of strings, not of records. A reader that
634
+ expected objects would find nothing on every real failure and still look correct
635
+ against a fixture that encoded the same wrong shape.
636
+ """
637
+ if not isinstance(value, Sequence) or isinstance(value, (str, bytes)):
638
+ return None
639
+ for entry in value:
640
+ if isinstance(entry, str) and entry:
641
+ return entry
389
642
  return None
390
643
 
391
644
 
645
+ def _job_result(
646
+ value: Any,
647
+ *,
648
+ knowledge_base_id: str,
649
+ data_source_id: str,
650
+ waited: bool = False,
651
+ ) -> SyncResult | None:
652
+ """A job record as a :class:`SyncResult`, or ``None`` when the record is unusable."""
653
+ job = _first_ingestion_job(value)
654
+ if job is None:
655
+ return None
656
+ job_id = job.get("ingestionJobId")
657
+ status = job.get("status")
658
+ if not isinstance(job_id, str) or not job_id or not isinstance(status, str) or not status:
659
+ return None
660
+ return SyncResult(
661
+ knowledge_base_id=knowledge_base_id,
662
+ data_source_id=data_source_id,
663
+ job_id=job_id,
664
+ status=status,
665
+ waited=waited,
666
+ failure_reason=_failure_reason(job.get("failureReasons")),
667
+ )
668
+
669
+
392
670
  def _bedrock_chunks(answer: Mapping[str, Any]) -> tuple[KnowledgeChunk, ...]:
393
671
  results = answer.get("retrievalResults")
394
672
  if not isinstance(results, Sequence) or isinstance(results, (str, bytes)):
@@ -501,6 +779,27 @@ class VertexKnowledgeBaseClient(_HttpKnowledgeBaseClient):
501
779
  cost_usd=base.retrieve_cost_per_query_usd,
502
780
  )
503
781
 
782
+ async def sync(
783
+ self,
784
+ base: KnowledgeBaseSpec,
785
+ *,
786
+ wait: bool = False,
787
+ timeout_seconds: float = DEFAULT_SYNC_TIMEOUT_SECONDS,
788
+ poll_seconds: float = DEFAULT_SYNC_POLL_SECONDS,
789
+ ) -> SyncResult:
790
+ """Refused: a Vertex RAG corpus has no ingestion job for a caller to start.
791
+
792
+ Refused rather than silently reported as started, because the caller asked for a
793
+ corpus to be rebuilt and returning success would let a run believe it had been. The
794
+ reason comes from :func:`sync_support`, so a caller that checks first and a caller
795
+ that calls anyway hear exactly the same sentence.
796
+ """
797
+ support = sync_support(base.engine)
798
+ raise ConfigurationError(
799
+ f"knowledge base {base.id!r} cannot be synced. "
800
+ f"{support.reason or 'This engine has no ingestion job to start.'}"
801
+ )
802
+
504
803
  def _resolve_project(self) -> str:
505
804
  if self._project:
506
805
  return self._project
@@ -662,6 +961,25 @@ class FixtureKnowledgeBaseClient:
662
961
  cost_usd=base.retrieve_cost_per_query_usd,
663
962
  )
664
963
 
964
+ async def sync(
965
+ self,
966
+ base: KnowledgeBaseSpec,
967
+ *,
968
+ wait: bool = False,
969
+ timeout_seconds: float = DEFAULT_SYNC_TIMEOUT_SECONDS,
970
+ poll_seconds: float = DEFAULT_SYNC_POLL_SECONDS,
971
+ ) -> SyncResult:
972
+ """Refused: a fixture is a recording, so there is no corpus to rebuild.
973
+
974
+ The engine's capability is not in question here -- the fixture replaces the engine,
975
+ not its provider -- so the refusal names the fixture instead of reusing
976
+ :func:`sync_support`, whose sentence would blame an engine that is not being used.
977
+ """
978
+ raise ConfigurationError(
979
+ f"knowledge base {base.id!r} is served from a fixture, so there is no remote "
980
+ f"corpus to sync; unset {FIXTURE_ENV} to run against the engine"
981
+ )
982
+
665
983
 
666
984
  def _fixture_chunks(value: Any) -> tuple[KnowledgeChunk, ...]:
667
985
  if not isinstance(value, Sequence) or isinstance(value, (str, bytes)):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.136
3
+ Version: 0.1.138
4
4
  Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
5
5
  Author: The AID Framework authors
6
6
  License-Expression: Apache-2.0