contextsynapse 1.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.
- contextsynapse/__init__.py +107 -0
- contextsynapse/__main__.py +9 -0
- contextsynapse/a2a/__init__.py +28 -0
- contextsynapse/a2a/client.py +120 -0
- contextsynapse/a2a/discovery.py +128 -0
- contextsynapse/a2a/handlers.py +164 -0
- contextsynapse/a2a/models.py +246 -0
- contextsynapse/a2a/streaming.py +92 -0
- contextsynapse/a2a/task_manager.py +275 -0
- contextsynapse/adapters/__init__.py +98 -0
- contextsynapse/adapters/_base.py +298 -0
- contextsynapse/adapters/autogen/__init__.py +4 -0
- contextsynapse/adapters/autogen/tools.py +34 -0
- contextsynapse/adapters/crewai/__init__.py +4 -0
- contextsynapse/adapters/crewai/tools.py +63 -0
- contextsynapse/adapters/langchain/__init__.py +19 -0
- contextsynapse/adapters/langchain/message_history.py +17 -0
- contextsynapse/adapters/langchain/retriever.py +158 -0
- contextsynapse/adapters/langchain/tools.py +43 -0
- contextsynapse/adapters/langgraph/__init__.py +21 -0
- contextsynapse/adapters/langgraph/checkpoint.py +223 -0
- contextsynapse/adapters/langgraph/context_tools.py +341 -0
- contextsynapse/adapters/langgraph/message_history.py +138 -0
- contextsynapse/adapters/langgraph/tools.py +43 -0
- contextsynapse/adapters/llamaindex/__init__.py +4 -0
- contextsynapse/adapters/llamaindex/tools.py +64 -0
- contextsynapse/adapters/openai/__init__.py +24 -0
- contextsynapse/adapters/openai/tools.py +206 -0
- contextsynapse/adapters/pydantic_ai/__init__.py +4 -0
- contextsynapse/adapters/pydantic_ai/tools.py +36 -0
- contextsynapse/adapters/swarm/__init__.py +4 -0
- contextsynapse/adapters/swarm/tools.py +44 -0
- contextsynapse/agents/__init__.py +6 -0
- contextsynapse/agents/auto_capture.py +80 -0
- contextsynapse/agents/dispatcher.py +299 -0
- contextsynapse/agents/notifications.py +112 -0
- contextsynapse/aiql/__init__.py +71 -0
- contextsynapse/aiql/cache.py +341 -0
- contextsynapse/aiql/compiler/__init__.py +62 -0
- contextsynapse/aiql/compiler/optimizer.py +126 -0
- contextsynapse/aiql/compiler/planner.py +366 -0
- contextsynapse/aiql/compiler/statistics.py +235 -0
- contextsynapse/aiql/compiler/validator.py +425 -0
- contextsynapse/aiql/engine/__init__.py +11 -0
- contextsynapse/aiql/engine/chunk_storage.py +2584 -0
- contextsynapse/aiql/engine/executor.py +7737 -0
- contextsynapse/aiql/engine/extraction_integration.py +442 -0
- contextsynapse/aiql/engine/graph_builder.py +405 -0
- contextsynapse/aiql/engine/node_creation_from_normalized.py +691 -0
- contextsynapse/aiql/engine/performance_monitor.py +289 -0
- contextsynapse/aiql/engine/postprocessing.py +365 -0
- contextsynapse/aiql/engine/ray_stage_executors.py +918 -0
- contextsynapse/aiql/engine/redis_cache.py +106 -0
- contextsynapse/aiql/engine/streaming_json.py +366 -0
- contextsynapse/aiql/engine/streaming_parquet.py +568 -0
- contextsynapse/aiql/engine/streaming_ray_chunking.py +419 -0
- contextsynapse/aiql/grammar/__init__.py +14 -0
- contextsynapse/aiql/grammar/aiql_grammar.py +1822 -0
- contextsynapse/aiql/grammar/base.py +71 -0
- contextsynapse/aiql/parser/__init__.py +46 -0
- contextsynapse/aiql/parser/aiql_parser.py +11330 -0
- contextsynapse/aiql/parser/base_parser.py +47 -0
- contextsynapse/api/__init__.py +5 -0
- contextsynapse/api/a2a_router.py +233 -0
- contextsynapse/api/admin_router.py +140 -0
- contextsynapse/api/agent_worker_router.py +978 -0
- contextsynapse/api/algorithms_router.py +317 -0
- contextsynapse/api/api.py +4144 -0
- contextsynapse/api/audit.py +204 -0
- contextsynapse/api/auth.py +441 -0
- contextsynapse/api/auth_router.py +537 -0
- contextsynapse/api/billing.py +261 -0
- contextsynapse/api/billing_router.py +275 -0
- contextsynapse/api/boundary_router.py +452 -0
- contextsynapse/api/cognition_router.py +116 -0
- contextsynapse/api/connector_router.py +237 -0
- contextsynapse/api/context_router.py +1619 -0
- contextsynapse/api/dashboard_router.py +11367 -0
- contextsynapse/api/errors.py +183 -0
- contextsynapse/api/events.py +88 -0
- contextsynapse/api/experiment_bootstrap.py +321 -0
- contextsynapse/api/experiment_orchestrator.py +1078 -0
- contextsynapse/api/experiment_router.py +2089 -0
- contextsynapse/api/feature_gate.py +89 -0
- contextsynapse/api/federation_router.py +108 -0
- contextsynapse/api/integrations.py +567 -0
- contextsynapse/api/integrations_router.py +461 -0
- contextsynapse/api/intelligence_router.py +1028 -0
- contextsynapse/api/metering.py +155 -0
- contextsynapse/api/metrics.py +112 -0
- contextsynapse/api/models.py +38 -0
- contextsynapse/api/monitoring_router.py +174 -0
- contextsynapse/api/pipeline_router.py +1437 -0
- contextsynapse/api/playground_conn.py +116 -0
- contextsynapse/api/projects_router.py +131 -0
- contextsynapse/api/queries_router.py +282 -0
- contextsynapse/api/quota.py +95 -0
- contextsynapse/api/rate_limit.py +64 -0
- contextsynapse/api/search_router.py +261 -0
- contextsynapse/api/shield_router.py +447 -0
- contextsynapse/api/tenant_guard.py +103 -0
- contextsynapse/api/tenant_quotas.py +231 -0
- contextsynapse/api/tenants.py +305 -0
- contextsynapse/api/users.py +646 -0
- contextsynapse/api/v1.py +167 -0
- contextsynapse/api/vertical_builder_router.py +387 -0
- contextsynapse/benchmark/__init__.py +15 -0
- contextsynapse/benchmark/__main__.py +64 -0
- contextsynapse/benchmark/agents.py +338 -0
- contextsynapse/benchmark/live_ab.py +338 -0
- contextsynapse/benchmark/reporter.py +149 -0
- contextsynapse/benchmark/runner.py +264 -0
- contextsynapse/benchmark/savings.py +266 -0
- contextsynapse/benchmark/token_counter.py +212 -0
- contextsynapse/benchmark/workloads.py +289 -0
- contextsynapse/buffer/__init__.py +154 -0
- contextsynapse/buffer/base.py +257 -0
- contextsynapse/buffer/duckdb_buffer.py +246 -0
- contextsynapse/buffer/file_buffer.py +229 -0
- contextsynapse/buffer/lmdb_buffer.py +286 -0
- contextsynapse/buffer/local_buffer.py +154 -0
- contextsynapse/buffer/redis_buffer.py +211 -0
- contextsynapse/buffer/sqlite_buffer.py +266 -0
- contextsynapse/cache.py +2 -0
- contextsynapse/cli/__init__.py +40 -0
- contextsynapse/cli/cli.py +475 -0
- contextsynapse/cli/config_cli.py +177 -0
- contextsynapse/cli/scaffold.py +465 -0
- contextsynapse/cognition/__init__.py +31 -0
- contextsynapse/cognition/derivation.py +55 -0
- contextsynapse/cognition/events.py +135 -0
- contextsynapse/cognition/feedback.py +52 -0
- contextsynapse/cognition/hallucination.py +90 -0
- contextsynapse/cognition/invalidation.py +70 -0
- contextsynapse/cognition/read_tracker.py +50 -0
- contextsynapse/collaboration.py +2 -0
- contextsynapse/comparison.py +2 -0
- contextsynapse/config/__init__.py +10 -0
- contextsynapse/config/connectors/amfi_nav.yaml +18 -0
- contextsynapse/config/connectors/auto_sector.yaml +20 -0
- contextsynapse/config/connectors/banking_sector.yaml +20 -0
- contextsynapse/config/connectors/energy_sector.yaml +20 -0
- contextsynapse/config/connectors/fmcg_sector.yaml +20 -0
- contextsynapse/config/connectors/nsdl_fpi.yaml +9 -0
- contextsynapse/config/connectors/nse_price.yaml +61 -0
- contextsynapse/config/connectors/pharma_sector.yaml +20 -0
- contextsynapse/config/connectors/rbi_dbie.yaml +12 -0
- contextsynapse/config/context_presets/ai_research.json +25 -0
- contextsynapse/config/context_presets/chatgpt_conversations.json +19 -0
- contextsynapse/config/context_presets/claude_conversations.json +19 -0
- contextsynapse/config/context_presets/legal_compliance.json +21 -0
- contextsynapse/config/context_presets/meeting_notes.json +21 -0
- contextsynapse/config/context_presets/slack_engineering.json +21 -0
- contextsynapse/config/context_presets/tech_climate.json +24 -0
- contextsynapse/config/context_presets/toi_politics.json +25 -0
- contextsynapse/config/database_config.py +453 -0
- contextsynapse/config/deployment.py +221 -0
- contextsynapse/config/gpt_action_schema.json +164 -0
- contextsynapse/config/indicators/india_macro.yaml +213 -0
- contextsynapse/config/logging_config.py +88 -0
- contextsynapse/config/mode_config.py +223 -0
- contextsynapse/config/schemas/api_spec.yaml +48 -0
- contextsynapse/config/schemas/architecture_doc.yaml +51 -0
- contextsynapse/config/schemas/chat_history.yaml +90 -0
- contextsynapse/config/schemas/chatgpt_conversation.yaml +101 -0
- contextsynapse/config/schemas/claude_conversation.yaml +148 -0
- contextsynapse/config/schemas/contract.yaml +48 -0
- contextsynapse/config/schemas/conversation.yaml +167 -0
- contextsynapse/config/schemas/database.yaml +74 -0
- contextsynapse/config/schemas/decision.yaml +72 -0
- contextsynapse/config/schemas/ecommerce.yaml +56 -0
- contextsynapse/config/schemas/education.yaml +42 -0
- contextsynapse/config/schemas/healthcare.yaml +133 -0
- contextsynapse/config/schemas/hr_document.yaml +48 -0
- contextsynapse/config/schemas/invoice.yaml +40 -0
- contextsynapse/config/schemas/knowledge_base.yaml +75 -0
- contextsynapse/config/schemas/legal.yaml +42 -0
- contextsynapse/config/schemas/marketing_content.yaml +48 -0
- contextsynapse/config/schemas/meeting_notes.yaml +51 -0
- contextsynapse/config/schemas/news_article.yaml +61 -0
- contextsynapse/config/schemas/real_estate.yaml +49 -0
- contextsynapse/config/schemas/requirements_doc.yaml +48 -0
- contextsynapse/config/schemas/research_paper.yaml +56 -0
- contextsynapse/config/schemas/resume.yaml +49 -0
- contextsynapse/config/schemas/retail.yaml +42 -0
- contextsynapse/config/schemas/rule_meta.yaml +173 -0
- contextsynapse/config/schemas/rules.yaml +72 -0
- contextsynapse/config/schemas/screener_meta.yaml +236 -0
- contextsynapse/config/schemas/sdlc.yaml +103 -0
- contextsynapse/config/schemas/session_graph.yaml +172 -0
- contextsynapse/config/schemas/support_ticket.yaml +48 -0
- contextsynapse/config/schemas/web.yaml +64 -0
- contextsynapse/config/sensors/earnings_calendar.yaml +52 -0
- contextsynapse/config/sensors/global_risk.yaml +53 -0
- contextsynapse/config/sensors/government_policy.yaml +54 -0
- contextsynapse/config/sensors/supply_chain.yaml +50 -0
- contextsynapse/config/sensors/templates/behavioral.yaml +56 -0
- contextsynapse/config/sensors/templates/equity_sentiment.yaml +48 -0
- contextsynapse/config/sensors/templates/global_macro.yaml +47 -0
- contextsynapse/config/sensors/templates/market_data.yaml +118 -0
- contextsynapse/config/sensors/templates/sector_technical.yaml +47 -0
- contextsynapse/config/sensors/weather.yaml +52 -0
- contextsynapse/config/storage_strategy.py +202 -0
- contextsynapse/config/templates/competitive_intel.yaml +39 -0
- contextsynapse/config/templates/geopolitical_risk.yaml +46 -0
- contextsynapse/config/templates/market_analysis.yaml +58 -0
- contextsynapse/connectors/__init__.py +15 -0
- contextsynapse/connectors/api_router.py +121 -0
- contextsynapse/connectors/base.py +357 -0
- contextsynapse/connectors/financial/audio.py +170 -0
- contextsynapse/connectors/financial/youtube.py +272 -0
- contextsynapse/connectors/github.py +164 -0
- contextsynapse/connectors/jira.py +120 -0
- contextsynapse/connectors/kafka_connector.py +124 -0
- contextsynapse/connectors/pipeline_connector.py +747 -0
- contextsynapse/connectors/registry.py +116 -0
- contextsynapse/connectors/scheduler.py +87 -0
- contextsynapse/connectors/universal.py +360 -0
- contextsynapse/context/__init__.py +96 -0
- contextsynapse/context/__main__.py +4 -0
- contextsynapse/context/acl.py +125 -0
- contextsynapse/context/agent_card.py +201 -0
- contextsynapse/context/agent_memory.py +814 -0
- contextsynapse/context/agents.py +472 -0
- contextsynapse/context/agents_redis.py +391 -0
- contextsynapse/context/assembled.py +204 -0
- contextsynapse/context/attribution.py +113 -0
- contextsynapse/context/blob.py +184 -0
- contextsynapse/context/boundaries.py +187 -0
- contextsynapse/context/boundary.py +507 -0
- contextsynapse/context/bundle.py +155 -0
- contextsynapse/context/cli.py +519 -0
- contextsynapse/context/collaboration.py +165 -0
- contextsynapse/context/compiler.py +604 -0
- contextsynapse/context/composite.py +536 -0
- contextsynapse/context/compression.py +147 -0
- contextsynapse/context/context_manager.py +888 -0
- contextsynapse/context/context_schema.py +90 -0
- contextsynapse/context/context_schema.yaml +105 -0
- contextsynapse/context/context_units.py +891 -0
- contextsynapse/context/conversation.py +488 -0
- contextsynapse/context/dedup.py +207 -0
- contextsynapse/context/document_processor.py +698 -0
- contextsynapse/context/embedding_hooks.py +338 -0
- contextsynapse/context/execution_schema.py +274 -0
- contextsynapse/context/fan_out.py +138 -0
- contextsynapse/context/frozen.py +80 -0
- contextsynapse/context/gravity.py +227 -0
- contextsynapse/context/hub.py +1401 -0
- contextsynapse/context/ingest.py +391 -0
- contextsynapse/context/injection.py +226 -0
- contextsynapse/context/interaction_graphifier.py +562 -0
- contextsynapse/context/layers.py +574 -0
- contextsynapse/context/projection.py +1195 -0
- contextsynapse/context/promotion.py +634 -0
- contextsynapse/context/proof.py +131 -0
- contextsynapse/context/propagation.py +577 -0
- contextsynapse/context/pubsub.py +135 -0
- contextsynapse/context/quality.py +1054 -0
- contextsynapse/context/quality_tracker.py +270 -0
- contextsynapse/context/scoping.py +370 -0
- contextsynapse/context/seed.py +992 -0
- contextsynapse/context/session.py +1142 -0
- contextsynapse/context/session_graph.py +593 -0
- contextsynapse/context/session_memory.py +309 -0
- contextsynapse/context/session_resolver.py +111 -0
- contextsynapse/context/skill_learning.py +237 -0
- contextsynapse/context/smart_budget.py +129 -0
- contextsynapse/context/source_policy.py +242 -0
- contextsynapse/context/store_factory.py +53 -0
- contextsynapse/context/sync.py +648 -0
- contextsynapse/context/token.py +236 -0
- contextsynapse/context/vector_integration.py +297 -0
- contextsynapse/context/webhooks.py +194 -0
- contextsynapse/context/working_memory.py +224 -0
- contextsynapse/core/__init__.py +18 -0
- contextsynapse/core/archiver.py +237 -0
- contextsynapse/core/change_stream.py +282 -0
- contextsynapse/core/checkpoint.py +310 -0
- contextsynapse/core/cloud_storage.py +387 -0
- contextsynapse/core/context_state.py +651 -0
- contextsynapse/core/cron.py +324 -0
- contextsynapse/core/datasource.py +643 -0
- contextsynapse/core/db.py +289 -0
- contextsynapse/core/federation.py +283 -0
- contextsynapse/core/graph_coordinator.py +201 -0
- contextsynapse/core/graph_intelligence.py +388 -0
- contextsynapse/core/graph_structures.py +106 -0
- contextsynapse/core/graph_sync.py +157 -0
- contextsynapse/core/hybrid_graph_storage.py +2998 -0
- contextsynapse/core/lifecycle.py +691 -0
- contextsynapse/core/multiworker.py +378 -0
- contextsynapse/core/pruning.py +312 -0
- contextsynapse/core/redis_registry.py +524 -0
- contextsynapse/core/registry.py +1043 -0
- contextsynapse/core/registry_factory.py +51 -0
- contextsynapse/core/registry_metadata.py +294 -0
- contextsynapse/core/replay.py +354 -0
- contextsynapse/core/replication.py +339 -0
- contextsynapse/core/time_travel.py +260 -0
- contextsynapse/core/write_behind.py +152 -0
- contextsynapse/core/write_context.py +39 -0
- contextsynapse/db/__init__.py +1 -0
- contextsynapse/db/postgres.py +267 -0
- contextsynapse/db/profile.py +236 -0
- contextsynapse/db/rules.py +328 -0
- contextsynapse/demo/__init__.py +0 -0
- contextsynapse/demo/report.py +147 -0
- contextsynapse/demo/runner.py +520 -0
- contextsynapse/demo/scenario.py +165 -0
- contextsynapse/demo/session_demo.py +280 -0
- contextsynapse/demo/session_report.py +143 -0
- contextsynapse/demo/universal_runner.py +257 -0
- contextsynapse/engine/__init__.py +15 -0
- contextsynapse/engine/core.py +555 -0
- contextsynapse/extraction/__init__.py +69 -0
- contextsynapse/extraction/cli.py +274 -0
- contextsynapse/extraction/config.py +107 -0
- contextsynapse/extraction/examples/example_usage.py +118 -0
- contextsynapse/extraction/examples/sample_manifest.json +53 -0
- contextsynapse/extraction/examples/sample_normalized.json +185 -0
- contextsynapse/extraction/extract_engine.py +440 -0
- contextsynapse/extraction/extractors/__init__.py +37 -0
- contextsynapse/extraction/extractors/chat_export_extractor.py +189 -0
- contextsynapse/extraction/extractors/csv_extractor.py +83 -0
- contextsynapse/extraction/extractors/docx_extractor.py +129 -0
- contextsynapse/extraction/extractors/excel_extractor.py +152 -0
- contextsynapse/extraction/extractors/html_extractor.py +146 -0
- contextsynapse/extraction/extractors/pdf_extractor.py +635 -0
- contextsynapse/extraction/extractors/pdf_extractor_layoutparser.py +408 -0
- contextsynapse/extraction/extractors/register_extractors.py +63 -0
- contextsynapse/extraction/extractors/text_extractor.py +65 -0
- contextsynapse/extraction/extractors/txt_extractor.py +120 -0
- contextsynapse/extraction/extractors/website_extractor.py +246 -0
- contextsynapse/extraction/fact_extractor.py +236 -0
- contextsynapse/extraction/file_manager.py +353 -0
- contextsynapse/extraction/hierarchy.py +239 -0
- contextsynapse/extraction/id_generator.py +450 -0
- contextsynapse/extraction/layout_detector.py +409 -0
- contextsynapse/extraction/llm_entity_extractor.py +301 -0
- contextsynapse/extraction/normalized_store.py +480 -0
- contextsynapse/extraction/normalizer.py +594 -0
- contextsynapse/extraction/parquet_writer.py +598 -0
- contextsynapse/extraction/post_processors/__init__.py +40 -0
- contextsynapse/extraction/post_processors/column_reorganizer.py +507 -0
- contextsynapse/extraction/ray_normalization.py +233 -0
- contextsynapse/extraction/ray_runner.py +207 -0
- contextsynapse/extraction/redis_schema_registry.py +222 -0
- contextsynapse/extraction/registry.py +204 -0
- contextsynapse/extraction/schema_loader.py +663 -0
- contextsynapse/extraction/schema_registry.py +230 -0
- contextsynapse/extraction/semantic_normalizer.py +245 -0
- contextsynapse/extraction/version_manager.py +314 -0
- contextsynapse/gateway/__init__.py +24 -0
- contextsynapse/gateway/action_emitter.py +212 -0
- contextsynapse/gateway/cost_tracker.py +508 -0
- contextsynapse/gateway/gateway.py +377 -0
- contextsynapse/gateway/policy.py +303 -0
- contextsynapse/governance/__init__.py +13 -0
- contextsynapse/governance/layer.py +513 -0
- contextsynapse/ingestion/__init__.py +15 -0
- contextsynapse/ingestion/amplifier.py +288 -0
- contextsynapse/ingestion/async_ingest.py +463 -0
- contextsynapse/ingestion/chunker.py +303 -0
- contextsynapse/ingestion/chunking.py +58 -0
- contextsynapse/ingestion/cleaner.py +190 -0
- contextsynapse/ingestion/cleanse.py +252 -0
- contextsynapse/ingestion/connectors/__init__.py +38 -0
- contextsynapse/ingestion/connectors/base.py +300 -0
- contextsynapse/ingestion/connectors/chatgpt_memory.py +247 -0
- contextsynapse/ingestion/connectors/claude_memory.py +274 -0
- contextsynapse/ingestion/connectors/sap_ingestor.py +208 -0
- contextsynapse/ingestion/content_detector.py +80 -0
- contextsynapse/ingestion/content_monitor.py +502 -0
- contextsynapse/ingestion/dedup.py +106 -0
- contextsynapse/ingestion/feed.py +640 -0
- contextsynapse/ingestion/filters.py +461 -0
- contextsynapse/ingestion/graph_builder.py +705 -0
- contextsynapse/ingestion/input_classifier.py +307 -0
- contextsynapse/ingestion/job_manager.py +571 -0
- contextsynapse/ingestion/llm_extractor.py +610 -0
- contextsynapse/ingestion/orchestrator.py +116 -0
- contextsynapse/ingestion/parsers/__init__.py +19 -0
- contextsynapse/ingestion/parsers/graph_parser_registry.py +103 -0
- contextsynapse/ingestion/parsers/graphml_parser.py +141 -0
- contextsynapse/ingestion/parsers/jsonld_parser.py +171 -0
- contextsynapse/ingestion/parsers/rdf_parser.py +150 -0
- contextsynapse/ingestion/pipeline_context.py +228 -0
- contextsynapse/ingestion/pipeline_store.py +1195 -0
- contextsynapse/ingestion/queue.py +133 -0
- contextsynapse/ingestion/reprocess.py +179 -0
- contextsynapse/ingestion/scenario_router.py +224 -0
- contextsynapse/ingestion/schema_extractor.py +759 -0
- contextsynapse/ingestion/schema_validator.py +274 -0
- contextsynapse/ingestion/sdlc_ingest.py +87 -0
- contextsynapse/ingestion/smart_ingest.py +2451 -0
- contextsynapse/ingestion/source_connector.py +171 -0
- contextsynapse/ingestion/stage_executor.py +2095 -0
- contextsynapse/ingestion/stages/__init__.py +9 -0
- contextsynapse/ingestion/stages/tabular_to_graph.py +289 -0
- contextsynapse/ingestion/strategies.py +386 -0
- contextsynapse/ingestion/universal/__init__.py +4 -0
- contextsynapse/ingestion/universal/_operator_registry.py +59 -0
- contextsynapse/ingestion/universal/ingest_content.py +32 -0
- contextsynapse/ingestion/universal/operators/__init__.py +1 -0
- contextsynapse/ingestion/universal/operators/base.py +19 -0
- contextsynapse/ingestion/universal/operators/build_edges.py +75 -0
- contextsynapse/ingestion/universal/operators/cluster_topics.py +397 -0
- contextsynapse/ingestion/universal/operators/deduplicate.py +45 -0
- contextsynapse/ingestion/universal/operators/detect_signals.py +90 -0
- contextsynapse/ingestion/universal/operators/embed.py +80 -0
- contextsynapse/ingestion/universal/operators/extract_entities.py +253 -0
- contextsynapse/ingestion/universal/operators/extract_preferences.py +117 -0
- contextsynapse/ingestion/universal/operators/filter_content.py +69 -0
- contextsynapse/ingestion/universal/operators/index_bm25.py +52 -0
- contextsynapse/ingestion/universal/operators/infer_domains.py +69 -0
- contextsynapse/ingestion/universal/operators/link_cross_reference.py +210 -0
- contextsynapse/ingestion/universal/operators/parse_records.py +66 -0
- contextsynapse/ingestion/universal/operators/resolve_entities.py +261 -0
- contextsynapse/ingestion/universal/operators/scanners/__init__.py +16 -0
- contextsynapse/ingestion/universal/operators/scanners/edges.py +173 -0
- contextsynapse/ingestion/universal/operators/scanners/git.py +187 -0
- contextsynapse/ingestion/universal/operators/scanners/github.py +135 -0
- contextsynapse/ingestion/universal/operators/scanners/github_api.py +509 -0
- contextsynapse/ingestion/universal/operators/scanners/helpers.py +67 -0
- contextsynapse/ingestion/universal/operators/scanners/jira.py +65 -0
- contextsynapse/ingestion/universal/operators/scanners/llm_enrichment.py +82 -0
- contextsynapse/ingestion/universal/operators/scanners/repo.py +149 -0
- contextsynapse/ingestion/universal/operators/sdlc_scan.py +213 -0
- contextsynapse/ingestion/universal/operators/spec_scanner.py +149 -0
- contextsynapse/ingestion/universal/operators/store_documents.py +72 -0
- contextsynapse/ingestion/universal/operators/synthesize_cu.py +180 -0
- contextsynapse/ingestion/universal/operators/validate_gate.py +65 -0
- contextsynapse/ingestion/universal/parsers/__init__.py +5 -0
- contextsynapse/ingestion/universal/parsers/record_parser.py +203 -0
- contextsynapse/ingestion/universal/parsers/turn_parser.py +329 -0
- contextsynapse/ingestion/universal/shared_signals.py +161 -0
- contextsynapse/ingestion/universal/stage_executor.py +219 -0
- contextsynapse/ingestion/web_crawler.py +265 -0
- contextsynapse/intelligence/__init__.py +53 -0
- contextsynapse/intelligence/alerts.py +198 -0
- contextsynapse/intelligence/collector.py +655 -0
- contextsynapse/intelligence/comparison.py +198 -0
- contextsynapse/intelligence/config.py +56 -0
- contextsynapse/intelligence/conflict_detector.py +182 -0
- contextsynapse/intelligence/context_gaps.py +192 -0
- contextsynapse/intelligence/context_radar.py +135 -0
- contextsynapse/intelligence/correlation_engine.py +416 -0
- contextsynapse/intelligence/correlation_template.py +120 -0
- contextsynapse/intelligence/dedup.py +296 -0
- contextsynapse/intelligence/event_bus.py +91 -0
- contextsynapse/intelligence/feedback_loop.py +101 -0
- contextsynapse/intelligence/freshness.py +307 -0
- contextsynapse/intelligence/fundamental_feed.py +551 -0
- contextsynapse/intelligence/geo_data.py +170 -0
- contextsynapse/intelligence/geo_reference.py +112 -0
- contextsynapse/intelligence/graph_fusion.py +465 -0
- contextsynapse/intelligence/heuristics.py +176 -0
- contextsynapse/intelligence/impact_tracker.py +336 -0
- contextsynapse/intelligence/macro_indicators.py +319 -0
- contextsynapse/intelligence/ocr.py +104 -0
- contextsynapse/intelligence/persistence.py +267 -0
- contextsynapse/intelligence/pipeline_health.py +130 -0
- contextsynapse/intelligence/price_feed.py +221 -0
- contextsynapse/intelligence/rate_limiter.py +130 -0
- contextsynapse/intelligence/reactive.py +411 -0
- contextsynapse/intelligence/runtime_context.py +390 -0
- contextsynapse/intelligence/sentiment_decay.py +426 -0
- contextsynapse/intelligence/session.py +277 -0
- contextsynapse/intelligence/signal_hierarchy.py +438 -0
- contextsynapse/intelligence/signals.py +185 -0
- contextsynapse/intelligence/source_watcher.py +132 -0
- contextsynapse/intelligence/table_enricher.py +256 -0
- contextsynapse/intelligence/tagger.py +319 -0
- contextsynapse/intelligence/timeseries.py +209 -0
- contextsynapse/intelligence/tracker.py +318 -0
- contextsynapse/intelligence/watchdog.py +392 -0
- contextsynapse/intelligence/watchdog_manager.py +263 -0
- contextsynapse/intelligence/webhook_receiver.py +165 -0
- contextsynapse/intelligence/weight_learner.py +234 -0
- contextsynapse/llm/__init__.py +8 -0
- contextsynapse/llm/client.py +348 -0
- contextsynapse/llm/rate_limiter.py +166 -0
- contextsynapse/logging_config.py +2 -0
- contextsynapse/marketplace/__init__.py +7 -0
- contextsynapse/marketplace/registry.py +173 -0
- contextsynapse/mcp/__init__.py +11 -0
- contextsynapse/mcp/__main__.py +4 -0
- contextsynapse/mcp/auth_middleware.py +212 -0
- contextsynapse/mcp/connection_pool.py +128 -0
- contextsynapse/mcp/server.py +986 -0
- contextsynapse/mcp/session_context.py +67 -0
- contextsynapse/memory/__init__.py +34 -0
- contextsynapse/memory/engine.py +475 -0
- contextsynapse/memory/temporal.py +327 -0
- contextsynapse/metadata/__init__.py +12 -0
- contextsynapse/metadata/metadata_db.py +272 -0
- contextsynapse/metadata/metadata_query_tool.py +300 -0
- contextsynapse/metadata/metadata_tracker.py +425 -0
- contextsynapse/models/__init__.py +27 -0
- contextsynapse/models/embedding_service.py +360 -0
- contextsynapse/models/model_registry.py +228 -0
- contextsynapse/multiworker.py +2 -0
- contextsynapse/pipelines/__init__.py +1 -0
- contextsynapse/pipelines/executor.py +851 -0
- contextsynapse/pipelines/filters.py +189 -0
- contextsynapse/pipelines/models.py +176 -0
- contextsynapse/pipelines/scheduler.py +268 -0
- contextsynapse/playground/__init__.py +1 -0
- contextsynapse/playground/templates.py +85 -0
- contextsynapse/plugins/__init__.py +43 -0
- contextsynapse/plugins/api.py +66 -0
- contextsynapse/plugins/base.py +350 -0
- contextsynapse/plugins/domain_interface.py +508 -0
- contextsynapse/plugins/domain_loader.py +241 -0
- contextsynapse/plugins/loader.py +148 -0
- contextsynapse/plugins/registry.py +265 -0
- contextsynapse/project/__init__.py +11 -0
- contextsynapse/project/code_context.py +807 -0
- contextsynapse/project/connectors/__init__.py +4 -0
- contextsynapse/project/connectors/github_connector.py +113 -0
- contextsynapse/project/connectors/jira_connector.py +160 -0
- contextsynapse/project/graph.py +1023 -0
- contextsynapse/project/project_context.py +545 -0
- contextsynapse/project/scanner_registry.py +61 -0
- contextsynapse/project/schema_manager.py +322 -0
- contextsynapse/project/schemas/knowledge.yaml +59 -0
- contextsynapse/project/schemas/sdlc.yaml +369 -0
- contextsynapse/project/sdlc_schema.py +172 -0
- contextsynapse/project/spec_parser.py +85 -0
- contextsynapse/project/task_lock.py +181 -0
- contextsynapse/project/task_stream.py +203 -0
- contextsynapse/project/team_tools.py +537 -0
- contextsynapse/py.typed +0 -0
- contextsynapse/realtime/__init__.py +6 -0
- contextsynapse/realtime/collaboration.py +147 -0
- contextsynapse/rules/__init__.py +10 -0
- contextsynapse/rules/engine.py +116 -0
- contextsynapse/rules/evaluators/__init__.py +6 -0
- contextsynapse/rules/evaluators/aggregate.py +205 -0
- contextsynapse/rules/evaluators/custom.py +170 -0
- contextsynapse/rules/evaluators/pre_action.py +125 -0
- contextsynapse/rules/evaluators/temporal.py +129 -0
- contextsynapse/rules/loader.py +52 -0
- contextsynapse/rules/models.py +124 -0
- contextsynapse/rules/universal.py +393 -0
- contextsynapse/scheduler.py +229 -0
- contextsynapse/schema/__init__.py +42 -0
- contextsynapse/schema/compiler.py +252 -0
- contextsynapse/schema/composer.py +158 -0
- contextsynapse/schema/dedup.py +73 -0
- contextsynapse/schema/derivation.py +172 -0
- contextsynapse/schema/sdl.py +326 -0
- contextsynapse/schema/validation_gate.py +124 -0
- contextsynapse/sdk/__init__.py +63 -0
- contextsynapse/sdk/agent.py +214 -0
- contextsynapse/sdk/client.py +269 -0
- contextsynapse/sdk/exceptions.py +23 -0
- contextsynapse/sdk/models.py +78 -0
- contextsynapse/sdk/session.py +408 -0
- contextsynapse/sdk/tracked.py +218 -0
- contextsynapse/sdk/worker.py +266 -0
- contextsynapse/sdk/workspace_client.py +98 -0
- contextsynapse/sdk/ws.py +41 -0
- contextsynapse/search/__init__.py +20 -0
- contextsynapse/search/embedding_cache.py +140 -0
- contextsynapse/search/enhanced_search.py +152 -0
- contextsynapse/search/fulltext.py +130 -0
- contextsynapse/search/graph_search.py +634 -0
- contextsynapse/search/lmdb_index.py +1218 -0
- contextsynapse/search/nl_to_aiql.py +199 -0
- contextsynapse/search/rag.py +1346 -0
- contextsynapse/search/rag_cache.py +167 -0
- contextsynapse/search/reasoning_chain.py +231 -0
- contextsynapse/search/redis_search.py +207 -0
- contextsynapse/search/retrieval_quality.py +314 -0
- contextsynapse/search/semantic_query.py +455 -0
- contextsynapse/search/text_resolver.py +159 -0
- contextsynapse/search/whoosh_search.py +373 -0
- contextsynapse/security/__init__.py +17 -0
- contextsynapse/security/audit.py +297 -0
- contextsynapse/security/audit_logger.py +97 -0
- contextsynapse/security/audit_trail.py +270 -0
- contextsynapse/security/auth_unified.py +284 -0
- contextsynapse/security/auto_tagger.py +230 -0
- contextsynapse/security/data_security.py +218 -0
- contextsynapse/security/encryption.py +207 -0
- contextsynapse/security/identity.py +447 -0
- contextsynapse/security/jwt_identity.py +59 -0
- contextsynapse/security/middleware.py +336 -0
- contextsynapse/security/pii.py +233 -0
- contextsynapse/security/rbac.py +96 -0
- contextsynapse/security/rls.py +205 -0
- contextsynapse/security/sanitize.py +233 -0
- contextsynapse/security/scoped_encryption.py +131 -0
- contextsynapse/security/tenant.py +401 -0
- contextsynapse/shield/__init__.py +21 -0
- contextsynapse/shield/anomaly.py +56 -0
- contextsynapse/shield/permissions.py +99 -0
- contextsynapse/shield/profile.py +103 -0
- contextsynapse/shield/shield.py +108 -0
- contextsynapse/shield/trust_engine.py +69 -0
- contextsynapse/skills/__init__.py +14 -0
- contextsynapse/skills/engine.py +233 -0
- contextsynapse/skills/loader.py +59 -0
- contextsynapse/skills/models.py +139 -0
- contextsynapse/storage/__init__.py +7 -0
- contextsynapse/storage/cache.py +208 -0
- contextsynapse/storage/columnar_store_v2.py +178 -0
- contextsynapse/storage/csr_graph_storage.py +587 -0
- contextsynapse/storage/csr_store.py +388 -0
- contextsynapse/storage/document_store.py +491 -0
- contextsynapse/storage/hnsw_index.py +294 -0
- contextsynapse/storage/hybrid_store_v2.py +278 -0
- contextsynapse/storage/lmdb_graph_storage.py +366 -0
- contextsynapse/storage/migration.py +279 -0
- contextsynapse/storage/namespace_store.py +346 -0
- contextsynapse/storage/pure_graph_storage.py +185 -0
- contextsynapse/storage/redis_graph_adapter.py +186 -0
- contextsynapse/storage/redis_graph_storage.py +375 -0
- contextsynapse/storage/router/__init__.py +29 -0
- contextsynapse/storage/router/duckdb_store.py +398 -0
- contextsynapse/storage/router/factory.py +83 -0
- contextsynapse/storage/router/interface.py +125 -0
- contextsynapse/storage/router/postgres_store.py +339 -0
- contextsynapse/storage/router/resolver.py +192 -0
- contextsynapse/storage/router/router.py +300 -0
- contextsynapse/storage/single_file_storage.py +391 -0
- contextsynapse/storage/storage_manager.py +214 -0
- contextsynapse/storage/storage_query_optimizer.py +314 -0
- contextsynapse/storage/wal.py +359 -0
- contextsynapse/temporal/__init__.py +0 -0
- contextsynapse/temporal/storage.py +106 -0
- contextsynapse/tests/__init__.py +11 -0
- contextsynapse/tests/regression/__init__.py +1 -0
- contextsynapse/tests/regression/add_metadata.py +395 -0
- contextsynapse/tests/regression/add_skip_flags.py +85 -0
- contextsynapse/tests/regression/cases/test_basic_create_node.yaml +20 -0
- contextsynapse/tests/regression/cases/test_basic_select.yaml +21 -0
- contextsynapse/tests/regression/cases/test_blockchain_audit_trail.yaml +37 -0
- contextsynapse/tests/regression/cases/test_blockchain_audit_trail_filtered.yaml +39 -0
- contextsynapse/tests/regression/cases/test_blockchain_blocks_range.yaml +39 -0
- contextsynapse/tests/regression/cases/test_blockchain_get_block.yaml +35 -0
- contextsynapse/tests/regression/cases/test_blockchain_latest_block.yaml +35 -0
- contextsynapse/tests/regression/cases/test_blockchain_length.yaml +37 -0
- contextsynapse/tests/regression/cases/test_blockchain_merkle_root.yaml +37 -0
- contextsynapse/tests/regression/cases/test_blockchain_verify.yaml +35 -0
- contextsynapse/tests/regression/cases/test_blockchain_verify_block.yaml +35 -0
- contextsynapse/tests/regression/cases/test_create_edge.yaml +28 -0
- contextsynapse/tests/regression/cases/test_delete_edge_basic.yaml +29 -0
- contextsynapse/tests/regression/cases/test_delete_node_basic.yaml +29 -0
- contextsynapse/tests/regression/cases/test_evaluation_mrr.yaml +40 -0
- contextsynapse/tests/regression/cases/test_evaluation_ndcg.yaml +40 -0
- contextsynapse/tests/regression/cases/test_evaluation_precision.yaml +40 -0
- contextsynapse/tests/regression/cases/test_evaluation_recall.yaml +40 -0
- contextsynapse/tests/regression/cases/test_group_by_basic.yaml +56 -0
- contextsynapse/tests/regression/cases/test_match_node_basic.yaml +29 -0
- contextsynapse/tests/regression/cases/test_match_node_with_order_limit.yaml +31 -0
- contextsynapse/tests/regression/cases/test_namespace_switch.yaml +18 -0
- contextsynapse/tests/regression/cases/test_pipeline_cascaded.yaml +61 -0
- contextsynapse/tests/regression/cases/test_pipeline_fixed_size_chunking.yaml +48 -0
- contextsynapse/tests/regression/cases/test_pipeline_gpt4_chunking.yaml +54 -0
- contextsynapse/tests/regression/cases/test_pipeline_hybrid_indexing.yaml +57 -0
- contextsynapse/tests/regression/cases/test_pipeline_large_embedding.yaml +52 -0
- contextsynapse/tests/regression/cases/test_pipeline_paragraph_chunking.yaml +49 -0
- contextsynapse/tests/regression/cases/test_pipeline_recursive_chunking.yaml +47 -0
- contextsynapse/tests/regression/cases/test_pipeline_run_pipeline.yaml +56 -0
- contextsynapse/tests/regression/cases/test_pipeline_section_based_chunking.yaml +53 -0
- contextsynapse/tests/regression/cases/test_pipeline_semantic_chunking.yaml +51 -0
- contextsynapse/tests/regression/cases/test_pipeline_with_entity_extraction.yaml +57 -0
- contextsynapse/tests/regression/cases/test_pipeline_with_relationships.yaml +62 -0
- contextsynapse/tests/regression/cases/test_rag_evaluation.yaml +38 -0
- contextsynapse/tests/regression/cases/test_rag_graph_bfs_with_eval.yaml +48 -0
- contextsynapse/tests/regression/cases/test_rag_graph_centrality.yaml +40 -0
- contextsynapse/tests/regression/cases/test_rag_graph_centrality_eval.yaml +35 -0
- contextsynapse/tests/regression/cases/test_rag_graph_community.yaml +40 -0
- contextsynapse/tests/regression/cases/test_rag_graph_community_eval.yaml +35 -0
- contextsynapse/tests/regression/cases/test_rag_graph_dfs_with_eval.yaml +35 -0
- contextsynapse/tests/regression/cases/test_rag_graph_multi_hop_eval.yaml +35 -0
- contextsynapse/tests/regression/cases/test_rag_graph_path.yaml +40 -0
- contextsynapse/tests/regression/cases/test_rag_graph_search_basic.yaml +38 -0
- contextsynapse/tests/regression/cases/test_rag_graph_search_bfs.yaml +52 -0
- contextsynapse/tests/regression/cases/test_rag_graph_search_dfs.yaml +41 -0
- contextsynapse/tests/regression/cases/test_rag_graph_search_multi_hop.yaml +43 -0
- contextsynapse/tests/regression/cases/test_rag_graph_search_shortest_path.yaml +41 -0
- contextsynapse/tests/regression/cases/test_rag_graph_search_weighted.yaml +43 -0
- contextsynapse/tests/regression/cases/test_rag_graph_shortest_path_eval.yaml +35 -0
- contextsynapse/tests/regression/cases/test_rag_graph_traversal.yaml +30 -0
- contextsynapse/tests/regression/cases/test_rag_graph_weighted_eval.yaml +35 -0
- contextsynapse/tests/regression/cases/test_rag_hybrid_search.yaml +33 -0
- contextsynapse/tests/regression/cases/test_rag_hybrid_with_prompt_embedding.yaml +44 -0
- contextsynapse/tests/regression/cases/test_rag_keyword_search.yaml +32 -0
- contextsynapse/tests/regression/cases/test_rag_multi_hop_graph.yaml +32 -0
- contextsynapse/tests/regression/cases/test_rag_path_based.yaml +34 -0
- contextsynapse/tests/regression/cases/test_rag_profile_based.yaml +32 -0
- contextsynapse/tests/regression/cases/test_rag_vector_search.yaml +32 -0
- contextsynapse/tests/regression/cases/test_rag_weighted_graph.yaml +34 -0
- contextsynapse/tests/regression/cases/test_rag_weighted_hybrid.yaml +31 -0
- contextsynapse/tests/regression/cases/test_semantic_boundary_chunking.yaml +57 -0
- contextsynapse/tests/regression/cases/test_semantic_boundary_detection.yaml +33 -0
- contextsynapse/tests/regression/cases/test_semantic_hash_function.yaml +30 -0
- contextsynapse/tests/regression/cases/test_semantic_hash_with_model.yaml +31 -0
- contextsynapse/tests/regression/cases/test_tcs_ingestion_fixed_size.yaml +44 -0
- contextsynapse/tests/regression/cases/test_tcs_ingestion_recursive.yaml +46 -0
- contextsynapse/tests/regression/cases/test_tcs_ingestion_section.yaml +46 -0
- contextsynapse/tests/regression/cases/test_tcs_ingestion_semantic.yaml +44 -0
- contextsynapse/tests/regression/cases/test_time_travel_as_of.yaml +35 -0
- contextsynapse/tests/regression/cases/test_time_travel_at_commit.yaml +33 -0
- contextsynapse/tests/regression/cases/test_time_travel_at_timestamp.yaml +33 -0
- contextsynapse/tests/regression/cases/test_time_travel_for_system_time_all.yaml +37 -0
- contextsynapse/tests/regression/cases/test_time_travel_versions_between.yaml +39 -0
- contextsynapse/tests/regression/cases/test_traverse_basic.yaml +31 -0
- contextsynapse/tests/regression/cases/test_traverse_max_depth.yaml +34 -0
- contextsynapse/tests/regression/cases/test_update_edge_basic.yaml +29 -0
- contextsynapse/tests/regression/evaluation_metrics.py +227 -0
- contextsynapse/tests/regression/regression_runner.py +1081 -0
- contextsynapse/tests/regression/setup_regression_data.py +212 -0
- contextsynapse/tests/regression/test_basic_only.py +84 -0
- contextsynapse/tests/regression/test_namespace_creation.py +29 -0
- contextsynapse/tests/regression/test_single_fix.py +61 -0
- contextsynapse/tests/regression/test_single_query.py +20 -0
- contextsynapse/tests/regression/validate_test_syntax.py +179 -0
- contextsynapse/tests/test_advanced_features.py +347 -0
- contextsynapse/tests/test_aiql_summary.py +283 -0
- contextsynapse/tests/test_all_aiql_queries.py +948 -0
- contextsynapse/tests/test_all_create_queries.py +213 -0
- contextsynapse/tests/test_api_vs_native.py +280 -0
- contextsynapse/tests/test_chunking_dedup.py +199 -0
- contextsynapse/tests/test_connectors.py +171 -0
- contextsynapse/tests/test_edges_and_match.py +202 -0
- contextsynapse/tests/test_extraction_pipeline_integration.py +581 -0
- contextsynapse/tests/test_name_property.py +224 -0
- contextsynapse/tests/test_node_edge_metadata.py +250 -0
- contextsynapse/tests/test_playground_conn.py +114 -0
- contextsynapse/tests/test_query_cache.py +213 -0
- contextsynapse/tests/test_source_policy_auth.py +348 -0
- contextsynapse/tests/test_temporal_and_domain.py +224 -0
- contextsynapse/tests/test_time_travel_e2e.py +571 -0
- contextsynapse/tests/test_traversal_and_aggregation.py +275 -0
- contextsynapse/tools/__init__.py +36 -0
- contextsynapse/tools/a2a_tools.py +106 -0
- contextsynapse/tools/cognition_tools.py +118 -0
- contextsynapse/tools/context.py +905 -0
- contextsynapse/tools/formatting.py +92 -0
- contextsynapse/tools/gateway_tools.py +186 -0
- contextsynapse/tools/graph.py +1700 -0
- contextsynapse/tools/intelligence.py +235 -0
- contextsynapse/tools/memory.py +118 -0
- contextsynapse/tools/registry.py +373 -0
- contextsynapse/tools/shield_tools.py +159 -0
- contextsynapse/tools/tasks.py +341 -0
- contextsynapse/tools/workspace_tools.py +124 -0
- contextsynapse/utils/__init__.py +15 -0
- contextsynapse/utils/config_loader.py +198 -0
- contextsynapse/utils/env_loader.py +156 -0
- contextsynapse/utils/file_utils.py +288 -0
- contextsynapse/utils/logging_optimizer.py +119 -0
- contextsynapse/vector/__init__.py +30 -0
- contextsynapse/vector/chroma_vector_store.py +152 -0
- contextsynapse/vector/custom_vector_store.py +537 -0
- contextsynapse/vector/faiss_vector_store.py +296 -0
- contextsynapse/vector/qdrant_vector_store.py +163 -0
- contextsynapse/vector/vector_db.py +953 -0
- contextsynapse/vector/vector_db_manager.py +197 -0
- contextsynapse/workspace/__init__.py +27 -0
- contextsynapse/workspace/base.py +94 -0
- contextsynapse/workspace/git.py +228 -0
- contextsynapse/workspace/github.py +78 -0
- contextsynapse/workspace/local.py +73 -0
- contextsynapse/workspace/tools.py +222 -0
- contextsynapse-1.0.0.dist-info/METADATA +847 -0
- contextsynapse-1.0.0.dist-info/RECORD +776 -0
- contextsynapse-1.0.0.dist-info/WHEEL +5 -0
- contextsynapse-1.0.0.dist-info/entry_points.txt +4 -0
- contextsynapse-1.0.0.dist-info/licenses/LICENSE +200 -0
- contextsynapse-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1195 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pipeline Store
|
|
3
|
+
==============
|
|
4
|
+
Stored-procedure-style pipeline definitions with metadata, run tracking,
|
|
5
|
+
governance tagging, and extraction accuracy scoring.
|
|
6
|
+
|
|
7
|
+
Pipelines are parameterized AIQL templates that can be:
|
|
8
|
+
- Created, versioned, and shared across tenants
|
|
9
|
+
- Executed with runtime parameters
|
|
10
|
+
- Tracked per-run with stage-level metrics
|
|
11
|
+
- Scored for extraction accuracy
|
|
12
|
+
- Tagged for data governance and lineage
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import logging
|
|
19
|
+
import secrets
|
|
20
|
+
import sqlite3
|
|
21
|
+
import time
|
|
22
|
+
from dataclasses import dataclass, field, asdict
|
|
23
|
+
from datetime import datetime, timezone
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Any, Dict, List, Optional
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
# Data models
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
# Stage-level explanations (shared across pipelines)
|
|
34
|
+
STAGE_EXPLANATIONS = {
|
|
35
|
+
"PARSE_FILE": "Reads the uploaded file (PDF, DOCX, Excel, CSV, etc.) and extracts raw content — text, tables, images.",
|
|
36
|
+
"CLASSIFY": "Auto-detects the file structure: Is it a document? A spreadsheet with rows? A table with source/target columns? Picks the right processing path.",
|
|
37
|
+
"CHUNK": "Splits long text into smaller pieces (chunks) so each piece fits in an LLM context window. Methods: paragraph (split by ¶), semantic (split at sentence boundaries), fixed (split every N chars).",
|
|
38
|
+
"EXTRACT": "Sends each chunk to an LLM to extract named entities (people, systems, concepts) and relationships between them. Creates graph nodes and edges.",
|
|
39
|
+
"EXTRACT_FACTS": "Sends each chunk to an LLM to extract factual statements — things the document states as true. Each fact becomes a Fact node in the graph.",
|
|
40
|
+
"EXTRACT_ENTITIES": "Same as EXTRACT — extracts entities and relationships using LLM.",
|
|
41
|
+
"EXTRACT_ENTITIES_AND_RELATIONSHIPS": "Extracts both entities AND their relationships in a single LLM pass. More comprehensive than separate extraction.",
|
|
42
|
+
"EMBED": "Generates vector embeddings for each chunk using an embedding model (e.g. nomic-embed-text). Enables semantic/similarity search later.",
|
|
43
|
+
"INDEX_BM25": "Builds a full-text search index (BM25/Whoosh) for keyword-based retrieval. Enables fast text search without vectors.",
|
|
44
|
+
"STORE_VECTORS": "Stores the generated embeddings in the vector database (FAISS, Qdrant, or NumPy). Makes chunks searchable by meaning.",
|
|
45
|
+
"MAP_TABULAR": "Converts spreadsheet data into graph nodes and edges. Detects column roles: source/target → edges, IDs → node keys, foreign keys → relationships.",
|
|
46
|
+
"CANONICALIZE": "Deduplicates entities — 'John Smith' and 'J. Smith' merged into one node. Uses name similarity and LLM disambiguation.",
|
|
47
|
+
"ENHANCE_GRAPH": "Adds inferred edges: co-occurrence links between entities mentioned together, hierarchical relationships, and cross-document connections.",
|
|
48
|
+
"PERSIST": "Saves all created nodes and edges to the graph database (CSR storage + HDF5). Makes data queryable.",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
BUILTIN_PIPELINES = [
|
|
52
|
+
{
|
|
53
|
+
"id": "builtin:smart",
|
|
54
|
+
"name": "Smart Pipeline",
|
|
55
|
+
"description": "Default pipeline for all content. Auto-detects input type and applies the right schema.",
|
|
56
|
+
"explanation": "**What it does:** Auto-detects your content (articles, chat exports, documents, code) and applies the appropriate extraction schema. Chunks text, extracts entities/facts/relationships with LLM, generates embeddings, builds search indexes, and clusters into Context Units.\n\n**When to use:** Always. This is the recommended pipeline for everything — news, PDFs, chat history ZIPs, code files.\n\n**Accepts:** PDF, DOCX, TXT, HTML, CSV, JSON, ZIP (ChatGPT/Claude/Gemini exports)\n\n**Result:** Rich knowledge graph with entities, facts, relationships, semantic search, and Context Units.",
|
|
57
|
+
"version": 1,
|
|
58
|
+
"category": "ingestion",
|
|
59
|
+
"schema_name": "",
|
|
60
|
+
"parser": "",
|
|
61
|
+
"filters": {},
|
|
62
|
+
"graph_config": {},
|
|
63
|
+
"_smart_pipeline": True,
|
|
64
|
+
"stages": [
|
|
65
|
+
{"name": "parse", "type": "PARSE_FILE", "config": {}},
|
|
66
|
+
{"name": "classify", "type": "CLASSIFY", "config": {}},
|
|
67
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "semantic", "max_size": 1500}},
|
|
68
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
69
|
+
{"name": "extract", "type": "EXTRACT", "config": {}},
|
|
70
|
+
{"name": "canonicalize", "type": "CANONICALIZE", "config": {}},
|
|
71
|
+
{"name": "index", "type": "INDEX_BM25", "config": {}},
|
|
72
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
73
|
+
],
|
|
74
|
+
"default_params": {
|
|
75
|
+
"chunk_method": "semantic",
|
|
76
|
+
"chunk_size": 1500,
|
|
77
|
+
"llm_model": "groq:gpt-oss-120b",
|
|
78
|
+
"embedding_model": "nomic-embed-text",
|
|
79
|
+
},
|
|
80
|
+
"aiql_template": "",
|
|
81
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
82
|
+
"tags": ["recommended", "auto", "smart", "default"],
|
|
83
|
+
"builtin": True,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"id": "builtin:basic",
|
|
87
|
+
"name": "Basic Chunking",
|
|
88
|
+
"description": "Split text into chunks. No LLM, no embeddings. Fast and free.",
|
|
89
|
+
"explanation": "**What it does:** Takes your text and splits it into paragraph-sized chunks (~2000 chars each). Each chunk becomes a TextChunk node in the graph.\n\n**When to use:** Quick ingestion when you just want searchable text. No AI processing — instant and free.\n\n**Result:** Document → TextChunk nodes (keyword-searchable only, no semantic search).",
|
|
90
|
+
"version": 1,
|
|
91
|
+
"category": "ingestion",
|
|
92
|
+
"schema_name": "",
|
|
93
|
+
"parser": "",
|
|
94
|
+
"filters": {},
|
|
95
|
+
"graph_config": {},
|
|
96
|
+
"stages": [
|
|
97
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "paragraph", "max_size": 2000}},
|
|
98
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
99
|
+
],
|
|
100
|
+
"default_params": {"chunk_method": "paragraph", "chunk_size": 2000},
|
|
101
|
+
"aiql_template": (
|
|
102
|
+
'USE GRAPH {{graph}}\n'
|
|
103
|
+
'INGEST TEXT {{source}} CHUNK BY {{chunk_method}}'
|
|
104
|
+
),
|
|
105
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
106
|
+
"tags": ["basic", "no-llm", "fast"],
|
|
107
|
+
"builtin": True,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"id": "builtin:semantic",
|
|
111
|
+
"name": "Semantic Search Ready",
|
|
112
|
+
"description": "Chunk text and generate embeddings for vector search. No entity extraction.",
|
|
113
|
+
"explanation": "**What it does:** Splits text into smart chunks (at sentence boundaries), then generates vector embeddings for each chunk using an embedding model.\n\n**When to use:** You want to search by meaning ('find content about authentication') not just keywords. No entity extraction — just text chunks with vectors.\n\n**Result:** Document → TextChunk nodes with embeddings (semantic search + keyword search).",
|
|
114
|
+
"version": 1,
|
|
115
|
+
"category": "ingestion",
|
|
116
|
+
"schema_name": "",
|
|
117
|
+
"parser": "",
|
|
118
|
+
"filters": {},
|
|
119
|
+
"graph_config": {},
|
|
120
|
+
"stages": [
|
|
121
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "semantic", "max_size": 1500}},
|
|
122
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
123
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
124
|
+
],
|
|
125
|
+
"default_params": {"chunk_method": "semantic", "chunk_size": 1500, "embedding_model": "nomic-embed-text"},
|
|
126
|
+
"aiql_template": (
|
|
127
|
+
'USE GRAPH {{graph}}\n'
|
|
128
|
+
'INGEST TEXT {{source}} CHUNK BY {{chunk_method}}\n'
|
|
129
|
+
'THEN EMBED USING MODEL "{{embedding_model}}"'
|
|
130
|
+
),
|
|
131
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
132
|
+
"tags": ["embeddings", "vector-search", "no-llm"],
|
|
133
|
+
"builtin": True,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"id": "builtin:knowledge-graph",
|
|
137
|
+
"name": "Knowledge Graph",
|
|
138
|
+
"description": "Extract entities and relationships with LLM to build a knowledge graph.",
|
|
139
|
+
"explanation": "**What it does:** Chunks text, then sends each chunk to an LLM which identifies entities (people, systems, concepts) and how they relate. Creates a connected knowledge graph.\n\n**When to use:** You want to understand WHO, WHAT, and HOW things connect in your documents. Best for meeting notes, specs, reports.\n\n**Result:** Entity nodes (Person, System, Concept) connected by relationship edges (MAINTAINS, DEPENDS_ON, etc.).\n\n**Requires:** LLM (Groq, OpenAI, or Ollama).",
|
|
140
|
+
"version": 1,
|
|
141
|
+
"category": "ingestion",
|
|
142
|
+
"schema_name": "",
|
|
143
|
+
"parser": "",
|
|
144
|
+
"filters": {},
|
|
145
|
+
"graph_config": {},
|
|
146
|
+
"stages": [
|
|
147
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "paragraph", "max_size": 2000}},
|
|
148
|
+
{"name": "extract_entities", "type": "EXTRACT_ENTITIES", "config": {}},
|
|
149
|
+
{"name": "enhance", "type": "ENHANCE_GRAPH", "config": {}},
|
|
150
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
151
|
+
],
|
|
152
|
+
"default_params": {"chunk_method": "paragraph", "chunk_size": 2000, "llm_model": "groq:gpt-oss-120b"},
|
|
153
|
+
"aiql_template": (
|
|
154
|
+
'USE GRAPH {{graph}}\n'
|
|
155
|
+
'INGEST TEXT {{source}} CHUNK BY {{chunk_method}}\n'
|
|
156
|
+
'THEN EXTRACT ENTITIES USING LLM "{{llm_model}}"\n'
|
|
157
|
+
'THEN ENHANCE_GRAPH'
|
|
158
|
+
),
|
|
159
|
+
"governance": {"owner": "system", "classification": "internal", "approved_by": "system"},
|
|
160
|
+
"tags": ["knowledge-graph", "entities", "relationships", "llm"],
|
|
161
|
+
"builtin": True,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"id": "builtin:full",
|
|
165
|
+
"name": "Full Pipeline",
|
|
166
|
+
"description": "Complete pipeline: chunk, embed, extract entities & relationships, enhance graph.",
|
|
167
|
+
"explanation": "**What it does:** Everything — chunks text, generates embeddings, extracts entities and relationships with LLM, deduplicates, and adds inferred connections.\n\n**When to use:** You want the richest possible graph from your documents. Best for important docs where you need both semantic search AND knowledge graph traversal.\n\n**Result:** TextChunks (with embeddings) + Entity nodes + Relationship edges + Co-occurrence links.\n\n**Requires:** LLM + Embedding model. Slower but most comprehensive.",
|
|
168
|
+
"version": 1,
|
|
169
|
+
"category": "ingestion",
|
|
170
|
+
"schema_name": "",
|
|
171
|
+
"parser": "",
|
|
172
|
+
"filters": {},
|
|
173
|
+
"graph_config": {},
|
|
174
|
+
"stages": [
|
|
175
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "semantic", "max_size": 1500}},
|
|
176
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
177
|
+
{"name": "extract_entities", "type": "EXTRACT_ENTITIES_AND_RELATIONSHIPS", "config": {}},
|
|
178
|
+
{"name": "enhance", "type": "ENHANCE_GRAPH", "config": {}},
|
|
179
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
180
|
+
],
|
|
181
|
+
"default_params": {
|
|
182
|
+
"chunk_method": "semantic",
|
|
183
|
+
"chunk_size": 1500,
|
|
184
|
+
"llm_model": "groq:gpt-oss-120b",
|
|
185
|
+
"embedding_model": "nomic-embed-text",
|
|
186
|
+
},
|
|
187
|
+
"aiql_template": (
|
|
188
|
+
'USE GRAPH {{graph}}\n'
|
|
189
|
+
'INGEST TEXT {{source}} CHUNK BY {{chunk_method}}\n'
|
|
190
|
+
'THEN EMBED USING MODEL "{{embedding_model}}"\n'
|
|
191
|
+
'THEN EXTRACT ENTITIES AND RELATIONSHIPS USING LLM "{{llm_model}}"\n'
|
|
192
|
+
'THEN ENHANCE_GRAPH'
|
|
193
|
+
),
|
|
194
|
+
"governance": {"owner": "system", "classification": "internal", "approved_by": "system"},
|
|
195
|
+
"tags": ["full", "knowledge-graph", "embeddings", "llm"],
|
|
196
|
+
"builtin": True,
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"id": "builtin:schema-guided",
|
|
200
|
+
"name": "Schema-Guided Extraction",
|
|
201
|
+
"description": "Extract entities constrained to a YAML schema. Best for structured domains.",
|
|
202
|
+
"explanation": "**What it does:** Like Knowledge Graph, but the LLM is constrained to only extract entity types defined in your schema (e.g. Patient, Condition, Treatment for healthcare). Produces a cleaner, more structured graph.\n\n**When to use:** You have domain-specific documents and want consistent entity types. Select an industry schema or create a custom one.\n\n**Result:** Typed entities matching your schema + relationships + embeddings.\n\n**Requires:** LLM + Embedding model + Extraction schema (auto-detected from context tags).",
|
|
203
|
+
"version": 1,
|
|
204
|
+
"category": "ingestion",
|
|
205
|
+
"schema_name": "",
|
|
206
|
+
"parser": "",
|
|
207
|
+
"filters": {},
|
|
208
|
+
"graph_config": {},
|
|
209
|
+
"stages": [
|
|
210
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "paragraph", "max_size": 2000}},
|
|
211
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
212
|
+
{"name": "extract_entities", "type": "EXTRACT_ENTITIES", "config": {"schema_guided": True}},
|
|
213
|
+
{"name": "enhance", "type": "ENHANCE_GRAPH", "config": {}},
|
|
214
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
215
|
+
],
|
|
216
|
+
"default_params": {
|
|
217
|
+
"chunk_method": "paragraph",
|
|
218
|
+
"chunk_size": 2000,
|
|
219
|
+
"llm_model": "groq:gpt-oss-120b",
|
|
220
|
+
"embedding_model": "nomic-embed-text",
|
|
221
|
+
},
|
|
222
|
+
"aiql_template": (
|
|
223
|
+
'USE GRAPH {{graph}}\n'
|
|
224
|
+
'INGEST TEXT {{source}} CHUNK BY {{chunk_method}}\n'
|
|
225
|
+
'THEN EMBED USING MODEL "{{embedding_model}}"\n'
|
|
226
|
+
'THEN EXTRACT ENTITIES USING LLM "{{llm_model}}" WITH SCHEMA {{schema}}\n'
|
|
227
|
+
'THEN ENHANCE_GRAPH'
|
|
228
|
+
),
|
|
229
|
+
"governance": {"owner": "system", "classification": "internal", "approved_by": "system"},
|
|
230
|
+
"tags": ["schema", "structured", "knowledge-graph", "llm"],
|
|
231
|
+
"builtin": True,
|
|
232
|
+
},
|
|
233
|
+
# --- Scenario-driven pipelines (file-aware) ---
|
|
234
|
+
{
|
|
235
|
+
"id": "builtin:structured-graph",
|
|
236
|
+
"name": "Structured Graph (Excel/CSV)",
|
|
237
|
+
"description": "Parse Excel/CSV with source/target/relation columns directly into a graph. No LLM needed.",
|
|
238
|
+
"schema_name": "",
|
|
239
|
+
"parser": "",
|
|
240
|
+
"filters": {},
|
|
241
|
+
"graph_config": {},
|
|
242
|
+
"explanation": "**What it does:** Reads an Excel/CSV file that has columns like 'Source', 'Target', 'Relation'. Each row becomes an edge in the graph, with source and target as nodes.\n\n**When to use:** Your data is already structured as relationships — org charts, dependency maps, network diagrams, adjacency lists.\n\n**Example input:**\n| Source | Target | Relation | Weight |\n| Alice | Auth | MAINTAINS | high |\n| Auth | Billing | DEPENDS_ON | critical |\n\n**Result:** Nodes (Alice, Auth, Billing) + Edges (MAINTAINS, DEPENDS_ON) with properties.\n\n**Requires:** Nothing — no LLM, no embeddings. Instant.",
|
|
243
|
+
"version": 1,
|
|
244
|
+
"category": "ingestion",
|
|
245
|
+
"stages": [
|
|
246
|
+
{"name": "parse_file", "type": "PARSE_FILE", "config": {}},
|
|
247
|
+
{"name": "classify", "type": "CLASSIFY", "config": {}},
|
|
248
|
+
{"name": "map_tabular", "type": "MAP_TABULAR", "config": {}},
|
|
249
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
250
|
+
],
|
|
251
|
+
"default_params": {},
|
|
252
|
+
"aiql_template": (
|
|
253
|
+
'USE GRAPH {{graph}}\n'
|
|
254
|
+
'LOAD FILE {{source}}\n'
|
|
255
|
+
'THEN MAP_TABULAR\n'
|
|
256
|
+
'THEN PERSIST'
|
|
257
|
+
),
|
|
258
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
259
|
+
"tags": ["structured", "excel", "csv", "no-llm", "fast", "tabular"],
|
|
260
|
+
"builtin": True,
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"id": "builtin:record-to-graph",
|
|
264
|
+
"name": "Record to Graph",
|
|
265
|
+
"description": "Convert flat records (Excel/CSV rows) into graph nodes with FK-derived edges and embeddings.",
|
|
266
|
+
"schema_name": "",
|
|
267
|
+
"parser": "",
|
|
268
|
+
"filters": {},
|
|
269
|
+
"graph_config": {},
|
|
270
|
+
"explanation": "**What it does:** Each row in your spreadsheet becomes a node. Columns ending in '_id' or '_key' are treated as foreign keys — they create edges to other nodes. Embeddings are generated for search.\n\n**When to use:** You have a flat table (customer list, product catalog, inventory) and want to create a searchable graph with auto-discovered relationships.\n\n**Example input:**\n| customer_id | name | order_id | product |\n| C001 | Alice | O123 | Widget |\n\n**Result:** Customer nodes linked to Order nodes via FK edges + embeddings.\n\n**Requires:** Embedding model (optional).",
|
|
271
|
+
"version": 1,
|
|
272
|
+
"category": "ingestion",
|
|
273
|
+
"stages": [
|
|
274
|
+
{"name": "parse_file", "type": "PARSE_FILE", "config": {}},
|
|
275
|
+
{"name": "classify", "type": "CLASSIFY", "config": {}},
|
|
276
|
+
{"name": "map_tabular", "type": "MAP_TABULAR", "config": {}},
|
|
277
|
+
{"name": "canonicalize", "type": "CANONICALIZE", "config": {}},
|
|
278
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
279
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
280
|
+
],
|
|
281
|
+
"default_params": {"embedding_model": "nomic-embed-text"},
|
|
282
|
+
"aiql_template": (
|
|
283
|
+
'USE GRAPH {{graph}}\n'
|
|
284
|
+
'LOAD FILE {{source}}\n'
|
|
285
|
+
'THEN MAP_TABULAR\n'
|
|
286
|
+
'THEN CANONICALIZE\n'
|
|
287
|
+
'THEN EMBED USING MODEL "{{embedding_model}}"\n'
|
|
288
|
+
'THEN PERSIST'
|
|
289
|
+
),
|
|
290
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
291
|
+
"tags": ["records", "excel", "csv", "embeddings", "tabular"],
|
|
292
|
+
"builtin": True,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"id": "builtin:table-extraction",
|
|
296
|
+
"name": "Table Extraction",
|
|
297
|
+
"description": "Extract tables from documents (PDF, DOCX), map to graph, and enrich with LLM.",
|
|
298
|
+
"schema_name": "",
|
|
299
|
+
"parser": "",
|
|
300
|
+
"filters": {},
|
|
301
|
+
"graph_config": {},
|
|
302
|
+
"explanation": "**What it does:** Finds tables inside PDF/DOCX documents, maps them to graph nodes/edges (like Structured Graph), then uses LLM to extract additional entities from the surrounding text.\n\n**When to use:** Your documents contain embedded tables (financial reports, spec sheets with data tables) that should become graph structure.\n\n**Result:** Table rows → nodes + edges, plus LLM-extracted entities from text content + embeddings.\n\n**Requires:** LLM + Embedding model.",
|
|
303
|
+
"version": 1,
|
|
304
|
+
"category": "ingestion",
|
|
305
|
+
"stages": [
|
|
306
|
+
{"name": "parse_file", "type": "PARSE_FILE", "config": {}},
|
|
307
|
+
{"name": "classify", "type": "CLASSIFY", "config": {}},
|
|
308
|
+
{"name": "map_tabular", "type": "MAP_TABULAR", "config": {}},
|
|
309
|
+
{"name": "extract", "type": "EXTRACT", "config": {}},
|
|
310
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
311
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
312
|
+
],
|
|
313
|
+
"default_params": {"llm_model": "groq:gpt-oss-120b", "embedding_model": "nomic-embed-text"},
|
|
314
|
+
"aiql_template": (
|
|
315
|
+
'USE GRAPH {{graph}}\n'
|
|
316
|
+
'LOAD FILE {{source}}\n'
|
|
317
|
+
'THEN MAP_TABULAR\n'
|
|
318
|
+
'THEN EXTRACT ENTITIES USING LLM "{{llm_model}}"\n'
|
|
319
|
+
'THEN EMBED USING MODEL "{{embedding_model}}"\n'
|
|
320
|
+
'THEN PERSIST'
|
|
321
|
+
),
|
|
322
|
+
"governance": {"owner": "system", "classification": "internal", "approved_by": "system"},
|
|
323
|
+
"tags": ["tables", "pdf", "docx", "llm", "embeddings"],
|
|
324
|
+
"builtin": True,
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
"id": "builtin:auto",
|
|
328
|
+
"name": "Auto-Detect Pipeline",
|
|
329
|
+
"description": "Automatically classify the input file and select the best pipeline. Recommended for most use cases.",
|
|
330
|
+
"schema_name": "",
|
|
331
|
+
"parser": "",
|
|
332
|
+
"filters": {},
|
|
333
|
+
"graph_config": {},
|
|
334
|
+
"explanation": "**What it does:** Reads your file, auto-detects its type (document, spreadsheet, table-heavy), and picks the best pipeline automatically.\n\n**When to use:** You're not sure which pipeline to pick. Let the system decide.\n\n**How it decides:**\n- Excel/CSV with source/target columns → Structured Graph\n- Excel/CSV with flat rows → Record to Graph\n- PDF/DOCX with tables → Table Extraction\n- PDF/DOCX with text → Multi-Layer Extraction\n- Plain text → Knowledge Graph\n\n**Requires:** LLM + Embedding model (for full extraction).",
|
|
335
|
+
"version": 1,
|
|
336
|
+
"category": "ingestion",
|
|
337
|
+
"stages": [
|
|
338
|
+
{"name": "parse_file", "type": "PARSE_FILE", "config": {}},
|
|
339
|
+
{"name": "classify", "type": "CLASSIFY", "config": {}},
|
|
340
|
+
# Remaining stages determined by ScenarioRouter at runtime
|
|
341
|
+
],
|
|
342
|
+
"default_params": {"llm_model": "groq:gpt-oss-120b", "embedding_model": "nomic-embed-text"},
|
|
343
|
+
"aiql_template": (
|
|
344
|
+
'USE GRAPH {{graph}}\n'
|
|
345
|
+
'RUN AUTO PIPELINE ON FILE {{source}}'
|
|
346
|
+
),
|
|
347
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
348
|
+
"tags": ["auto", "smart", "recommended"],
|
|
349
|
+
"builtin": True,
|
|
350
|
+
},
|
|
351
|
+
# --- Smart Article Pipeline (new 7-stage) ---
|
|
352
|
+
{
|
|
353
|
+
"id": "builtin:smart-article",
|
|
354
|
+
"name": "Smart Article Ingestion",
|
|
355
|
+
"schema_name": "",
|
|
356
|
+
"parser": "",
|
|
357
|
+
"filters": {},
|
|
358
|
+
"graph_config": {},
|
|
359
|
+
"description": (
|
|
360
|
+
"For news articles, blog posts, and web pages. Uses Trafilatura for HTML cleaning, "
|
|
361
|
+
"hybrid paragraph chunking, local LLM for entity/fact/relationship extraction, "
|
|
362
|
+
"and builds a rich knowledge graph with Passages, Entities, Facts, and Links."
|
|
363
|
+
),
|
|
364
|
+
"explanation": (
|
|
365
|
+
"**What it does:** The smartest ingestion pipeline. 7 stages:\n\n"
|
|
366
|
+
"1. **Clean** \u2014 Trafilatura strips HTML/nav/ads, extracts article body + metadata + links\n"
|
|
367
|
+
"2. **Chunk** \u2014 Hybrid paragraph chunker (merge short, split long, sentence overlap)\n"
|
|
368
|
+
"3. **Extract** \u2014 Per-chunk LLM extraction (entities, facts, relationships) + regex supplement\n"
|
|
369
|
+
"4. **Link** \u2014 Create graph: Document, Passage, Entity, Fact, Link nodes + all edges\n"
|
|
370
|
+
"5. **Embed** \u2014 Vector embed each Passage + Entity for semantic search\n"
|
|
371
|
+
"6. **Index** \u2014 BM25 index for keyword search\n"
|
|
372
|
+
"7. **Validate** \u2014 Schema validation + dedup\n\n"
|
|
373
|
+
"**When to use:** Best quality for web content. Produces the richest graph.\n\n"
|
|
374
|
+
"**Result:** Document \u2192 Passages (with overlap) \u2192 Entities (deduped) \u2192 Facts (with provenance) + Links + typed relationship edges.\n\n"
|
|
375
|
+
"**Requires:** LLM (local Ollama = free, or cloud)."
|
|
376
|
+
),
|
|
377
|
+
"version": 1,
|
|
378
|
+
"category": "ingestion",
|
|
379
|
+
"stages": [
|
|
380
|
+
{"name": "clean", "type": "CLEAN", "config": {"method": "trafilatura"}},
|
|
381
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "hybrid_paragraph", "overlap": True}},
|
|
382
|
+
{"name": "extract", "type": "EXTRACT", "config": {"method": "llm+regex", "per_chunk": True}},
|
|
383
|
+
{"name": "link", "type": "LINK", "config": {"edges": ["CONTAINS", "NEXT", "MENTIONS", "STATES", "DERIVED_FROM", "LINKS_TO"]}},
|
|
384
|
+
{"name": "embed", "type": "EMBED", "config": {"targets": ["Passage", "Entity"]}},
|
|
385
|
+
{"name": "index", "type": "INDEX_BM25", "config": {"targets": ["Passage", "Entity", "Fact"]}},
|
|
386
|
+
{"name": "validate", "type": "VALIDATE_SCHEMA", "config": {}},
|
|
387
|
+
],
|
|
388
|
+
"default_params": {},
|
|
389
|
+
"aiql_template": "",
|
|
390
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
391
|
+
"tags": ["smart", "article", "web", "llm", "recommended"],
|
|
392
|
+
"builtin": True,
|
|
393
|
+
"_smart_pipeline": "smart_article",
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
"id": "builtin:smart-fast",
|
|
397
|
+
"name": "Fast Ingest (No LLM)",
|
|
398
|
+
"schema_name": "",
|
|
399
|
+
"parser": "",
|
|
400
|
+
"filters": {},
|
|
401
|
+
"graph_config": {},
|
|
402
|
+
"description": "Regex-only extraction, no LLM calls. Fastest pipeline for bulk imports where speed matters more than extraction depth.",
|
|
403
|
+
"explanation": (
|
|
404
|
+
"**What it does:** Same chunking as Smart Article but uses only regex for extraction (no LLM).\n\n"
|
|
405
|
+
"**When to use:** Bulk imports, low-priority content, or when no LLM is available.\n\n"
|
|
406
|
+
"**Result:** Document \u2192 Passages + basic entities (names, emails, dates).\n\n"
|
|
407
|
+
"**Requires:** Nothing \u2014 no LLM, no embeddings."
|
|
408
|
+
),
|
|
409
|
+
"version": 1,
|
|
410
|
+
"category": "ingestion",
|
|
411
|
+
"stages": [
|
|
412
|
+
{"name": "clean", "type": "CLEAN", "config": {}},
|
|
413
|
+
{"name": "chunk", "type": "CHUNK", "config": {}},
|
|
414
|
+
{"name": "extract", "type": "EXTRACT", "config": {"method": "regex_only"}},
|
|
415
|
+
{"name": "link", "type": "LINK", "config": {}},
|
|
416
|
+
{"name": "validate", "type": "VALIDATE_SCHEMA", "config": {}},
|
|
417
|
+
],
|
|
418
|
+
"default_params": {},
|
|
419
|
+
"aiql_template": "",
|
|
420
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
421
|
+
"tags": ["fast", "no-llm", "bulk"],
|
|
422
|
+
"builtin": True,
|
|
423
|
+
"_smart_pipeline": "fast_ingest",
|
|
424
|
+
},
|
|
425
|
+
# --- Multi-Layer Graph-Based Extraction ---
|
|
426
|
+
{
|
|
427
|
+
"id": "builtin:multi-layer-extraction",
|
|
428
|
+
"name": "Multi-Layer Graph-Based Extraction",
|
|
429
|
+
"schema_name": "",
|
|
430
|
+
"parser": "",
|
|
431
|
+
"filters": {},
|
|
432
|
+
"graph_config": {},
|
|
433
|
+
"description": (
|
|
434
|
+
"Multi-layer extraction: Document \u2192 Passage \u2192 Fact \u2192 Entity hierarchy. "
|
|
435
|
+
"Passages are embedded and stored in vector DB. "
|
|
436
|
+
"Facts are BM25-indexed for keyword search. "
|
|
437
|
+
"Entities are linked across the entire graph for traversal-based retrieval."
|
|
438
|
+
),
|
|
439
|
+
"explanation": "**What it does:** Creates a 3-layer knowledge hierarchy:\n\n1. **Passages** — text chunks (embedded for vector search)\n2. **Facts** — individual factual statements extracted by LLM (BM25-indexed)\n3. **Entities** — named things with relationships (graph-traversable)\n\nEach layer is connected: Passage → STATES → Fact → MENTIONS → Entity.\n\n**When to use:** Maximum retrieval quality. RAG queries can search by meaning (vectors), keywords (BM25), or graph traversal (follow edges). Best for important knowledge bases.\n\n**Result:** Document → Passages → Facts → Entities, all cross-linked.\n\n**Requires:** LLM + Embedding model. Most comprehensive but slowest.",
|
|
440
|
+
"version": 1,
|
|
441
|
+
"category": "ingestion",
|
|
442
|
+
"stages": [
|
|
443
|
+
{"name": "parse_file", "type": "PARSE_FILE", "config": {}},
|
|
444
|
+
{"name": "classify", "type": "CLASSIFY", "config": {}},
|
|
445
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "paragraph", "max_size": 1500}},
|
|
446
|
+
{"name": "extract_facts", "type": "EXTRACT_FACTS", "config": {}},
|
|
447
|
+
{"name": "extract_entities", "type": "EXTRACT", "config": {}},
|
|
448
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
449
|
+
{"name": "index_bm25", "type": "INDEX_BM25", "config": {}},
|
|
450
|
+
{"name": "store_vectors", "type": "STORE_VECTORS", "config": {}},
|
|
451
|
+
{"name": "canonicalize", "type": "CANONICALIZE", "config": {}},
|
|
452
|
+
{"name": "enhance_graph", "type": "ENHANCE_GRAPH", "config": {}},
|
|
453
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
454
|
+
],
|
|
455
|
+
"default_params": {
|
|
456
|
+
"llm_model": "groq:gpt-oss-120b",
|
|
457
|
+
"embedding_model": "nomic-embed-text",
|
|
458
|
+
"chunk_method": "paragraph",
|
|
459
|
+
"chunk_size": 1500,
|
|
460
|
+
},
|
|
461
|
+
"aiql_template": (
|
|
462
|
+
'USE GRAPH {{graph}}\n'
|
|
463
|
+
'LOAD FILE {{source}}\n'
|
|
464
|
+
'THEN CHUNK BY {{chunk_method}}\n'
|
|
465
|
+
'THEN EXTRACT FACTS USING LLM "{{llm_model}}"\n'
|
|
466
|
+
'THEN EXTRACT ENTITIES USING LLM "{{llm_model}}"\n'
|
|
467
|
+
'THEN EMBED USING MODEL "{{embedding_model}}"\n'
|
|
468
|
+
'THEN INDEX_BM25\n'
|
|
469
|
+
'THEN STORE_VECTORS\n'
|
|
470
|
+
'THEN CANONICALIZE\n'
|
|
471
|
+
'THEN ENHANCE_GRAPH\n'
|
|
472
|
+
'THEN PERSIST'
|
|
473
|
+
),
|
|
474
|
+
"governance": {"owner": "system", "classification": "internal", "approved_by": "system"},
|
|
475
|
+
"tags": ["multi-layer", "extraction", "facts", "bm25", "vector", "knowledge-graph", "rag"],
|
|
476
|
+
"builtin": True,
|
|
477
|
+
},
|
|
478
|
+
# --- Software Development / SDLC ---
|
|
479
|
+
{
|
|
480
|
+
"id": "builtin:sdlc-graph-rag",
|
|
481
|
+
"name": "SDLC Graph RAG",
|
|
482
|
+
"schema_name": "",
|
|
483
|
+
"parser": "",
|
|
484
|
+
"filters": {},
|
|
485
|
+
"graph_config": {},
|
|
486
|
+
"description": (
|
|
487
|
+
"Extract software development artifacts — features, requirements, components, APIs, "
|
|
488
|
+
"data models, risks, stakeholders — from project specs and design docs. "
|
|
489
|
+
"Uses the SDLC extraction schema for structured, schema-guided extraction."
|
|
490
|
+
),
|
|
491
|
+
"explanation": "**What it does:** Specialized for software projects. Extracts:\n- Requirements, Features, User Stories\n- System components, APIs, Endpoints\n- Data models, Schemas\n- Risks, Stakeholders, Decisions\n\nUses the SDLC extraction schema to constrain the LLM to only extract software-relevant entities.\n\n**When to use:** Ingesting project specs, PRDs, design docs, API documentation. The extracted graph powers agent briefings and task planning.\n\n**Result:** Typed software entities + relationships + facts + embeddings.\n\n**Requires:** LLM + Embedding model.",
|
|
492
|
+
"version": 1,
|
|
493
|
+
"category": "ingestion",
|
|
494
|
+
"stages": [
|
|
495
|
+
{"name": "parse_file", "type": "PARSE_FILE", "config": {}},
|
|
496
|
+
{"name": "classify", "type": "CLASSIFY", "config": {}},
|
|
497
|
+
{"name": "chunk", "type": "CHUNK", "config": {"method": "paragraph", "max_size": 2000}},
|
|
498
|
+
{"name": "extract_facts", "type": "EXTRACT_FACTS", "config": {}},
|
|
499
|
+
{"name": "extract_entities", "type": "EXTRACT", "config": {"schema_guided": True}},
|
|
500
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
501
|
+
{"name": "index_bm25", "type": "INDEX_BM25", "config": {}},
|
|
502
|
+
{"name": "store_vectors", "type": "STORE_VECTORS", "config": {}},
|
|
503
|
+
{"name": "canonicalize", "type": "CANONICALIZE", "config": {}},
|
|
504
|
+
{"name": "enhance_graph", "type": "ENHANCE_GRAPH", "config": {}},
|
|
505
|
+
{"name": "persist", "type": "PERSIST", "config": {}},
|
|
506
|
+
],
|
|
507
|
+
"default_params": {
|
|
508
|
+
"llm_model": "groq:gpt-oss-120b",
|
|
509
|
+
"embedding_model": "nomic-embed-text",
|
|
510
|
+
"chunk_method": "paragraph",
|
|
511
|
+
"chunk_size": 2000,
|
|
512
|
+
},
|
|
513
|
+
"aiql_template": (
|
|
514
|
+
'USE GRAPH {{graph}}\n'
|
|
515
|
+
'LOAD FILE {{source}}\n'
|
|
516
|
+
'THEN CHUNK BY {{chunk_method}}\n'
|
|
517
|
+
'THEN EXTRACT FACTS USING LLM "{{llm_model}}"\n'
|
|
518
|
+
'THEN EXTRACT ENTITIES USING LLM "{{llm_model}}" WITH SCHEMA sdlc\n'
|
|
519
|
+
'THEN EMBED USING MODEL "{{embedding_model}}"\n'
|
|
520
|
+
'THEN INDEX_BM25\n'
|
|
521
|
+
'THEN STORE_VECTORS\n'
|
|
522
|
+
'THEN CANONICALIZE\n'
|
|
523
|
+
'THEN ENHANCE_GRAPH\n'
|
|
524
|
+
'THEN PERSIST'
|
|
525
|
+
),
|
|
526
|
+
"governance": {"owner": "system", "classification": "internal", "approved_by": "system"},
|
|
527
|
+
"tags": ["sdlc", "software", "schema", "extraction", "facts", "knowledge-graph", "rag", "recommended"],
|
|
528
|
+
"builtin": True,
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
"id": "builtin:conversation",
|
|
532
|
+
"name": "Conversation Import",
|
|
533
|
+
"description": "For ChatGPT/Claude/Gemini exports. TurnParser + full graph construction with entity resolution and domain inference.",
|
|
534
|
+
"explanation": "**What it does:** Parses chat conversations into turns, detects signals (decisions/problems/solutions), extracts entities, resolves duplicates across conversations, builds schema-driven edges, infers domains, and clusters into Context Units.\n\n**When to use:** Upload a ChatGPT or Claude export (ZIP or JSON). This pipeline understands conversation structure.\n\n**Accepts:** JSON, ZIP (conversation exports)\n\n**Result:** Rich entity-centric graph with cross-conversation linking and domain clustering.",
|
|
535
|
+
"version": 1,
|
|
536
|
+
"category": "ingestion",
|
|
537
|
+
"schema_name": "claude_conversation",
|
|
538
|
+
"parser": "turn",
|
|
539
|
+
"filters": {"min_length": 10},
|
|
540
|
+
"graph_config": {
|
|
541
|
+
"entity_resolution": True,
|
|
542
|
+
"co_occurrence_threshold": 2,
|
|
543
|
+
"domain_inference": True,
|
|
544
|
+
"context_units": True,
|
|
545
|
+
},
|
|
546
|
+
"stages": [
|
|
547
|
+
{"name": "filter", "type": "filter_content", "config": {}},
|
|
548
|
+
{"name": "signals", "type": "detect_signals", "config": {}},
|
|
549
|
+
{"name": "entities", "type": "extract_entities", "config": {}},
|
|
550
|
+
{"name": "store", "type": "store_documents", "config": {}},
|
|
551
|
+
{"name": "resolve", "type": "resolve_entities", "config": {}},
|
|
552
|
+
{"name": "edges", "type": "build_edges", "config": {}},
|
|
553
|
+
{"name": "domains", "type": "infer_domains", "config": {}},
|
|
554
|
+
{"name": "topics", "type": "cluster_topics", "config": {}},
|
|
555
|
+
{"name": "xref", "type": "link_cross_reference", "config": {}},
|
|
556
|
+
{"name": "validate", "type": "validate_gate", "config": {}},
|
|
557
|
+
{"name": "dedup", "type": "deduplicate", "config": {}},
|
|
558
|
+
{"name": "cu", "type": "synthesize_cu", "config": {}},
|
|
559
|
+
{"name": "embed", "type": "EMBED", "config": {}},
|
|
560
|
+
{"name": "index", "type": "INDEX_BM25", "config": {}},
|
|
561
|
+
],
|
|
562
|
+
"default_params": {"llm_model": "openai:gpt-4o-mini", "embedding_model": "nomic-embed-text"},
|
|
563
|
+
"aiql_template": "",
|
|
564
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
565
|
+
"tags": ["conversation", "chat", "claude", "chatgpt", "import"],
|
|
566
|
+
"builtin": True,
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
"id": "builtin:sdlc-quickscan",
|
|
570
|
+
"name": "SDLC Quick Scan (No Clone)",
|
|
571
|
+
"description": "Quick scan via GitHub API — no clone needed. Fetches README, issues, PRs, contributors, metadata in ~5 seconds.",
|
|
572
|
+
"explanation": "**What it does:** Uses GitHub REST API to fetch:\n- README → Requirements\n- Open + closed issues → Requirements / KnownIssues\n- Pull requests → ChangeRecords (what's in progress)\n- Contributors → who built what\n- Repo metadata → stars, forks, branches, tags, language\n\n**When to use:** Quick overview of any GitHub repository. No clone, no disk usage, instant.\n\n**What you DON'T get:** Source code analysis, test file scanning, API route detection, import analysis.\n\n**Result:** Intent + verify + evolution layers populated. Build layer empty (use Full Scan for that).",
|
|
573
|
+
"version": 1,
|
|
574
|
+
"category": "ingestion",
|
|
575
|
+
"schema_name": "",
|
|
576
|
+
"parser": "",
|
|
577
|
+
"filters": {},
|
|
578
|
+
"graph_config": {},
|
|
579
|
+
"stages": [
|
|
580
|
+
{"name": "sdlc_scan", "type": "SDLC_SCAN", "config": {}},
|
|
581
|
+
],
|
|
582
|
+
"default_params": {
|
|
583
|
+
"scan_mode": "quick",
|
|
584
|
+
"max_cus": 8,
|
|
585
|
+
},
|
|
586
|
+
"aiql_template": "",
|
|
587
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
588
|
+
"tags": ["sdlc", "repo", "quick", "api", "no-clone", "recommended", "default"],
|
|
589
|
+
"builtin": True,
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
"id": "builtin:sdlc-fullscan",
|
|
593
|
+
"name": "SDLC Full Scan (Clone)",
|
|
594
|
+
"description": "Full repository scan — clones the repo and analyzes source code, tests, docs, API routes, plus GitHub API data. Resumable — restart from any failed step.",
|
|
595
|
+
"explanation": "**What it does:** Everything from Quick Scan PLUS:\n- Source code → CodeModules with summaries\n- Tests → TestCases\n- Docs → ArchDecisions\n- API routes → APIContracts\n- Import analysis → DEPENDS_ON edges\n- Git history → high-churn ChangeRecords\n- Optional LLM enrichment for deep code understanding\n\n**Resumable:** 5 sub-stages run independently. If stage 3 fails, restart from stage 3 — stages 1-2 are preserved.\n\n**When to use:** When agents need to read/write code, run tests, or do gap analysis between spec and implementation.\n\n**Result:** All 5 SDLC layers populated. Full edge inference. Coverage scoring.",
|
|
596
|
+
"version": 2,
|
|
597
|
+
"category": "ingestion",
|
|
598
|
+
"schema_name": "",
|
|
599
|
+
"parser": "",
|
|
600
|
+
"filters": {},
|
|
601
|
+
"graph_config": {},
|
|
602
|
+
"stages": [
|
|
603
|
+
{"name": "scan_files", "type": "SDLC_SCAN_FILES", "config": {}},
|
|
604
|
+
{"name": "scan_github", "type": "SDLC_SCAN_GITHUB", "config": {}},
|
|
605
|
+
{"name": "scan_git", "type": "SDLC_SCAN_GIT", "config": {}},
|
|
606
|
+
{"name": "infer_edges", "type": "SDLC_SCAN_EDGES", "config": {}},
|
|
607
|
+
{"name": "context_units", "type": "SDLC_SCAN_CU", "config": {}},
|
|
608
|
+
],
|
|
609
|
+
"default_params": {
|
|
610
|
+
"scan_mode": "full",
|
|
611
|
+
"max_cus": 8,
|
|
612
|
+
"skip_llm": True,
|
|
613
|
+
"file_extensions": ".py,.ts,.js,.go,.rs,.java,.tsx,.jsx",
|
|
614
|
+
},
|
|
615
|
+
"aiql_template": "",
|
|
616
|
+
"governance": {"owner": "system", "classification": "public", "approved_by": "system"},
|
|
617
|
+
"tags": ["sdlc", "repo", "full", "clone", "code", "scan"],
|
|
618
|
+
"builtin": True,
|
|
619
|
+
},
|
|
620
|
+
]
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
@dataclass
|
|
624
|
+
class AccuracyScore:
|
|
625
|
+
"""Extraction accuracy breakdown for a pipeline run."""
|
|
626
|
+
overall: float = 0.0 # 0.0 - 1.0
|
|
627
|
+
entity_confidence_avg: float = 0.0 # avg LLM confidence on entities
|
|
628
|
+
relationship_coverage: float = 0.0 # % chunks with ≥1 relationship
|
|
629
|
+
chunk_quality: float = 0.0 # avg chunk length / target ratio
|
|
630
|
+
embedding_coverage: float = 0.0 # % nodes with embeddings
|
|
631
|
+
schema_compliance: float = 0.0 # % entities matching schema types
|
|
632
|
+
entity_count: int = 0
|
|
633
|
+
relationship_count: int = 0
|
|
634
|
+
chunk_count: int = 0
|
|
635
|
+
embedded_count: int = 0
|
|
636
|
+
|
|
637
|
+
def compute_overall(self):
|
|
638
|
+
"""Weighted average of sub-scores."""
|
|
639
|
+
weights = {
|
|
640
|
+
"entity_confidence_avg": 0.3,
|
|
641
|
+
"relationship_coverage": 0.2,
|
|
642
|
+
"chunk_quality": 0.2,
|
|
643
|
+
"embedding_coverage": 0.15,
|
|
644
|
+
"schema_compliance": 0.15,
|
|
645
|
+
}
|
|
646
|
+
total_w = 0.0
|
|
647
|
+
total_s = 0.0
|
|
648
|
+
for key, w in weights.items():
|
|
649
|
+
val = getattr(self, key, 0.0)
|
|
650
|
+
if val > 0:
|
|
651
|
+
total_s += val * w
|
|
652
|
+
total_w += w
|
|
653
|
+
self.overall = round(total_s / total_w, 4) if total_w > 0 else 0.0
|
|
654
|
+
return self.overall
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
@dataclass
|
|
658
|
+
class StageLog:
|
|
659
|
+
"""Per-stage execution record."""
|
|
660
|
+
name: str
|
|
661
|
+
stage_type: str
|
|
662
|
+
status: str = "pending" # pending | running | completed | failed | skipped
|
|
663
|
+
started_at: Optional[str] = None
|
|
664
|
+
completed_at: Optional[str] = None
|
|
665
|
+
duration_ms: int = 0
|
|
666
|
+
items_processed: int = 0
|
|
667
|
+
items_created: int = 0
|
|
668
|
+
error: Optional[str] = None
|
|
669
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
@dataclass
|
|
673
|
+
class PipelineRun:
|
|
674
|
+
"""Execution record for a pipeline run."""
|
|
675
|
+
run_id: str
|
|
676
|
+
pipeline_id: str
|
|
677
|
+
pipeline_name: str
|
|
678
|
+
tenant_id: str
|
|
679
|
+
user_id: str
|
|
680
|
+
graph: str
|
|
681
|
+
source: str
|
|
682
|
+
source_type: str # text | file | url
|
|
683
|
+
params_used: Dict[str, Any] = field(default_factory=dict)
|
|
684
|
+
source_hash: str = "" # SHA-256 of source content (for dedup)
|
|
685
|
+
status: str = "pending" # pending | running | completed | failed
|
|
686
|
+
started_at: Optional[str] = None
|
|
687
|
+
completed_at: Optional[str] = None
|
|
688
|
+
duration_ms: int = 0
|
|
689
|
+
stages: List[StageLog] = field(default_factory=list)
|
|
690
|
+
nodes_created: int = 0
|
|
691
|
+
edges_created: int = 0
|
|
692
|
+
entities_extracted: int = 0
|
|
693
|
+
accuracy: Optional[AccuracyScore] = None
|
|
694
|
+
governance_tags: List[str] = field(default_factory=list)
|
|
695
|
+
data_classification: str = "internal" # public | internal | confidential | restricted
|
|
696
|
+
error: Optional[str] = None
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
# ---------------------------------------------------------------------------
|
|
700
|
+
# Pipeline Store (SQLite-backed)
|
|
701
|
+
# ---------------------------------------------------------------------------
|
|
702
|
+
|
|
703
|
+
class PipelineStore:
|
|
704
|
+
"""
|
|
705
|
+
Persistent store for pipeline definitions and run history.
|
|
706
|
+
|
|
707
|
+
Pipelines are stored procedures: named, versioned AIQL templates
|
|
708
|
+
with metadata, governance info, and execution tracking.
|
|
709
|
+
"""
|
|
710
|
+
|
|
711
|
+
def __init__(self, db_path: Optional[str] = None):
|
|
712
|
+
if db_path is None:
|
|
713
|
+
db_path = str(Path(__file__).resolve().parents[1] / "contextcore_data" / "pipelines.db")
|
|
714
|
+
self._db_path = db_path
|
|
715
|
+
Path(self._db_path).parent.mkdir(parents=True, exist_ok=True)
|
|
716
|
+
self._init_tables()
|
|
717
|
+
self._seed_builtins()
|
|
718
|
+
|
|
719
|
+
def _get_conn(self):
|
|
720
|
+
conn = sqlite3.connect(self._db_path)
|
|
721
|
+
conn.row_factory = sqlite3.Row
|
|
722
|
+
conn.execute("PRAGMA journal_mode=WAL")
|
|
723
|
+
conn.execute("PRAGMA foreign_keys=ON")
|
|
724
|
+
return conn
|
|
725
|
+
|
|
726
|
+
def _init_tables(self):
|
|
727
|
+
with self._get_conn() as conn:
|
|
728
|
+
conn.executescript("""
|
|
729
|
+
-- Pipeline definitions (stored procedures)
|
|
730
|
+
CREATE TABLE IF NOT EXISTS pipelines (
|
|
731
|
+
id TEXT PRIMARY KEY,
|
|
732
|
+
tenant_id TEXT NOT NULL DEFAULT 'system',
|
|
733
|
+
name TEXT NOT NULL,
|
|
734
|
+
description TEXT DEFAULT '',
|
|
735
|
+
version INTEGER DEFAULT 1,
|
|
736
|
+
category TEXT DEFAULT 'ingestion',
|
|
737
|
+
stages TEXT NOT NULL, -- JSON array of stage defs
|
|
738
|
+
default_params TEXT DEFAULT '{}', -- JSON defaults
|
|
739
|
+
aiql_template TEXT NOT NULL, -- parameterized AIQL
|
|
740
|
+
governance TEXT DEFAULT '{}', -- JSON {owner, classification, approved_by, approved_at}
|
|
741
|
+
tags TEXT DEFAULT '[]', -- JSON array of strings
|
|
742
|
+
builtin INTEGER DEFAULT 0,
|
|
743
|
+
enabled INTEGER DEFAULT 1,
|
|
744
|
+
created_at TEXT NOT NULL,
|
|
745
|
+
updated_at TEXT NOT NULL,
|
|
746
|
+
created_by TEXT DEFAULT 'system'
|
|
747
|
+
);
|
|
748
|
+
CREATE INDEX IF NOT EXISTS idx_pipelines_tenant ON pipelines(tenant_id);
|
|
749
|
+
CREATE INDEX IF NOT EXISTS idx_pipelines_category ON pipelines(category);
|
|
750
|
+
|
|
751
|
+
-- Pipeline run history
|
|
752
|
+
CREATE TABLE IF NOT EXISTS pipeline_runs (
|
|
753
|
+
run_id TEXT PRIMARY KEY,
|
|
754
|
+
pipeline_id TEXT NOT NULL,
|
|
755
|
+
pipeline_name TEXT NOT NULL,
|
|
756
|
+
tenant_id TEXT NOT NULL,
|
|
757
|
+
user_id TEXT NOT NULL,
|
|
758
|
+
graph TEXT NOT NULL,
|
|
759
|
+
source TEXT DEFAULT '',
|
|
760
|
+
source_type TEXT DEFAULT 'text',
|
|
761
|
+
source_hash TEXT DEFAULT '',
|
|
762
|
+
params_used TEXT DEFAULT '{}',
|
|
763
|
+
status TEXT DEFAULT 'pending',
|
|
764
|
+
started_at TEXT,
|
|
765
|
+
completed_at TEXT,
|
|
766
|
+
duration_ms INTEGER DEFAULT 0,
|
|
767
|
+
stages_log TEXT DEFAULT '[]', -- JSON array of StageLog
|
|
768
|
+
nodes_created INTEGER DEFAULT 0,
|
|
769
|
+
edges_created INTEGER DEFAULT 0,
|
|
770
|
+
entities_extracted INTEGER DEFAULT 0,
|
|
771
|
+
accuracy_score REAL DEFAULT 0.0,
|
|
772
|
+
accuracy_breakdown TEXT DEFAULT '{}', -- JSON AccuracyScore
|
|
773
|
+
governance_tags TEXT DEFAULT '[]',
|
|
774
|
+
data_classification TEXT DEFAULT 'internal',
|
|
775
|
+
error TEXT,
|
|
776
|
+
FOREIGN KEY (pipeline_id) REFERENCES pipelines(id)
|
|
777
|
+
);
|
|
778
|
+
CREATE INDEX IF NOT EXISTS idx_runs_tenant ON pipeline_runs(tenant_id);
|
|
779
|
+
CREATE INDEX IF NOT EXISTS idx_runs_pipeline ON pipeline_runs(pipeline_id);
|
|
780
|
+
CREATE INDEX IF NOT EXISTS idx_runs_status ON pipeline_runs(status);
|
|
781
|
+
CREATE INDEX IF NOT EXISTS idx_runs_graph ON pipeline_runs(graph);
|
|
782
|
+
""")
|
|
783
|
+
|
|
784
|
+
# Migration: add source_hash column if missing (existing DBs)
|
|
785
|
+
with self._get_conn() as conn:
|
|
786
|
+
cols = [r["name"] for r in conn.execute("PRAGMA table_info(pipeline_runs)").fetchall()]
|
|
787
|
+
if "source_hash" not in cols:
|
|
788
|
+
conn.execute("ALTER TABLE pipeline_runs ADD COLUMN source_hash TEXT DEFAULT ''")
|
|
789
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_runs_source_hash ON pipeline_runs(source_hash, graph)")
|
|
790
|
+
|
|
791
|
+
# Migration: add extended pipeline columns (schema_name, parser, filters, graph_config)
|
|
792
|
+
with self._get_conn() as conn:
|
|
793
|
+
for col, default in [("schema_name", "''"), ("parser", "''"), ("filters", "'{}'"), ("graph_config", "'{}'")]:
|
|
794
|
+
try:
|
|
795
|
+
conn.execute(f"ALTER TABLE pipelines ADD COLUMN {col} TEXT DEFAULT {default}")
|
|
796
|
+
except sqlite3.OperationalError:
|
|
797
|
+
pass
|
|
798
|
+
|
|
799
|
+
def _seed_builtins(self):
|
|
800
|
+
"""Insert/update built-in pipeline templates."""
|
|
801
|
+
now = datetime.now(timezone.utc).isoformat()
|
|
802
|
+
with self._get_conn() as conn:
|
|
803
|
+
for p in BUILTIN_PIPELINES:
|
|
804
|
+
existing = conn.execute("SELECT id, version FROM pipelines WHERE id = ?", (p["id"],)).fetchone()
|
|
805
|
+
if not existing:
|
|
806
|
+
conn.execute(
|
|
807
|
+
"""INSERT INTO pipelines
|
|
808
|
+
(id, tenant_id, name, description, version, category,
|
|
809
|
+
stages, default_params, aiql_template, governance, tags,
|
|
810
|
+
builtin, enabled, created_at, updated_at, created_by)
|
|
811
|
+
VALUES (?, 'system', ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, 1, ?, ?, 'system')""",
|
|
812
|
+
(
|
|
813
|
+
p["id"], p["name"], p["description"], p["version"], p["category"],
|
|
814
|
+
json.dumps(p["stages"]), json.dumps(p.get("default_params", {})),
|
|
815
|
+
p.get("aiql_template", ""), json.dumps(p.get("governance", {})),
|
|
816
|
+
json.dumps(p.get("tags", [])), now, now,
|
|
817
|
+
),
|
|
818
|
+
)
|
|
819
|
+
elif existing["version"] < p["version"]:
|
|
820
|
+
conn.execute(
|
|
821
|
+
"""UPDATE pipelines SET name=?, description=?, version=?, stages=?,
|
|
822
|
+
default_params=?, aiql_template=?, governance=?, tags=?, updated_at=?
|
|
823
|
+
WHERE id=?""",
|
|
824
|
+
(
|
|
825
|
+
p["name"], p["description"], p["version"],
|
|
826
|
+
json.dumps(p["stages"]), json.dumps(p.get("default_params", {})),
|
|
827
|
+
p.get("aiql_template", ""), json.dumps(p.get("governance", {})),
|
|
828
|
+
json.dumps(p.get("tags", [])), now, p["id"],
|
|
829
|
+
),
|
|
830
|
+
)
|
|
831
|
+
|
|
832
|
+
# ── Pipeline CRUD ──────────────────────────────────────────────────
|
|
833
|
+
|
|
834
|
+
def list_pipelines(self, tenant_id: str = "system", include_builtins: bool = True) -> List[Dict]:
|
|
835
|
+
"""List available pipelines for a tenant (includes builtins)."""
|
|
836
|
+
with self._get_conn() as conn:
|
|
837
|
+
if include_builtins:
|
|
838
|
+
rows = conn.execute(
|
|
839
|
+
"""SELECT * FROM pipelines
|
|
840
|
+
WHERE (tenant_id = ? OR tenant_id = 'system') AND enabled = 1
|
|
841
|
+
ORDER BY builtin DESC, name ASC""",
|
|
842
|
+
(tenant_id,),
|
|
843
|
+
).fetchall()
|
|
844
|
+
else:
|
|
845
|
+
rows = conn.execute(
|
|
846
|
+
"SELECT * FROM pipelines WHERE tenant_id = ? AND enabled = 1 ORDER BY name",
|
|
847
|
+
(tenant_id,),
|
|
848
|
+
).fetchall()
|
|
849
|
+
return [self._row_to_pipeline(r) for r in rows]
|
|
850
|
+
|
|
851
|
+
def get_pipeline(self, pipeline_id: str) -> Optional[Dict]:
|
|
852
|
+
"""Get a single pipeline definition."""
|
|
853
|
+
with self._get_conn() as conn:
|
|
854
|
+
row = conn.execute("SELECT * FROM pipelines WHERE id = ?", (pipeline_id,)).fetchone()
|
|
855
|
+
return self._row_to_pipeline(row) if row else None
|
|
856
|
+
|
|
857
|
+
def create_pipeline(
|
|
858
|
+
self,
|
|
859
|
+
tenant_id: str,
|
|
860
|
+
name: str,
|
|
861
|
+
description: str,
|
|
862
|
+
stages: List[Dict],
|
|
863
|
+
aiql_template: str,
|
|
864
|
+
default_params: Optional[Dict] = None,
|
|
865
|
+
governance: Optional[Dict] = None,
|
|
866
|
+
tags: Optional[List[str]] = None,
|
|
867
|
+
category: str = "ingestion",
|
|
868
|
+
created_by: str = "user",
|
|
869
|
+
schema_name: str = "",
|
|
870
|
+
parser: str = "",
|
|
871
|
+
filters: Optional[Dict] = None,
|
|
872
|
+
graph_config: Optional[Dict] = None,
|
|
873
|
+
) -> Dict:
|
|
874
|
+
"""Create a custom pipeline definition."""
|
|
875
|
+
pipeline_id = f"custom:{secrets.token_hex(8)}"
|
|
876
|
+
now = datetime.now(timezone.utc).isoformat()
|
|
877
|
+
gov = governance or {"owner": created_by, "classification": "internal"}
|
|
878
|
+
|
|
879
|
+
with self._get_conn() as conn:
|
|
880
|
+
conn.execute(
|
|
881
|
+
"""INSERT INTO pipelines
|
|
882
|
+
(id, tenant_id, name, description, version, category,
|
|
883
|
+
stages, default_params, aiql_template, governance, tags,
|
|
884
|
+
builtin, enabled, created_at, updated_at, created_by,
|
|
885
|
+
schema_name, parser, filters, graph_config)
|
|
886
|
+
VALUES (?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?, 0, 1, ?, ?, ?, ?, ?, ?, ?)""",
|
|
887
|
+
(
|
|
888
|
+
pipeline_id, tenant_id, name, description, category,
|
|
889
|
+
json.dumps(stages), json.dumps(default_params or {}),
|
|
890
|
+
aiql_template, json.dumps(gov), json.dumps(tags or []),
|
|
891
|
+
now, now, created_by,
|
|
892
|
+
schema_name, parser,
|
|
893
|
+
json.dumps(filters or {}), json.dumps(graph_config or {}),
|
|
894
|
+
),
|
|
895
|
+
)
|
|
896
|
+
return self.get_pipeline(pipeline_id)
|
|
897
|
+
|
|
898
|
+
def update_pipeline(self, pipeline_id: str, **updates) -> Optional[Dict]:
|
|
899
|
+
"""Update a custom pipeline (cannot update builtins)."""
|
|
900
|
+
pipeline = self.get_pipeline(pipeline_id)
|
|
901
|
+
if not pipeline or pipeline.get("builtin"):
|
|
902
|
+
return None
|
|
903
|
+
|
|
904
|
+
now = datetime.now(timezone.utc).isoformat()
|
|
905
|
+
allowed = {"name", "description", "stages", "aiql_template", "default_params", "governance", "tags", "category", "enabled", "schema_name", "parser", "filters", "graph_config"}
|
|
906
|
+
sets = ["updated_at = ?", "version = version + 1"]
|
|
907
|
+
vals = [now]
|
|
908
|
+
|
|
909
|
+
for key, val in updates.items():
|
|
910
|
+
if key not in allowed:
|
|
911
|
+
continue
|
|
912
|
+
if key in ("stages", "default_params", "governance", "tags", "filters", "graph_config"):
|
|
913
|
+
val = json.dumps(val)
|
|
914
|
+
sets.append(f"{key} = ?")
|
|
915
|
+
vals.append(val)
|
|
916
|
+
|
|
917
|
+
vals.append(pipeline_id)
|
|
918
|
+
with self._get_conn() as conn:
|
|
919
|
+
conn.execute(f"UPDATE pipelines SET {', '.join(sets)} WHERE id = ?", vals)
|
|
920
|
+
return self.get_pipeline(pipeline_id)
|
|
921
|
+
|
|
922
|
+
def delete_pipeline(self, pipeline_id: str) -> bool:
|
|
923
|
+
"""Delete a custom pipeline (cannot delete builtins)."""
|
|
924
|
+
with self._get_conn() as conn:
|
|
925
|
+
result = conn.execute(
|
|
926
|
+
"DELETE FROM pipelines WHERE id = ? AND builtin = 0", (pipeline_id,)
|
|
927
|
+
)
|
|
928
|
+
return result.rowcount > 0
|
|
929
|
+
|
|
930
|
+
# ── Pipeline Runs ──────────────────────────────────────────────────
|
|
931
|
+
|
|
932
|
+
def find_duplicate(self, graph: str, source_hash: str, tenant_id: str) -> Optional[Dict]:
|
|
933
|
+
"""Check if a file with the same content hash was already ingested into this graph."""
|
|
934
|
+
if not source_hash:
|
|
935
|
+
return None
|
|
936
|
+
with self._get_conn() as conn:
|
|
937
|
+
row = conn.execute(
|
|
938
|
+
"""SELECT run_id, source, status, started_at
|
|
939
|
+
FROM pipeline_runs
|
|
940
|
+
WHERE graph = ? AND source_hash = ? AND tenant_id = ?
|
|
941
|
+
AND status IN ('completed', 'running', 'pending')
|
|
942
|
+
ORDER BY started_at DESC LIMIT 1""",
|
|
943
|
+
(graph, source_hash, tenant_id),
|
|
944
|
+
).fetchone()
|
|
945
|
+
return dict(row) if row else None
|
|
946
|
+
|
|
947
|
+
def create_run(
|
|
948
|
+
self,
|
|
949
|
+
pipeline_id: str,
|
|
950
|
+
tenant_id: str,
|
|
951
|
+
user_id: str,
|
|
952
|
+
graph: str,
|
|
953
|
+
source: str = "",
|
|
954
|
+
source_type: str = "text",
|
|
955
|
+
source_hash: str = "",
|
|
956
|
+
params: Optional[Dict] = None,
|
|
957
|
+
governance_tags: Optional[List[str]] = None,
|
|
958
|
+
data_classification: str = "internal",
|
|
959
|
+
) -> PipelineRun:
|
|
960
|
+
"""Create a new pipeline run record."""
|
|
961
|
+
pipeline = self.get_pipeline(pipeline_id)
|
|
962
|
+
if not pipeline:
|
|
963
|
+
raise ValueError(f"Pipeline '{pipeline_id}' not found")
|
|
964
|
+
|
|
965
|
+
run_id = f"run_{secrets.token_hex(10)}"
|
|
966
|
+
now = datetime.now(timezone.utc).isoformat()
|
|
967
|
+
|
|
968
|
+
# Merge default params with runtime overrides
|
|
969
|
+
merged_params = {**(pipeline.get("default_params") or {}), **(params or {})}
|
|
970
|
+
|
|
971
|
+
# Initialize stage logs from pipeline definition
|
|
972
|
+
stage_logs = []
|
|
973
|
+
for stage_def in pipeline.get("stages", []):
|
|
974
|
+
stage_logs.append(StageLog(
|
|
975
|
+
name=stage_def["name"],
|
|
976
|
+
stage_type=stage_def["type"],
|
|
977
|
+
))
|
|
978
|
+
|
|
979
|
+
gov_tags = governance_tags or pipeline.get("governance", {}).get("tags", [])
|
|
980
|
+
|
|
981
|
+
run = PipelineRun(
|
|
982
|
+
run_id=run_id,
|
|
983
|
+
pipeline_id=pipeline_id,
|
|
984
|
+
pipeline_name=pipeline.get("name", ""),
|
|
985
|
+
tenant_id=tenant_id,
|
|
986
|
+
user_id=user_id,
|
|
987
|
+
graph=graph,
|
|
988
|
+
source=source,
|
|
989
|
+
source_type=source_type,
|
|
990
|
+
source_hash=source_hash,
|
|
991
|
+
params_used=merged_params,
|
|
992
|
+
status="pending",
|
|
993
|
+
started_at=now,
|
|
994
|
+
stages=[asdict(s) for s in stage_logs],
|
|
995
|
+
governance_tags=gov_tags,
|
|
996
|
+
data_classification=data_classification,
|
|
997
|
+
)
|
|
998
|
+
|
|
999
|
+
with self._get_conn() as conn:
|
|
1000
|
+
conn.execute(
|
|
1001
|
+
"""INSERT INTO pipeline_runs
|
|
1002
|
+
(run_id, pipeline_id, pipeline_name, tenant_id, user_id,
|
|
1003
|
+
graph, source, source_type, source_hash, params_used, status, started_at,
|
|
1004
|
+
stages_log, governance_tags, data_classification)
|
|
1005
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?, ?)""",
|
|
1006
|
+
(
|
|
1007
|
+
run_id, pipeline_id, run.pipeline_name, tenant_id, user_id,
|
|
1008
|
+
graph, source, source_type, source_hash, json.dumps(merged_params), now,
|
|
1009
|
+
json.dumps([asdict(s) for s in stage_logs]),
|
|
1010
|
+
json.dumps(gov_tags), data_classification,
|
|
1011
|
+
),
|
|
1012
|
+
)
|
|
1013
|
+
return run
|
|
1014
|
+
|
|
1015
|
+
def update_run_status(self, run_id: str, status: str, error: Optional[str] = None):
|
|
1016
|
+
"""Update overall run status."""
|
|
1017
|
+
now = datetime.now(timezone.utc).isoformat()
|
|
1018
|
+
with self._get_conn() as conn:
|
|
1019
|
+
if status in ("completed", "failed"):
|
|
1020
|
+
# Calculate duration
|
|
1021
|
+
row = conn.execute("SELECT started_at FROM pipeline_runs WHERE run_id = ?", (run_id,)).fetchone()
|
|
1022
|
+
duration_ms = 0
|
|
1023
|
+
if row and row["started_at"]:
|
|
1024
|
+
try:
|
|
1025
|
+
started = datetime.fromisoformat(row["started_at"])
|
|
1026
|
+
duration_ms = int((datetime.now(timezone.utc) - started).total_seconds() * 1000)
|
|
1027
|
+
except Exception:
|
|
1028
|
+
pass
|
|
1029
|
+
conn.execute(
|
|
1030
|
+
"""UPDATE pipeline_runs
|
|
1031
|
+
SET status=?, completed_at=?, duration_ms=?, error=?
|
|
1032
|
+
WHERE run_id=?""",
|
|
1033
|
+
(status, now, duration_ms, error, run_id),
|
|
1034
|
+
)
|
|
1035
|
+
else:
|
|
1036
|
+
conn.execute(
|
|
1037
|
+
"UPDATE pipeline_runs SET status=?, error=? WHERE run_id=?",
|
|
1038
|
+
(status, error, run_id),
|
|
1039
|
+
)
|
|
1040
|
+
|
|
1041
|
+
def update_stage(
|
|
1042
|
+
self,
|
|
1043
|
+
run_id: str,
|
|
1044
|
+
stage_name: str,
|
|
1045
|
+
status: str,
|
|
1046
|
+
items_processed: int = 0,
|
|
1047
|
+
items_created: int = 0,
|
|
1048
|
+
error: Optional[str] = None,
|
|
1049
|
+
metadata: Optional[Dict] = None,
|
|
1050
|
+
):
|
|
1051
|
+
"""Update a specific stage within a run."""
|
|
1052
|
+
now = datetime.now(timezone.utc).isoformat()
|
|
1053
|
+
with self._get_conn() as conn:
|
|
1054
|
+
row = conn.execute("SELECT stages_log FROM pipeline_runs WHERE run_id = ?", (run_id,)).fetchone()
|
|
1055
|
+
if not row:
|
|
1056
|
+
return
|
|
1057
|
+
stages = json.loads(row["stages_log"])
|
|
1058
|
+
for stage in stages:
|
|
1059
|
+
if stage["name"] == stage_name:
|
|
1060
|
+
stage["status"] = status
|
|
1061
|
+
if status == "running" and not stage.get("started_at"):
|
|
1062
|
+
stage["started_at"] = now
|
|
1063
|
+
if status in ("completed", "failed", "skipped"):
|
|
1064
|
+
stage["completed_at"] = now
|
|
1065
|
+
if stage.get("started_at"):
|
|
1066
|
+
try:
|
|
1067
|
+
s = datetime.fromisoformat(stage["started_at"])
|
|
1068
|
+
stage["duration_ms"] = int((datetime.now(timezone.utc) - s).total_seconds() * 1000)
|
|
1069
|
+
except Exception:
|
|
1070
|
+
pass
|
|
1071
|
+
stage["items_processed"] = items_processed or stage.get("items_processed", 0)
|
|
1072
|
+
stage["items_created"] = items_created or stage.get("items_created", 0)
|
|
1073
|
+
if error:
|
|
1074
|
+
stage["error"] = error
|
|
1075
|
+
if metadata:
|
|
1076
|
+
stage["metadata"] = {**stage.get("metadata", {}), **metadata}
|
|
1077
|
+
break
|
|
1078
|
+
|
|
1079
|
+
conn.execute(
|
|
1080
|
+
"UPDATE pipeline_runs SET stages_log = ? WHERE run_id = ?",
|
|
1081
|
+
(json.dumps(stages), run_id),
|
|
1082
|
+
)
|
|
1083
|
+
|
|
1084
|
+
def sync_stages_log(self, run_id: str, stage_results: list):
|
|
1085
|
+
"""Overwrite stages_log with the full list from PipelineContext.stage_results."""
|
|
1086
|
+
with self._get_conn() as conn:
|
|
1087
|
+
conn.execute(
|
|
1088
|
+
"UPDATE pipeline_runs SET stages_log = ? WHERE run_id = ?",
|
|
1089
|
+
(json.dumps(stage_results, default=str), run_id),
|
|
1090
|
+
)
|
|
1091
|
+
|
|
1092
|
+
def update_run_counts(self, run_id: str, nodes: int = 0, edges: int = 0, entities: int = 0):
|
|
1093
|
+
"""Update aggregate counts for a run."""
|
|
1094
|
+
with self._get_conn() as conn:
|
|
1095
|
+
conn.execute(
|
|
1096
|
+
"""UPDATE pipeline_runs
|
|
1097
|
+
SET nodes_created = ?, edges_created = ?, entities_extracted = ?
|
|
1098
|
+
WHERE run_id = ?""",
|
|
1099
|
+
(nodes, edges, entities, run_id),
|
|
1100
|
+
)
|
|
1101
|
+
|
|
1102
|
+
def set_accuracy(self, run_id: str, accuracy: AccuracyScore):
|
|
1103
|
+
"""Set extraction accuracy scores for a run."""
|
|
1104
|
+
accuracy.compute_overall()
|
|
1105
|
+
with self._get_conn() as conn:
|
|
1106
|
+
conn.execute(
|
|
1107
|
+
"""UPDATE pipeline_runs
|
|
1108
|
+
SET accuracy_score = ?, accuracy_breakdown = ?
|
|
1109
|
+
WHERE run_id = ?""",
|
|
1110
|
+
(accuracy.overall, json.dumps(asdict(accuracy)), run_id),
|
|
1111
|
+
)
|
|
1112
|
+
|
|
1113
|
+
def get_run(self, run_id: str) -> Optional[Dict]:
|
|
1114
|
+
"""Get a single run record."""
|
|
1115
|
+
with self._get_conn() as conn:
|
|
1116
|
+
row = conn.execute("SELECT * FROM pipeline_runs WHERE run_id = ?", (run_id,)).fetchone()
|
|
1117
|
+
return self._row_to_run(row) if row else None
|
|
1118
|
+
|
|
1119
|
+
def list_runs(
|
|
1120
|
+
self,
|
|
1121
|
+
tenant_id: str,
|
|
1122
|
+
pipeline_id: Optional[str] = None,
|
|
1123
|
+
graph: Optional[str] = None,
|
|
1124
|
+
status: Optional[str] = None,
|
|
1125
|
+
limit: int = 50,
|
|
1126
|
+
) -> List[Dict]:
|
|
1127
|
+
"""List pipeline runs with optional filters."""
|
|
1128
|
+
query = "SELECT * FROM pipeline_runs WHERE tenant_id = ?"
|
|
1129
|
+
params = [tenant_id]
|
|
1130
|
+
|
|
1131
|
+
if pipeline_id:
|
|
1132
|
+
query += " AND pipeline_id = ?"
|
|
1133
|
+
params.append(pipeline_id)
|
|
1134
|
+
if graph:
|
|
1135
|
+
query += " AND graph = ?"
|
|
1136
|
+
params.append(graph)
|
|
1137
|
+
if status:
|
|
1138
|
+
query += " AND status = ?"
|
|
1139
|
+
params.append(status)
|
|
1140
|
+
|
|
1141
|
+
query += " ORDER BY started_at DESC LIMIT ?"
|
|
1142
|
+
params.append(limit)
|
|
1143
|
+
|
|
1144
|
+
with self._get_conn() as conn:
|
|
1145
|
+
rows = conn.execute(query, params).fetchall()
|
|
1146
|
+
return [self._row_to_run(r) for r in rows]
|
|
1147
|
+
|
|
1148
|
+
def get_pipeline_stats(self, pipeline_id: str, tenant_id: str) -> Dict:
|
|
1149
|
+
"""Get aggregate stats for a pipeline."""
|
|
1150
|
+
with self._get_conn() as conn:
|
|
1151
|
+
row = conn.execute(
|
|
1152
|
+
"""SELECT
|
|
1153
|
+
COUNT(*) as total_runs,
|
|
1154
|
+
SUM(CASE WHEN status='completed' THEN 1 ELSE 0 END) as successful,
|
|
1155
|
+
SUM(CASE WHEN status='failed' THEN 1 ELSE 0 END) as failed,
|
|
1156
|
+
AVG(CASE WHEN status='completed' THEN duration_ms END) as avg_duration_ms,
|
|
1157
|
+
AVG(CASE WHEN status='completed' THEN accuracy_score END) as avg_accuracy,
|
|
1158
|
+
SUM(nodes_created) as total_nodes,
|
|
1159
|
+
SUM(edges_created) as total_edges,
|
|
1160
|
+
SUM(entities_extracted) as total_entities,
|
|
1161
|
+
MAX(started_at) as last_run_at
|
|
1162
|
+
FROM pipeline_runs
|
|
1163
|
+
WHERE pipeline_id = ? AND tenant_id = ?""",
|
|
1164
|
+
(pipeline_id, tenant_id),
|
|
1165
|
+
).fetchone()
|
|
1166
|
+
return dict(row) if row else {}
|
|
1167
|
+
|
|
1168
|
+
# ── Helpers ────────────────────────────────────────────────────────
|
|
1169
|
+
|
|
1170
|
+
def _row_to_pipeline(self, row) -> Dict:
|
|
1171
|
+
d = dict(row)
|
|
1172
|
+
for key in ("stages", "default_params", "governance", "tags", "filters", "graph_config"):
|
|
1173
|
+
if key in d and isinstance(d[key], str):
|
|
1174
|
+
d[key] = json.loads(d[key])
|
|
1175
|
+
d["builtin"] = bool(d.get("builtin", 0))
|
|
1176
|
+
d["enabled"] = bool(d.get("enabled", 1))
|
|
1177
|
+
# Ensure extended fields have defaults even if missing from older rows
|
|
1178
|
+
d.setdefault("schema_name", "")
|
|
1179
|
+
d.setdefault("parser", "")
|
|
1180
|
+
d.setdefault("filters", {})
|
|
1181
|
+
d.setdefault("graph_config", {})
|
|
1182
|
+
return d
|
|
1183
|
+
|
|
1184
|
+
def _row_to_run(self, row) -> Dict:
|
|
1185
|
+
d = dict(row)
|
|
1186
|
+
for key in ("params_used", "stages_log", "accuracy_breakdown", "governance_tags"):
|
|
1187
|
+
if key in d and isinstance(d[key], str):
|
|
1188
|
+
try:
|
|
1189
|
+
d[key] = json.loads(d[key])
|
|
1190
|
+
except Exception:
|
|
1191
|
+
pass
|
|
1192
|
+
# Rename stages_log → stages for API consistency
|
|
1193
|
+
if "stages_log" in d:
|
|
1194
|
+
d["stages"] = d.pop("stages_log")
|
|
1195
|
+
return d
|