harborrag-runtime 2.0.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.
- harborrag_runtime/__init__.py +22 -0
- harborrag_runtime/application/README.md +39 -0
- harborrag_runtime/application/__init__.py +39 -0
- harborrag_runtime/application/chat/__init__.py +7 -0
- harborrag_runtime/application/chat/citations.py +149 -0
- harborrag_runtime/application/chat/client.py +201 -0
- harborrag_runtime/application/chat/completion.py +92 -0
- harborrag_runtime/application/chat/completion_request.py +130 -0
- harborrag_runtime/application/chat/evidence.py +202 -0
- harborrag_runtime/application/chat/options.py +43 -0
- harborrag_runtime/application/chat/preparation.py +135 -0
- harborrag_runtime/application/chat/presenters.py +130 -0
- harborrag_runtime/application/chat/prompting.py +127 -0
- harborrag_runtime/application/chat/query_scope.py +146 -0
- harborrag_runtime/application/chat/replay.py +141 -0
- harborrag_runtime/application/chat/request_filters.py +134 -0
- harborrag_runtime/application/chat/retrieval.py +127 -0
- harborrag_runtime/application/chat/service.py +371 -0
- harborrag_runtime/application/composition/__init__.py +1 -0
- harborrag_runtime/application/composition/factories.py +106 -0
- harborrag_runtime/application/composition/resources.py +141 -0
- harborrag_runtime/application/composition/selection.py +65 -0
- harborrag_runtime/application/composition/service.py +550 -0
- harborrag_runtime/application/composition/tenant_models.py +45 -0
- harborrag_runtime/application/control_plane/__init__.py +1 -0
- harborrag_runtime/application/control_plane/active_runs.py +38 -0
- harborrag_runtime/application/control_plane/connection_models.py +109 -0
- harborrag_runtime/application/control_plane/connection_testing.py +91 -0
- harborrag_runtime/application/control_plane/connection_writes.py +227 -0
- harborrag_runtime/application/control_plane/connections.py +749 -0
- harborrag_runtime/application/control_plane/effect_recovery.py +235 -0
- harborrag_runtime/application/control_plane/projects.py +313 -0
- harborrag_runtime/application/control_plane/settings_import.py +239 -0
- harborrag_runtime/application/control_plane/settings_service.py +233 -0
- harborrag_runtime/application/control_plane/tenants.py +55 -0
- harborrag_runtime/application/errors.py +110 -0
- harborrag_runtime/application/ingestion/__init__.py +1 -0
- harborrag_runtime/application/ingestion/client.py +65 -0
- harborrag_runtime/application/ingestion/connection_sources.py +96 -0
- harborrag_runtime/application/ingestion/direct.py +120 -0
- harborrag_runtime/application/ingestion/follower.py +83 -0
- harborrag_runtime/application/ingestion/ports.py +174 -0
- harborrag_runtime/application/ingestion/progress_bridge.py +221 -0
- harborrag_runtime/application/ingestion/retry_selection.py +71 -0
- harborrag_runtime/application/ingestion/service.py +564 -0
- harborrag_runtime/application/ingestion/starter.py +78 -0
- harborrag_runtime/application/memory/__init__.py +21 -0
- harborrag_runtime/application/memory/client.py +114 -0
- harborrag_runtime/application/memory/composition.py +90 -0
- harborrag_runtime/application/memory/context.py +45 -0
- harborrag_runtime/application/memory/sessions.py +117 -0
- harborrag_runtime/application/ports.py +133 -0
- harborrag_runtime/application/retrieval/__init__.py +1 -0
- harborrag_runtime/application/retrieval/access.py +26 -0
- harborrag_runtime/application/scheduling/service.py +58 -0
- harborrag_runtime/application/schemas.py +15 -0
- harborrag_runtime/chat/README.md +40 -0
- harborrag_runtime/chat/__init__.py +18 -0
- harborrag_runtime/chat/composition.py +53 -0
- harborrag_runtime/chat/facade.py +46 -0
- harborrag_runtime/chat/service.py +183 -0
- harborrag_runtime/chat/tenant_clients.py +341 -0
- harborrag_runtime/chat/tenant_config.py +235 -0
- harborrag_runtime/chat/tenant_models.py +22 -0
- harborrag_runtime/composition/__init__.py +5 -0
- harborrag_runtime/composition/config_store.py +53 -0
- harborrag_runtime/composition/connection_removal.py +120 -0
- harborrag_runtime/composition/connection_stores.py +107 -0
- harborrag_runtime/composition/control_plane.py +401 -0
- harborrag_runtime/composition/mcp_auth.py +39 -0
- harborrag_runtime/composition/readers.py +113 -0
- harborrag_runtime/composition/resources.py +336 -0
- harborrag_runtime/composition/storage_providers.py +113 -0
- harborrag_runtime/config/__init__.py +84 -0
- harborrag_runtime/config/checkout.py +212 -0
- harborrag_runtime/config/chunking.py +167 -0
- harborrag_runtime/config/connectors/__init__.py +19 -0
- harborrag_runtime/config/connectors/fingerprints.py +54 -0
- harborrag_runtime/config/connectors/importing.py +611 -0
- harborrag_runtime/config/connectors/loader.py +95 -0
- harborrag_runtime/config/connectors/models/__init__.py +30 -0
- harborrag_runtime/config/connectors/models/atlassian.py +199 -0
- harborrag_runtime/config/connectors/models/builder.py +208 -0
- harborrag_runtime/config/connectors/models/common.py +45 -0
- harborrag_runtime/config/connectors/models/fields.py +134 -0
- harborrag_runtime/config/connectors/models/github.py +143 -0
- harborrag_runtime/config/connectors/models/local_file.py +119 -0
- harborrag_runtime/config/connectors/models/registry.py +149 -0
- harborrag_runtime/config/connectors/models/sharepoint.py +186 -0
- harborrag_runtime/config/connectors/models/spec.py +563 -0
- harborrag_runtime/config/connectors/parsing.py +275 -0
- harborrag_runtime/config/connectors/providers.py +177 -0
- harborrag_runtime/config/connectors/schemas.py +215 -0
- harborrag_runtime/config/errors.py +26 -0
- harborrag_runtime/config/graph_build.py +335 -0
- harborrag_runtime/config/graph_build_loading.py +38 -0
- harborrag_runtime/config/loading.py +245 -0
- harborrag_runtime/config/models.py +95 -0
- harborrag_runtime/config/ontology_loading.py +76 -0
- harborrag_runtime/config/parsers/__init__.py +19 -0
- harborrag_runtime/config/parsers/loader.py +85 -0
- harborrag_runtime/config/parsers/parsing.py +285 -0
- harborrag_runtime/config/parsers/providers.py +305 -0
- harborrag_runtime/config/parsers/schemas.py +614 -0
- harborrag_runtime/config/settings.py +378 -0
- harborrag_runtime/config/settings_document.py +133 -0
- harborrag_runtime/config/temporal.py +331 -0
- harborrag_runtime/config/temporal_loading.py +310 -0
- harborrag_runtime/config_store/__init__.py +5 -0
- harborrag_runtime/config_store/defaults.py +47 -0
- harborrag_runtime/config_store/provider.py +153 -0
- harborrag_runtime/config_store/run_settings.py +72 -0
- harborrag_runtime/connections/__init__.py +27 -0
- harborrag_runtime/connections/secrets.py +348 -0
- harborrag_runtime/contracts.py +237 -0
- harborrag_runtime/document_stage_catalog.py +82 -0
- harborrag_runtime/errors.py +64 -0
- harborrag_runtime/events/__init__.py +3 -0
- harborrag_runtime/events/in_process.py +100 -0
- harborrag_runtime/execution/__init__.py +26 -0
- harborrag_runtime/execution/contracts.py +32 -0
- harborrag_runtime/execution/direct.py +169 -0
- harborrag_runtime/execution/gateway.py +97 -0
- harborrag_runtime/execution/source_conversion.py +61 -0
- harborrag_runtime/execution/source_submission.py +278 -0
- harborrag_runtime/execution/submission.py +64 -0
- harborrag_runtime/execution/task_registry.py +387 -0
- harborrag_runtime/execution/temporal.py +165 -0
- harborrag_runtime/ingestion/README.md +79 -0
- harborrag_runtime/ingestion/__init__.py +59 -0
- harborrag_runtime/ingestion/chunking_profile.py +97 -0
- harborrag_runtime/ingestion/composition.py +279 -0
- harborrag_runtime/ingestion/connection_checks.py +239 -0
- harborrag_runtime/ingestion/connections.py +507 -0
- harborrag_runtime/ingestion/document/__init__.py +1 -0
- harborrag_runtime/ingestion/document/normalization.py +14 -0
- harborrag_runtime/ingestion/document/normalizers/__init__.py +9 -0
- harborrag_runtime/ingestion/document/normalizers/builtins.py +39 -0
- harborrag_runtime/ingestion/document/normalizers/transform.py +30 -0
- harborrag_runtime/ingestion/document/run_tools.py +152 -0
- harborrag_runtime/ingestion/failure_classification.py +82 -0
- harborrag_runtime/ingestion/field_indexes.py +56 -0
- harborrag_runtime/ingestion/maintenance/__init__.py +1 -0
- harborrag_runtime/ingestion/maintenance/connection_removal.py +115 -0
- harborrag_runtime/ingestion/maintenance/projection_admin.py +180 -0
- harborrag_runtime/ingestion/maintenance/relation_repair.py +555 -0
- harborrag_runtime/ingestion/maintenance/retention.py +353 -0
- harborrag_runtime/ingestion/observability.py +3 -0
- harborrag_runtime/ingestion/profiles.py +127 -0
- harborrag_runtime/ingestion/runtime_builder.py +339 -0
- harborrag_runtime/ingestion/source/__init__.py +1 -0
- harborrag_runtime/ingestion/source/descriptor_mapping.py +144 -0
- harborrag_runtime/ingestion/source/discovery.py +290 -0
- harborrag_runtime/ingestion/source/documents.py +184 -0
- harborrag_runtime/ingestion/source/finalization.py +288 -0
- harborrag_runtime/ingestion/source/operations.py +175 -0
- harborrag_runtime/ingestion/source/plan.py +413 -0
- harborrag_runtime/ingestion/source/retry.py +150 -0
- harborrag_runtime/ingestion/source/service.py +470 -0
- harborrag_runtime/ingestion/source/skips.py +172 -0
- harborrag_runtime/ingestion_contracts.py +107 -0
- harborrag_runtime/memory/__init__.py +81 -0
- harborrag_runtime/memory/access.py +47 -0
- harborrag_runtime/memory/administration.py +460 -0
- harborrag_runtime/memory/context/__init__.py +5 -0
- harborrag_runtime/memory/context/result.py +20 -0
- harborrag_runtime/memory/directory.py +166 -0
- harborrag_runtime/memory/erasure.py +122 -0
- harborrag_runtime/memory/locks.py +170 -0
- harborrag_runtime/memory/messages.py +202 -0
- harborrag_runtime/memory/presenters.py +117 -0
- harborrag_runtime/memory/projects.py +38 -0
- harborrag_runtime/memory/tiers/__init__.py +1 -0
- harborrag_runtime/memory/tiers/in_memory.py +491 -0
- harborrag_runtime/memory/titles.py +32 -0
- harborrag_runtime/memory/usage.py +131 -0
- harborrag_runtime/observability/__init__.py +1 -0
- harborrag_runtime/observability/connector_metrics.py +14 -0
- harborrag_runtime/observability/discovery_metrics.py +46 -0
- harborrag_runtime/observability/model.py +410 -0
- harborrag_runtime/observability/observability_types.py +47 -0
- harborrag_runtime/observability/stage_observation.py +96 -0
- harborrag_runtime/observability/tool_audit.py +17 -0
- harborrag_runtime/plugins.py +56 -0
- harborrag_runtime/rate_limiting.py +39 -0
- harborrag_runtime/reader_contracts.py +149 -0
- harborrag_runtime/retrieval/__init__.py +1 -0
- harborrag_runtime/retrieval/composition.py +174 -0
- harborrag_runtime/retrieval/facades.py +224 -0
- harborrag_runtime/scheduling/__init__.py +48 -0
- harborrag_runtime/scheduling/config.py +185 -0
- harborrag_runtime/scheduling/errors.py +37 -0
- harborrag_runtime/scheduling/models.py +146 -0
- harborrag_runtime/scheduling/service.py +297 -0
- harborrag_runtime/scheduling/validation.py +213 -0
- harborrag_runtime/sdk/__init__.py +86 -0
- harborrag_runtime/sdk/configuration.py +44 -0
- harborrag_runtime/sdk/facades.py +47 -0
- harborrag_runtime/sdk/runtime.py +242 -0
- harborrag_runtime/security/__init__.py +1 -0
- harborrag_runtime/security/api_key_operations.py +236 -0
- harborrag_runtime/serialization.py +35 -0
- harborrag_runtime/temporal/__init__.py +19 -0
- harborrag_runtime/temporal/activity_observability.py +313 -0
- harborrag_runtime/temporal/client.py +580 -0
- harborrag_runtime/temporal/connection.py +39 -0
- harborrag_runtime/temporal/conversion.py +147 -0
- harborrag_runtime/temporal/dispatch.py +38 -0
- harborrag_runtime/temporal/document_workflow.py +154 -0
- harborrag_runtime/temporal/failure_handling.py +68 -0
- harborrag_runtime/temporal/gateway.py +121 -0
- harborrag_runtime/temporal/heartbeats.py +67 -0
- harborrag_runtime/temporal/identity.py +14 -0
- harborrag_runtime/temporal/ingestion_activities.py +435 -0
- harborrag_runtime/temporal/maintenance_activities.py +251 -0
- harborrag_runtime/temporal/maintenance_schemas.py +88 -0
- harborrag_runtime/temporal/optional.py +19 -0
- harborrag_runtime/temporal/plan_resolver.py +149 -0
- harborrag_runtime/temporal/policies.py +18 -0
- harborrag_runtime/temporal/reindex_workflow.py +71 -0
- harborrag_runtime/temporal/retry_activities.py +147 -0
- harborrag_runtime/temporal/retry_workflow.py +222 -0
- harborrag_runtime/temporal/sandbox.py +51 -0
- harborrag_runtime/temporal/schedules.py +341 -0
- harborrag_runtime/temporal/schemas.py +482 -0
- harborrag_runtime/temporal/source_activities.py +590 -0
- harborrag_runtime/temporal/source_batch_workflow.py +226 -0
- harborrag_runtime/temporal/source_workflow.py +908 -0
- harborrag_runtime/temporal/submission.py +23 -0
- harborrag_runtime/temporal/worker.py +478 -0
- harborrag_runtime/temporal/worker_registry.py +141 -0
- harborrag_runtime/temporal_models.py +227 -0
- harborrag_runtime/testing/chat_fakes.py +309 -0
- harborrag_runtime/testing/chat_service_double.py +126 -0
- harborrag_runtime/testing/connection_fakes.py +278 -0
- harborrag_runtime/testing/memory_fakes.py +128 -0
- harborrag_runtime/topology/__init__.py +1 -0
- harborrag_runtime/topology/budgeted_extractor.py +110 -0
- harborrag_runtime/topology/chunk_runner.py +41 -0
- harborrag_runtime/topology/composition.py +168 -0
- harborrag_runtime/topology/configuration.py +126 -0
- harborrag_runtime/topology/contextual.py +140 -0
- harborrag_runtime/topology/derived.py +238 -0
- harborrag_runtime/topology/derived_coverage.py +5 -0
- harborrag_runtime/topology/derived_dispatch.py +63 -0
- harborrag_runtime/topology/derived_factory.py +175 -0
- harborrag_runtime/topology/derived_models.py +251 -0
- harborrag_runtime/topology/derived_projection.py +127 -0
- harborrag_runtime/topology/description_factory.py +81 -0
- harborrag_runtime/topology/embedding_profile.py +85 -0
- harborrag_runtime/topology/entity_summary_index.py +304 -0
- harborrag_runtime/topology/maintenance.py +126 -0
- harborrag_runtime/topology/operations.py +277 -0
- harborrag_runtime/topology/parent_materializer.py +167 -0
- harborrag_runtime/topology/run_cost.py +43 -0
- harborrag_runtime/topology/security_operations.py +46 -0
- harborrag_runtime/topology/service.py +349 -0
- harborrag_runtime/topology/summary_factory.py +164 -0
- harborrag_runtime/topology/summary_inputs.py +129 -0
- harborrag_runtime/topology/summary_operations.py +128 -0
- harborrag_runtime/topology/summary_policy.py +39 -0
- harborrag_runtime/topology/summary_products.py +43 -0
- harborrag_runtime/topology/summary_service.py +625 -0
- harborrag_runtime/topology/summary_worker.py +129 -0
- harborrag_runtime/topology/summary_workflow.py +32 -0
- harborrag_runtime/topology/worker.py +101 -0
- harborrag_runtime/topology/workflow.py +32 -0
- harborrag_runtime-2.0.0.dist-info/METADATA +267 -0
- harborrag_runtime-2.0.0.dist-info/RECORD +271 -0
- harborrag_runtime-2.0.0.dist-info/WHEEL +4 -0
- harborrag_runtime-2.0.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Explicit summary administration and graph-independent worker composition."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import AsyncIterator, Awaitable, Callable
|
|
6
|
+
from contextlib import AsyncExitStack, asynccontextmanager
|
|
7
|
+
from typing import TYPE_CHECKING, cast
|
|
8
|
+
|
|
9
|
+
from harborrag_adapters.models.embed import HarborEmbedClient, HarborEmbedClientConfig
|
|
10
|
+
from harborrag_adapters.repositories.object_store import (
|
|
11
|
+
ARTIFACT_BUCKET,
|
|
12
|
+
ImmutableArtifactReader,
|
|
13
|
+
ImmutableArtifactWriter,
|
|
14
|
+
)
|
|
15
|
+
from harborrag_runtime.composition.resources import build_object_store, build_vector_repository
|
|
16
|
+
from harborrag_runtime.config.graph_build import GraphBuildConfig
|
|
17
|
+
from harborrag_runtime.config.settings import RuntimeSettings
|
|
18
|
+
from harborrag_runtime.config.temporal import TemporalRuntimeConfig
|
|
19
|
+
from harborrag_runtime.temporal.optional import load_temporal_attribute
|
|
20
|
+
|
|
21
|
+
from .composition import connect_topology_authority
|
|
22
|
+
from .derived_models import RequestEmbedder
|
|
23
|
+
from .summary_factory import SummaryRuntimeFactory
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from temporalio.client import Client
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def connect_temporal_client(config: TemporalRuntimeConfig) -> Client:
|
|
30
|
+
"""Load the optional Temporal transport only when the worker needs it."""
|
|
31
|
+
connect = cast(
|
|
32
|
+
"Callable[[TemporalRuntimeConfig], Awaitable[Client]]",
|
|
33
|
+
load_temporal_attribute(
|
|
34
|
+
"harborrag_runtime.temporal.connection",
|
|
35
|
+
"connect_temporal_client",
|
|
36
|
+
),
|
|
37
|
+
)
|
|
38
|
+
return await connect(config)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
async def watch_summaries(client: Client, factory: SummaryRuntimeFactory, tenant_id: str) -> None:
|
|
42
|
+
"""Load Temporal workflow definitions only when the worker starts."""
|
|
43
|
+
watch = cast(
|
|
44
|
+
"Callable[[Client, SummaryRuntimeFactory, str], Awaitable[None]]",
|
|
45
|
+
load_temporal_attribute(
|
|
46
|
+
"harborrag_runtime.topology.summary_worker",
|
|
47
|
+
"watch_summaries",
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
await watch(client, factory, tenant_id)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@asynccontextmanager
|
|
54
|
+
async def connect_summaries(
|
|
55
|
+
settings: RuntimeSettings, tenant_id: str
|
|
56
|
+
) -> AsyncIterator[SummaryRuntimeFactory]:
|
|
57
|
+
"""Open the control database, artifact store and optional entity index for summary work."""
|
|
58
|
+
config = GraphBuildConfig.from_settings(settings)
|
|
59
|
+
settings = config.effective_settings(settings)
|
|
60
|
+
async with AsyncExitStack() as stack:
|
|
61
|
+
control = await stack.enter_async_context(connect_topology_authority(settings))
|
|
62
|
+
store = build_object_store(settings)
|
|
63
|
+
stack.push_async_callback(store.close)
|
|
64
|
+
await store.connect()
|
|
65
|
+
await store.ensure_buckets((ARTIFACT_BUCKET,))
|
|
66
|
+
vectors = None
|
|
67
|
+
embed = None
|
|
68
|
+
if settings.summary_entity_index_enabled:
|
|
69
|
+
vectors = build_vector_repository(settings)
|
|
70
|
+
stack.push_async_callback(vectors.close)
|
|
71
|
+
await vectors.connect()
|
|
72
|
+
client = HarborEmbedClient.from_config(
|
|
73
|
+
HarborEmbedClientConfig.from_file(settings.model_config_path)
|
|
74
|
+
)
|
|
75
|
+
stack.push_async_callback(client.aclose)
|
|
76
|
+
embed = RequestEmbedder(client)
|
|
77
|
+
factory = SummaryRuntimeFactory(
|
|
78
|
+
settings,
|
|
79
|
+
control,
|
|
80
|
+
ImmutableArtifactReader(store),
|
|
81
|
+
ImmutableArtifactWriter(store),
|
|
82
|
+
vectors,
|
|
83
|
+
embed,
|
|
84
|
+
)
|
|
85
|
+
await factory.initialize(tenant_id)
|
|
86
|
+
yield factory
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
async def status(settings: RuntimeSettings, tenant_id: str) -> dict[str, object]:
|
|
90
|
+
"""Return the tenant's summary scopes and their state."""
|
|
91
|
+
async with connect_topology_authority(settings, migrate=False) as control:
|
|
92
|
+
return {"scopes": await control.summaries.status(tenant_id), "limit": 100}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
async def backfill(
|
|
96
|
+
settings: RuntimeSettings, tenant_id: str, scope: str | None
|
|
97
|
+
) -> dict[str, object]:
|
|
98
|
+
"""Enqueue summary jobs for one scope, or for every scope when ``scope`` is None."""
|
|
99
|
+
async with connect_summaries(settings, tenant_id) as factory:
|
|
100
|
+
await factory.synchronize(tenant_id)
|
|
101
|
+
return {"enqueued": await factory.control.summaries.backfill(tenant_id, scope)}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
async def run_once(settings: RuntimeSettings, tenant_id: str) -> dict[str, object]:
|
|
105
|
+
"""Reconcile summary jobs and run one."""
|
|
106
|
+
async with connect_summaries(settings, tenant_id) as factory:
|
|
107
|
+
await factory.synchronize(tenant_id)
|
|
108
|
+
await factory.control.summaries.reconcile(tenant_id)
|
|
109
|
+
return {"state": await factory.service().run_once(tenant_id)}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
async def worker(settings: RuntimeSettings, tenant_id: str) -> None:
|
|
113
|
+
"""Run the Temporal summary worker for the tenant until it stops."""
|
|
114
|
+
async with connect_summaries(settings, tenant_id) as factory:
|
|
115
|
+
client = await connect_temporal_client(
|
|
116
|
+
TemporalRuntimeConfig.from_settings(factory.settings)
|
|
117
|
+
)
|
|
118
|
+
await watch_summaries(client, factory, tenant_id)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
async def cleanup(
|
|
122
|
+
settings: RuntimeSettings, tenant_id: str, *, retention_days: int, apply: bool
|
|
123
|
+
) -> dict[str, object]:
|
|
124
|
+
"""Report or, when ``apply`` is true, delete summary data past ``retention_days``."""
|
|
125
|
+
async with connect_topology_authority(settings, migrate=False) as control:
|
|
126
|
+
return await control.summaries.cleanup(
|
|
127
|
+
tenant_id, retention_days=retention_days, apply=apply
|
|
128
|
+
)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Freeze all model-affecting summary policy without provider calls."""
|
|
2
|
+
|
|
3
|
+
from harborrag_adapters.models.chat import HarborChatClientConfig
|
|
4
|
+
from harborrag_adapters.topology import default_extraction_profile
|
|
5
|
+
from harborrag_adapters.topology.descriptions import (
|
|
6
|
+
DESCRIPTION_CONTRACT_VERSION,
|
|
7
|
+
DESCRIPTION_PROMPT,
|
|
8
|
+
)
|
|
9
|
+
from harborrag_core.summaries import CardWordBudgets, SummaryPolicy
|
|
10
|
+
from harborrag_core.topology.extraction import digest
|
|
11
|
+
from harborrag_runtime.config.settings import RuntimeSettings
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_summary_policy(
|
|
15
|
+
settings: RuntimeSettings, catalog: HarborChatClientConfig | None = None
|
|
16
|
+
) -> SummaryPolicy:
|
|
17
|
+
catalog = catalog or HarborChatClientConfig.from_file(settings.model_config_path)
|
|
18
|
+
profile = default_extraction_profile(catalog, settings.topology_parent_model)
|
|
19
|
+
return SummaryPolicy(
|
|
20
|
+
model_fingerprint=digest(
|
|
21
|
+
[
|
|
22
|
+
profile.model,
|
|
23
|
+
profile.deployment_revision,
|
|
24
|
+
profile.temperature,
|
|
25
|
+
profile.reasoning_effort,
|
|
26
|
+
settings.topology_parent_max_output_tokens,
|
|
27
|
+
DESCRIPTION_CONTRACT_VERSION,
|
|
28
|
+
DESCRIPTION_PROMPT,
|
|
29
|
+
]
|
|
30
|
+
),
|
|
31
|
+
max_fan_in=settings.topology_parent_max_fan_in,
|
|
32
|
+
max_input_bytes=settings.topology_parent_max_input_bytes,
|
|
33
|
+
max_input_tokens=settings.topology_parent_max_input_tokens,
|
|
34
|
+
max_calls=settings.topology_parent_max_calls,
|
|
35
|
+
card_words=CardWordBudgets(source_entity=settings.summary_entity_card_max_words),
|
|
36
|
+
debounce_seconds=settings.summary_debounce_seconds,
|
|
37
|
+
max_wait_seconds=settings.summary_max_wait_seconds,
|
|
38
|
+
tenant_enabled=settings.summary_tenant_enabled,
|
|
39
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Reuse accepted cards for the existing independently retriable graph/vector products."""
|
|
2
|
+
|
|
3
|
+
from harborrag_adapters.repositories.database import IngestionControlPlaneDatabase
|
|
4
|
+
from harborrag_core.topology import DocumentTopologyBuild
|
|
5
|
+
from harborrag_core.topology.derived import ParentDescription
|
|
6
|
+
from harborrag_core.topology.extraction import digest
|
|
7
|
+
|
|
8
|
+
from .budgeted_extractor import EnrichmentDeferredError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def summary_parents(
|
|
12
|
+
control: IngestionControlPlaneDatabase,
|
|
13
|
+
tenant_id: str,
|
|
14
|
+
build: DocumentTopologyBuild,
|
|
15
|
+
) -> tuple[ParentDescription, ...]:
|
|
16
|
+
records = await control.summaries.document_bindings(
|
|
17
|
+
tenant_id, build.document_id, build.document_version_id
|
|
18
|
+
)
|
|
19
|
+
parents = []
|
|
20
|
+
for node, binding in records:
|
|
21
|
+
chunks = binding.manifest.input_chunk_ids
|
|
22
|
+
if not chunks:
|
|
23
|
+
continue
|
|
24
|
+
document = binding.manifest.kind == "DocumentVersion"
|
|
25
|
+
section = node.entity_type.value == "section"
|
|
26
|
+
parents.append(
|
|
27
|
+
ParentDescription(
|
|
28
|
+
parent_key=build.document_id
|
|
29
|
+
if document
|
|
30
|
+
else digest([build.document_id, node.entity_type.value, node.logical_id]),
|
|
31
|
+
level="document" if document else "section" if section else "structure",
|
|
32
|
+
section_path=() if document else node.section_path,
|
|
33
|
+
structure_id=None if document else node.logical_id,
|
|
34
|
+
description=binding.card.description,
|
|
35
|
+
input_chunk_ids=chunks,
|
|
36
|
+
cited_chunk_ids=chunks,
|
|
37
|
+
input_digest=binding.manifest.input_digest,
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
documents = [parent for parent in parents if parent.level == "document"]
|
|
41
|
+
if len(documents) != 1 or set(documents[0].input_chunk_ids) != set(build.chunk_ids):
|
|
42
|
+
raise EnrichmentDeferredError("summary_projection_pending")
|
|
43
|
+
return tuple(parents)
|