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,339 @@
|
|
|
1
|
+
"""Builder for the production ingestion object graph."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from dataclasses import replace
|
|
7
|
+
|
|
8
|
+
from harborrag_adapters.connectors.policies.network import DestinationPolicy
|
|
9
|
+
from harborrag_adapters.connectors.rate_limiting import ConnectorRateLimiter
|
|
10
|
+
from harborrag_adapters.models.embed import HarborEmbedClient, HarborEmbedClientConfig
|
|
11
|
+
from harborrag_adapters.models.runtime import ResourceOwnership
|
|
12
|
+
from harborrag_adapters.repositories.object_store import (
|
|
13
|
+
CanonicalCommentArtifactRepository,
|
|
14
|
+
CanonicalDocumentArtifactRepository,
|
|
15
|
+
CanonicalTableArtifactRepository,
|
|
16
|
+
ChunkArtifactReader,
|
|
17
|
+
ChunkArtifactWriter,
|
|
18
|
+
ImmutableArtifactReader,
|
|
19
|
+
ImmutableArtifactWriter,
|
|
20
|
+
ProjectionArtifactRepository,
|
|
21
|
+
RawDocumentArtifactRepository,
|
|
22
|
+
)
|
|
23
|
+
from harborrag_core.chunking.tokenization import ApproximateTokenCounter
|
|
24
|
+
from harborrag_core.ingestion import SparseEncoderProfile
|
|
25
|
+
from harborrag_engine.ingestion import (
|
|
26
|
+
BaseChunker,
|
|
27
|
+
BaseDocumentNormalizer,
|
|
28
|
+
BM25SparseEncoder,
|
|
29
|
+
ChunkingConfig,
|
|
30
|
+
ChunkRepresentationEncoder,
|
|
31
|
+
ChunkStrategy,
|
|
32
|
+
RepresentationEncodingPolicy,
|
|
33
|
+
RepresentationReuseService,
|
|
34
|
+
VectorProjectionPolicy,
|
|
35
|
+
VectorProjectionStore,
|
|
36
|
+
build_chunking_service,
|
|
37
|
+
)
|
|
38
|
+
from harborrag_engine.ingestion.maintenance.cleanup import ProjectionCleanupService
|
|
39
|
+
from harborrag_engine.ingestion.maintenance.reindex import DocumentReindexService
|
|
40
|
+
from harborrag_engine.ingestion.normalizers.builder import SourceDocumentNormalizerBuilder
|
|
41
|
+
from harborrag_engine.ingestion.release.dependencies import DocumentReleaseDependencies
|
|
42
|
+
from harborrag_engine.ingestion.release.pipeline import DocumentStagePipeline
|
|
43
|
+
from harborrag_engine.ingestion.release.service import DocumentReleaseService
|
|
44
|
+
from harborrag_runtime.composition.config_store import build_config_provider
|
|
45
|
+
from harborrag_runtime.composition.connection_stores import build_connection_stores
|
|
46
|
+
from harborrag_runtime.composition.resources import (
|
|
47
|
+
build_ingestion_control,
|
|
48
|
+
build_knowledge_graph,
|
|
49
|
+
build_object_store,
|
|
50
|
+
build_vector_repository,
|
|
51
|
+
check_embedding_dimensions,
|
|
52
|
+
embedding_dimensions,
|
|
53
|
+
resource_hints,
|
|
54
|
+
resource_targets,
|
|
55
|
+
)
|
|
56
|
+
from harborrag_runtime.config import load_parser_catalog
|
|
57
|
+
from harborrag_runtime.config.chunking import RefinerConfig, chunking_settings_from
|
|
58
|
+
from harborrag_runtime.config.graph_build import GraphBuildConfig
|
|
59
|
+
from harborrag_runtime.config.settings import RuntimeSettings
|
|
60
|
+
from harborrag_runtime.config_store.run_settings import RunSettingsResolver
|
|
61
|
+
from harborrag_runtime.connections import default_secret_resolver
|
|
62
|
+
from harborrag_runtime.rate_limiting import build_connector_rate_limiter
|
|
63
|
+
|
|
64
|
+
from .chunking_profile import build_refiner, default_chunking_config
|
|
65
|
+
from .composition import IngestionRuntime
|
|
66
|
+
from .connections import ConnectionHealth, ConnectionResolver, ConnectorPool
|
|
67
|
+
from .document.normalizers import default_source_document_normalizer_builder
|
|
68
|
+
from .document.run_tools import RunTools
|
|
69
|
+
from .failure_classification import ingestion_failure_classifier
|
|
70
|
+
from .field_indexes import declared_field_indexes
|
|
71
|
+
from .maintenance.relation_repair import GraphRelationRepairService
|
|
72
|
+
from .maintenance.retention import RetiredVersionPurgeService
|
|
73
|
+
from .observability import IngestionTelemetry, build_model_telemetry
|
|
74
|
+
from .profiles import build_processing_profile
|
|
75
|
+
from .source.plan import SourcePlanRepository
|
|
76
|
+
from .source.service import SourceIngestionService
|
|
77
|
+
|
|
78
|
+
logger = logging.getLogger("harborrag.runtime.ingestion.runtime_builder")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class IngestionRuntimeBuilder:
|
|
82
|
+
"""Assemble one runtime graph without performing external I/O.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
settings: Runtime settings the graph is built from.
|
|
86
|
+
normalizer_builder: Source normalizer builder; the built-in providers when omitted.
|
|
87
|
+
chunking_config: Chunking configuration overriding the settings'.
|
|
88
|
+
chunking_strategies: Extra chunk strategies registered next to the built-in ones.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
def __init__(
|
|
92
|
+
self,
|
|
93
|
+
settings: RuntimeSettings,
|
|
94
|
+
*,
|
|
95
|
+
normalizer_builder: SourceDocumentNormalizerBuilder | None = None,
|
|
96
|
+
chunking_config: ChunkingConfig | None = None,
|
|
97
|
+
chunking_strategies: tuple[ChunkStrategy, ...] = (),
|
|
98
|
+
) -> None:
|
|
99
|
+
self._settings = settings
|
|
100
|
+
self._normalizer_builder = (
|
|
101
|
+
normalizer_builder or default_source_document_normalizer_builder()
|
|
102
|
+
)
|
|
103
|
+
self._chunking_config = chunking_config
|
|
104
|
+
self._chunking_strategies = tuple(chunking_strategies)
|
|
105
|
+
|
|
106
|
+
def build(self) -> IngestionRuntime:
|
|
107
|
+
"""Create the clients and services of the ingestion runtime without connecting them."""
|
|
108
|
+
settings = self._settings
|
|
109
|
+
telemetry = IngestionTelemetry(
|
|
110
|
+
metrics_port=settings.metrics_port,
|
|
111
|
+
metrics_bind_address=settings.metrics_bind_address,
|
|
112
|
+
)
|
|
113
|
+
parser_catalog = load_parser_catalog(settings.parser_config_path)
|
|
114
|
+
parser = parser_catalog.build_harbor_parser()
|
|
115
|
+
chunking = chunking_settings_from(settings)
|
|
116
|
+
boot_chunking = replace(chunking, config=self._chunking_config or chunking.config)
|
|
117
|
+
boot_chunker = build_default_chunker(
|
|
118
|
+
config=boot_chunking.config,
|
|
119
|
+
additional_strategies=self._chunking_strategies,
|
|
120
|
+
refiner=chunking.refiner,
|
|
121
|
+
)
|
|
122
|
+
rate_limiter = self._rate_limiter(telemetry)
|
|
123
|
+
stores = build_connection_stores(settings)
|
|
124
|
+
embed_client, model, dimensions = self._embedding_client()
|
|
125
|
+
control = build_ingestion_control(settings)
|
|
126
|
+
object_store = build_object_store(settings)
|
|
127
|
+
vectors = build_vector_repository(settings)
|
|
128
|
+
graph = build_knowledge_graph(settings)
|
|
129
|
+
artifacts = ImmutableArtifactWriter(object_store)
|
|
130
|
+
artifact_reader = ImmutableArtifactReader(object_store)
|
|
131
|
+
vector_store = VectorProjectionStore(
|
|
132
|
+
vectors,
|
|
133
|
+
VectorProjectionPolicy(
|
|
134
|
+
dimension=dimensions,
|
|
135
|
+
field_indexes=declared_field_indexes(GraphBuildConfig.from_settings(settings)),
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
canonical_artifacts = CanonicalDocumentArtifactRepository(
|
|
139
|
+
artifacts,
|
|
140
|
+
artifact_reader,
|
|
141
|
+
)
|
|
142
|
+
chunk_reader = ChunkArtifactReader(artifact_reader)
|
|
143
|
+
boot_representations = RepresentationReuseService(
|
|
144
|
+
ChunkRepresentationEncoder(
|
|
145
|
+
embed_client,
|
|
146
|
+
BM25SparseEncoder(self._sparse_profile()),
|
|
147
|
+
RepresentationEncodingPolicy(
|
|
148
|
+
logical_model=model,
|
|
149
|
+
dense_profile_id=settings.dense_encoder_profile,
|
|
150
|
+
dense_dimension=dimensions,
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
run_tools = RunTools(
|
|
155
|
+
parser=parser,
|
|
156
|
+
chunker=boot_chunker,
|
|
157
|
+
chunking=boot_chunking,
|
|
158
|
+
parsers=parser_catalog,
|
|
159
|
+
build_chunker=lambda config: build_default_chunker(
|
|
160
|
+
config=config,
|
|
161
|
+
additional_strategies=self._chunking_strategies,
|
|
162
|
+
refiner=chunking.refiner,
|
|
163
|
+
),
|
|
164
|
+
representations=boot_representations,
|
|
165
|
+
build_representations=lambda batch_size: RepresentationReuseService(
|
|
166
|
+
ChunkRepresentationEncoder(
|
|
167
|
+
embed_client,
|
|
168
|
+
BM25SparseEncoder(self._sparse_profile()),
|
|
169
|
+
RepresentationEncodingPolicy(
|
|
170
|
+
logical_model=model,
|
|
171
|
+
dense_profile_id=settings.dense_encoder_profile,
|
|
172
|
+
dense_dimension=dimensions,
|
|
173
|
+
batch_size=batch_size,
|
|
174
|
+
),
|
|
175
|
+
)
|
|
176
|
+
),
|
|
177
|
+
)
|
|
178
|
+
dependencies = DocumentReleaseDependencies(
|
|
179
|
+
parser=parser,
|
|
180
|
+
normalizer=self.build_document_normalizer(),
|
|
181
|
+
chunker=boot_chunker,
|
|
182
|
+
representations=boot_representations,
|
|
183
|
+
control=control,
|
|
184
|
+
raw_artifacts=RawDocumentArtifactRepository(artifacts, artifact_reader),
|
|
185
|
+
canonical_artifacts=canonical_artifacts,
|
|
186
|
+
comment_artifacts=CanonicalCommentArtifactRepository(
|
|
187
|
+
artifacts,
|
|
188
|
+
artifact_reader,
|
|
189
|
+
),
|
|
190
|
+
table_artifacts=CanonicalTableArtifactRepository(
|
|
191
|
+
artifacts,
|
|
192
|
+
artifact_reader,
|
|
193
|
+
),
|
|
194
|
+
chunk_writer=ChunkArtifactWriter(artifacts, artifact_reader),
|
|
195
|
+
chunk_reader=chunk_reader,
|
|
196
|
+
projection_artifacts=ProjectionArtifactRepository(
|
|
197
|
+
artifacts,
|
|
198
|
+
artifact_reader,
|
|
199
|
+
),
|
|
200
|
+
vector_store=vector_store,
|
|
201
|
+
graph_store=graph,
|
|
202
|
+
failures=ingestion_failure_classifier(),
|
|
203
|
+
parser_for=run_tools.parser_for,
|
|
204
|
+
chunker_for=run_tools.chunker_for,
|
|
205
|
+
representations_for=run_tools.representations_for,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
stages = DocumentStagePipeline(dependencies)
|
|
209
|
+
documents = DocumentReleaseService(dependencies, pipeline=stages)
|
|
210
|
+
relations = GraphRelationRepairService(
|
|
211
|
+
control=control,
|
|
212
|
+
canonical_artifacts=canonical_artifacts,
|
|
213
|
+
chunk_reader=chunk_reader,
|
|
214
|
+
graph_store=graph,
|
|
215
|
+
max_concurrency=settings.graph_relation_repair_concurrency,
|
|
216
|
+
)
|
|
217
|
+
config = build_config_provider(settings, engine=stores.engine, store=stores.config_store)
|
|
218
|
+
return IngestionRuntime(
|
|
219
|
+
connector_pool=ConnectorPool(
|
|
220
|
+
revisions=stores.revisions,
|
|
221
|
+
secrets=default_secret_resolver(stores.secrets),
|
|
222
|
+
parser=parser,
|
|
223
|
+
destination_policy=DestinationPolicy.from_environ(),
|
|
224
|
+
rate_limiter=rate_limiter,
|
|
225
|
+
),
|
|
226
|
+
connection_health=ConnectionHealth(stores.connections),
|
|
227
|
+
connection_resolver=ConnectionResolver(
|
|
228
|
+
stores.connections, stores.revisions, run_settings=RunSettingsResolver(config)
|
|
229
|
+
),
|
|
230
|
+
connection_stores=stores,
|
|
231
|
+
config=config,
|
|
232
|
+
processing=build_processing_profile(
|
|
233
|
+
settings,
|
|
234
|
+
chunking_config=self._chunking_config,
|
|
235
|
+
chunking_strategies=self._chunking_strategies,
|
|
236
|
+
),
|
|
237
|
+
control=control,
|
|
238
|
+
documents=documents,
|
|
239
|
+
stages=stages,
|
|
240
|
+
sources=SourceIngestionService(
|
|
241
|
+
control=control,
|
|
242
|
+
documents=documents,
|
|
243
|
+
relations=relations,
|
|
244
|
+
),
|
|
245
|
+
relations=relations,
|
|
246
|
+
cleanup=ProjectionCleanupService(
|
|
247
|
+
control=control,
|
|
248
|
+
vector_store=vector_store,
|
|
249
|
+
graph_store=graph,
|
|
250
|
+
),
|
|
251
|
+
retention=RetiredVersionPurgeService(
|
|
252
|
+
control=control,
|
|
253
|
+
object_store=object_store,
|
|
254
|
+
retention_days=settings.retired_version_retention_days,
|
|
255
|
+
),
|
|
256
|
+
reindex=DocumentReindexService(dependencies, pipeline=stages),
|
|
257
|
+
source_plans=SourcePlanRepository(artifacts, artifact_reader),
|
|
258
|
+
object_store=object_store,
|
|
259
|
+
vector_repository=vectors,
|
|
260
|
+
graph_repository=graph,
|
|
261
|
+
embed_client=embed_client,
|
|
262
|
+
connector_rate_limiter=rate_limiter,
|
|
263
|
+
telemetry=telemetry,
|
|
264
|
+
resource_targets=resource_targets(settings),
|
|
265
|
+
resource_hints=resource_hints(settings),
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
def build_document_normalizer(self) -> BaseDocumentNormalizer:
|
|
269
|
+
"""Build the configured immutable provider router."""
|
|
270
|
+
return self._normalizer_builder.build()
|
|
271
|
+
|
|
272
|
+
def _rate_limiter(self, telemetry: IngestionTelemetry) -> ConnectorRateLimiter:
|
|
273
|
+
return build_connector_rate_limiter(
|
|
274
|
+
self._settings,
|
|
275
|
+
on_wait=lambda scope, wait_seconds: telemetry.record_rate_limit_wait(
|
|
276
|
+
scope.connector_type,
|
|
277
|
+
wait_seconds,
|
|
278
|
+
),
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
def _embedding_client(self) -> tuple[HarborEmbedClient, str, int]:
|
|
282
|
+
settings = self._settings
|
|
283
|
+
config = HarborEmbedClientConfig.from_file(settings.model_config_path)
|
|
284
|
+
model = settings.embedding_model or config.default_model
|
|
285
|
+
if settings.embedding_dimensions:
|
|
286
|
+
dimensions = settings.embedding_dimensions
|
|
287
|
+
check_embedding_dimensions(config, model, dimensions)
|
|
288
|
+
else:
|
|
289
|
+
dimensions = embedding_dimensions(config, model)
|
|
290
|
+
client = HarborEmbedClient.from_config(
|
|
291
|
+
config,
|
|
292
|
+
telemetry=build_model_telemetry(
|
|
293
|
+
config,
|
|
294
|
+
langfuse_enabled=settings.langfuse_enabled,
|
|
295
|
+
),
|
|
296
|
+
telemetry_ownership=ResourceOwnership.OWNED,
|
|
297
|
+
)
|
|
298
|
+
return client, model, dimensions
|
|
299
|
+
|
|
300
|
+
def _sparse_profile(self) -> SparseEncoderProfile:
|
|
301
|
+
settings = self._settings
|
|
302
|
+
return SparseEncoderProfile(
|
|
303
|
+
profile_id=settings.sparse_encoder_profile,
|
|
304
|
+
k=settings.sparse_k,
|
|
305
|
+
b=settings.sparse_b,
|
|
306
|
+
fixed_avg_len=settings.sparse_fixed_avg_len,
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def build_default_chunker(
|
|
311
|
+
*,
|
|
312
|
+
config: ChunkingConfig | None = None,
|
|
313
|
+
additional_strategies: tuple[ChunkStrategy, ...] = (),
|
|
314
|
+
refiner: RefinerConfig | None = None,
|
|
315
|
+
) -> BaseChunker:
|
|
316
|
+
"""Build canonical chunking with optional source-owned extensions."""
|
|
317
|
+
token_counter = ApproximateTokenCounter()
|
|
318
|
+
return build_chunking_service(
|
|
319
|
+
config=config or default_chunking_config(),
|
|
320
|
+
token_counter=token_counter,
|
|
321
|
+
refiner=build_refiner(token_counter, refiner),
|
|
322
|
+
additional_strategies=additional_strategies,
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def build_ingestion_runtime(
|
|
327
|
+
settings: RuntimeSettings | None = None,
|
|
328
|
+
*,
|
|
329
|
+
normalizer_builder: SourceDocumentNormalizerBuilder | None = None,
|
|
330
|
+
chunking_config: ChunkingConfig | None = None,
|
|
331
|
+
chunking_strategies: tuple[ChunkStrategy, ...] = (),
|
|
332
|
+
) -> IngestionRuntime:
|
|
333
|
+
"""Build the production ingestion object graph without starting resources."""
|
|
334
|
+
return IngestionRuntimeBuilder(
|
|
335
|
+
settings or RuntimeSettings(),
|
|
336
|
+
normalizer_builder=normalizer_builder,
|
|
337
|
+
chunking_config=chunking_config,
|
|
338
|
+
chunking_strategies=chunking_strategies,
|
|
339
|
+
).build()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Source discovery, dispatch, retry, and finalization services."""
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""Map connector descriptors into durable source registrations and releases."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import asdict, dataclass
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from harborrag_adapters.connectors.descriptors import ConnectorDocumentDescriptor
|
|
9
|
+
from harborrag_core.chunking import RelationType
|
|
10
|
+
from harborrag_core.domain.source import SourceRecord
|
|
11
|
+
from harborrag_core.ingestion import (
|
|
12
|
+
AdmissionSnapshot,
|
|
13
|
+
BindingKind,
|
|
14
|
+
ChangeFingerprintBuilder,
|
|
15
|
+
DiscoveredSourceItem,
|
|
16
|
+
DocumentIdentityBuilder,
|
|
17
|
+
SourceBinding,
|
|
18
|
+
SourceIdentity,
|
|
19
|
+
SourceRelationDescriptor,
|
|
20
|
+
)
|
|
21
|
+
from harborrag_engine.ingestion.release.models import DocumentReleaseRequest
|
|
22
|
+
from harborrag_engine.ingestion.source.models import PlannedDocumentRelease, SourceIngestionRequest
|
|
23
|
+
from harborrag_runtime.serialization import to_json_value
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True, slots=True)
|
|
27
|
+
class PendingSourceRelease:
|
|
28
|
+
"""A discovered item paired with the release planned for it."""
|
|
29
|
+
|
|
30
|
+
item: DiscoveredSourceItem
|
|
31
|
+
release: PlannedDocumentRelease
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class SourceDescriptorMapper:
|
|
35
|
+
"""Apply stable identity and admission rules to connector descriptors."""
|
|
36
|
+
|
|
37
|
+
def __init__(self) -> None:
|
|
38
|
+
self._identities = DocumentIdentityBuilder()
|
|
39
|
+
self._fingerprints = ChangeFingerprintBuilder()
|
|
40
|
+
|
|
41
|
+
def releases(
|
|
42
|
+
self,
|
|
43
|
+
request: SourceIngestionRequest,
|
|
44
|
+
descriptor: ConnectorDocumentDescriptor,
|
|
45
|
+
) -> tuple[PendingSourceRelease, ...]:
|
|
46
|
+
"""Map a connector descriptor to the releases it contributes."""
|
|
47
|
+
sources = (
|
|
48
|
+
(descriptor.source, descriptor.admission),
|
|
49
|
+
*((bound, self._bound_admission(bound)) for bound in descriptor.bound_records),
|
|
50
|
+
)
|
|
51
|
+
pending: list[PendingSourceRelease] = []
|
|
52
|
+
for source, admission in sources:
|
|
53
|
+
identity = self._source_identity(request, source)
|
|
54
|
+
document_id = self._identities.document_id(
|
|
55
|
+
tenant_id=identity.tenant_id,
|
|
56
|
+
connector_type=identity.connector_type,
|
|
57
|
+
connection_id=identity.connection_id,
|
|
58
|
+
source_item_id=identity.source_item_id,
|
|
59
|
+
)
|
|
60
|
+
pending.append(
|
|
61
|
+
PendingSourceRelease(
|
|
62
|
+
item=DiscoveredSourceItem(
|
|
63
|
+
source_identity=identity,
|
|
64
|
+
document_id=document_id,
|
|
65
|
+
source_version=admission.source_version,
|
|
66
|
+
admission_change_key=(
|
|
67
|
+
self._fingerprints.admission_change_key(snapshot=admission)
|
|
68
|
+
),
|
|
69
|
+
descriptor=self._source_payload(source),
|
|
70
|
+
),
|
|
71
|
+
release=PlannedDocumentRelease(
|
|
72
|
+
request=DocumentReleaseRequest(
|
|
73
|
+
tenant_id=request.tenant_id,
|
|
74
|
+
connector_name=request.connector_name,
|
|
75
|
+
source=source,
|
|
76
|
+
source_identity=identity,
|
|
77
|
+
admission=admission,
|
|
78
|
+
processing=request.processing,
|
|
79
|
+
configuration_fingerprint=request.configuration_fingerprint,
|
|
80
|
+
force_reprocess=request.force_reprocess,
|
|
81
|
+
run_settings=request.run_settings,
|
|
82
|
+
),
|
|
83
|
+
document_id=document_id,
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
return tuple(pending)
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def _source_identity(
|
|
91
|
+
request: SourceIngestionRequest,
|
|
92
|
+
source: SourceRecord,
|
|
93
|
+
) -> SourceIdentity:
|
|
94
|
+
raw_binding = str(source.metadata.get("binding_kind") or "ROOT")
|
|
95
|
+
parent = source.metadata.get("parent_source_item_id")
|
|
96
|
+
return SourceIdentity(
|
|
97
|
+
tenant_id=request.tenant_id,
|
|
98
|
+
connector_type=request.connector_type,
|
|
99
|
+
connection_id=request.connection_id,
|
|
100
|
+
source_item_id=SourceDescriptorMapper._source_item_id(request, source),
|
|
101
|
+
source_scope_id=request.source_scope_id,
|
|
102
|
+
binding=SourceBinding(
|
|
103
|
+
kind=BindingKind(raw_binding),
|
|
104
|
+
parent_source_item_id=(str(parent) if parent is not None else None),
|
|
105
|
+
),
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def _source_item_id(
|
|
110
|
+
request: SourceIngestionRequest,
|
|
111
|
+
source: SourceRecord,
|
|
112
|
+
) -> str:
|
|
113
|
+
del request
|
|
114
|
+
relative_path = source.metadata.get("relative_path")
|
|
115
|
+
if relative_path is None:
|
|
116
|
+
return source.id
|
|
117
|
+
if not str(relative_path).strip():
|
|
118
|
+
raise ValueError("source relative_path must be non-empty when provided")
|
|
119
|
+
value = str(relative_path).replace("\\", "/")
|
|
120
|
+
if value.startswith(("/", "../")) or "/../" in f"/{value}/":
|
|
121
|
+
raise ValueError("source relative_path must stay inside its source scope")
|
|
122
|
+
return value
|
|
123
|
+
|
|
124
|
+
@staticmethod
|
|
125
|
+
def _bound_admission(source: SourceRecord) -> AdmissionSnapshot:
|
|
126
|
+
parent = str(source.metadata["parent_source_item_id"])
|
|
127
|
+
version = str(source.metadata["source_version"])
|
|
128
|
+
return AdmissionSnapshot(
|
|
129
|
+
source_version=version,
|
|
130
|
+
relations=(
|
|
131
|
+
SourceRelationDescriptor(
|
|
132
|
+
relation_type=RelationType.ATTACHED_TO,
|
|
133
|
+
target_source_item_id=parent,
|
|
134
|
+
source_relation_version=version,
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
@staticmethod
|
|
140
|
+
def _source_payload(source: SourceRecord) -> dict[str, Any]:
|
|
141
|
+
payload = to_json_value(asdict(source))
|
|
142
|
+
if not isinstance(payload, dict):
|
|
143
|
+
raise TypeError("serialized source descriptor is not an object")
|
|
144
|
+
return {str(key): value for key, value in payload.items()}
|