infinity-context 0.1.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.
- infinity_context-0.1.0.dist-info/METADATA +239 -0
- infinity_context-0.1.0.dist-info/RECORD +1053 -0
- infinity_context-0.1.0.dist-info/WHEEL +5 -0
- infinity_context-0.1.0.dist-info/entry_points.txt +9 -0
- infinity_context-0.1.0.dist-info/licenses/LICENSE +201 -0
- infinity_context-0.1.0.dist-info/top_level.txt +8 -0
- infinity_context_adapters/__init__.py +1 -0
- infinity_context_adapters/cognee/__init__.py +5 -0
- infinity_context_adapters/cognee/adapter.py +364 -0
- infinity_context_adapters/embeddings/__init__.py +6 -0
- infinity_context_adapters/embeddings/noop_adapter.py +5 -0
- infinity_context_adapters/embeddings/openai_adapter.py +104 -0
- infinity_context_adapters/extraction/__init__.py +41 -0
- infinity_context_adapters/extraction/content.py +828 -0
- infinity_context_adapters/extraction/docling_engine.py +255 -0
- infinity_context_adapters/extraction/document_normalization.py +434 -0
- infinity_context_adapters/extraction/factory.py +69 -0
- infinity_context_adapters/extraction/fallback_context.py +137 -0
- infinity_context_adapters/extraction/file_detection.py +378 -0
- infinity_context_adapters/extraction/image_evidence.py +319 -0
- infinity_context_adapters/extraction/media_tools.py +579 -0
- infinity_context_adapters/extraction/openai_json.py +356 -0
- infinity_context_adapters/extraction/openai_vision.py +722 -0
- infinity_context_adapters/extraction/prompts/__init__.py +1 -0
- infinity_context_adapters/extraction/prompts/semantic_memory_v1.md +20 -0
- infinity_context_adapters/extraction/schemas/__init__.py +1 -0
- infinity_context_adapters/extraction/schemas/semantic_memory_v1.json +62 -0
- infinity_context_adapters/extraction/transcription/__init__.py +11 -0
- infinity_context_adapters/extraction/transcription/openai_adapter.py +400 -0
- infinity_context_adapters/extraction/transcription_engine.py +544 -0
- infinity_context_adapters/extraction/video_evidence.py +129 -0
- infinity_context_adapters/extraction/whisper_engine.py +386 -0
- infinity_context_adapters/features/__init__.py +7 -0
- infinity_context_adapters/features/context_building/__init__.py +53 -0
- infinity_context_adapters/features/context_building/candidate_provider_chain.py +68 -0
- infinity_context_adapters/features/context_building/graphiti_candidate_provider.py +44 -0
- infinity_context_adapters/features/context_building/in_memory_candidate_provider.py +62 -0
- infinity_context_adapters/features/context_building/postgres_candidate_provider.py +44 -0
- infinity_context_adapters/features/context_building/qdrant_candidate_provider.py +44 -0
- infinity_context_adapters/features/context_building/query_request.py +99 -0
- infinity_context_adapters/features/context_building/records.py +113 -0
- infinity_context_adapters/features/document_ingestion/__init__.py +74 -0
- infinity_context_adapters/features/document_ingestion/composition.py +69 -0
- infinity_context_adapters/features/document_ingestion/extraction_adapter.py +114 -0
- infinity_context_adapters/features/document_ingestion/in_memory_chunk_index.py +67 -0
- infinity_context_adapters/features/document_ingestion/in_memory_document_store.py +176 -0
- infinity_context_adapters/features/document_ingestion/postgres_document_store.py +110 -0
- infinity_context_adapters/features/document_ingestion/qdrant_chunk_index.py +49 -0
- infinity_context_adapters/features/document_ingestion/records.py +88 -0
- infinity_context_adapters/features/memory_facts/__init__.py +53 -0
- infinity_context_adapters/features/memory_facts/graphiti_fact_projection.py +111 -0
- infinity_context_adapters/features/memory_facts/in_memory_fact_store.py +200 -0
- infinity_context_adapters/features/memory_facts/postgres_fact_store.py +126 -0
- infinity_context_adapters/features/memory_facts/qdrant_fact_projection.py +100 -0
- infinity_context_adapters/features/memory_scopes/__init__.py +44 -0
- infinity_context_adapters/features/memory_scopes/in_memory_scope_store.py +189 -0
- infinity_context_adapters/features/memory_scopes/postgres_scope_store.py +121 -0
- infinity_context_adapters/features/memory_scopes/records.py +86 -0
- infinity_context_adapters/graphiti/__init__.py +5 -0
- infinity_context_adapters/graphiti/adapter.py +613 -0
- infinity_context_adapters/graphiti/identity_evidence.py +711 -0
- infinity_context_adapters/graphiti/scope_identity.py +31 -0
- infinity_context_adapters/local_blob.py +101 -0
- infinity_context_adapters/noop/__init__.py +16 -0
- infinity_context_adapters/noop/adapters.py +156 -0
- infinity_context_adapters/noop/runtime.py +21 -0
- infinity_context_adapters/postgres/__init__.py +19 -0
- infinity_context_adapters/postgres/asset_mappers.py +348 -0
- infinity_context_adapters/postgres/asset_repositories.py +865 -0
- infinity_context_adapters/postgres/benchmark_projection_schema.py +241 -0
- infinity_context_adapters/postgres/benchmark_run_completion.py +645 -0
- infinity_context_adapters/postgres/benchmark_run_repositories.py +908 -0
- infinity_context_adapters/postgres/benchmark_writer_fence.py +139 -0
- infinity_context_adapters/postgres/canonical_keyword_trigram.py +31 -0
- infinity_context_adapters/postgres/canonical_retrieval_batching.py +388 -0
- infinity_context_adapters/postgres/fact_repositories.py +766 -0
- infinity_context_adapters/postgres/mappers.py +745 -0
- infinity_context_adapters/postgres/migrations/0001_core_facts.sql +95 -0
- infinity_context_adapters/postgres/migrations/0002_threads_documents_chunks.sql +97 -0
- infinity_context_adapters/postgres/migrations/0003_suggestions.sql +24 -0
- infinity_context_adapters/postgres/migrations/0004_service_tokens.sql +16 -0
- infinity_context_adapters/postgres/migrations/0005_data_classification_lite.sql +8 -0
- infinity_context_adapters/postgres/migrations/0006_service_token_usage_metadata.sql +5 -0
- infinity_context_adapters/postgres/migrations/0007_service_token_permissions.sql +2 -0
- infinity_context_adapters/postgres/migrations/0008_service_token_memory_scope.sql +2 -0
- infinity_context_adapters/postgres/migrations/0009_outbox_lifecycle_hardening.sql +15 -0
- infinity_context_adapters/postgres/migrations/0010_fact_taxonomy.sql +14 -0
- infinity_context_adapters/postgres/migrations/0011_asset_extractions.sql +66 -0
- infinity_context_adapters/postgres/migrations/0012_asset_extraction_execution_hardening.sql +20 -0
- infinity_context_adapters/postgres/migrations/0012_usage_governance.sql +33 -0
- infinity_context_adapters/postgres/migrations/0013_context_link_suggestions.sql +44 -0
- infinity_context_adapters/postgres/migrations/0014_memory_anchors.sql +26 -0
- infinity_context_adapters/postgres/migrations/0015_users_acl.sql +36 -0
- infinity_context_adapters/postgres/migrations/0016_managed_benchmark_runs.sql +27 -0
- infinity_context_adapters/postgres/migrations/0017_managed_benchmark_writer_fence.sql +104 -0
- infinity_context_adapters/postgres/migrations/0018_benchmark_projection_manifest.sql +51 -0
- infinity_context_adapters/postgres/migrations/0019_managed_benchmark_sealed_fence.sql +131 -0
- infinity_context_adapters/postgres/migrations/0020_benchmark_cleanup_completion.sql +219 -0
- infinity_context_adapters/postgres/migrations/0021_benchmark_unsealed_abort.sql +64 -0
- infinity_context_adapters/postgres/migrations/0022_canonical_keyword_trigram.sql +5 -0
- infinity_context_adapters/postgres/models.py +878 -0
- infinity_context_adapters/postgres/projection_fence.py +80 -0
- infinity_context_adapters/postgres/repositories.py +906 -0
- infinity_context_adapters/postgres/repository_helpers.py +115 -0
- infinity_context_adapters/postgres/scope_repositories.py +540 -0
- infinity_context_adapters/postgres/unit_of_work.py +785 -0
- infinity_context_adapters/postgres/usage_repositories.py +128 -0
- infinity_context_adapters/postgres/user_repositories.py +164 -0
- infinity_context_adapters/provider_errors.py +73 -0
- infinity_context_adapters/qdrant/__init__.py +5 -0
- infinity_context_adapters/qdrant/identity_evidence.py +504 -0
- infinity_context_adapters/qdrant/vector_adapter.py +718 -0
- infinity_context_adapters/s3_blob.py +242 -0
- infinity_context_cli/__init__.py +5 -0
- infinity_context_cli/__main__.py +6 -0
- infinity_context_cli/cli.py +964 -0
- infinity_context_cli/config.py +184 -0
- infinity_context_cli/doctor.py +397 -0
- infinity_context_cli/local_experience.py +250 -0
- infinity_context_cli/mcp_config.py +124 -0
- infinity_context_cli/onboarding.py +542 -0
- infinity_context_cli/runtime.py +179 -0
- infinity_context_contracts/__init__.py +16 -0
- infinity_context_contracts/_json.py +32 -0
- infinity_context_contracts/capabilities.py +67 -0
- infinity_context_contracts/common.py +54 -0
- infinity_context_contracts/features/__init__.py +12 -0
- infinity_context_contracts/features/context_building.py +248 -0
- infinity_context_contracts/features/document_ingestion.py +277 -0
- infinity_context_contracts/features/memory_facts.py +236 -0
- infinity_context_contracts/features/memory_scopes.py +329 -0
- infinity_context_contracts/health.py +23 -0
- infinity_context_core/__init__.py +76 -0
- infinity_context_core/agent_behavior_contract.py +72 -0
- infinity_context_core/application/__init__.py +580 -0
- infinity_context_core/application/anchor_creative_work_filters.py +148 -0
- infinity_context_core/application/anchor_event_extraction.py +1571 -0
- infinity_context_core/application/anchor_extraction.py +1144 -0
- infinity_context_core/application/anchor_identity_normalization.py +90 -0
- infinity_context_core/application/anchor_relation_projection.py +203 -0
- infinity_context_core/application/anchor_temporal_window.py +172 -0
- infinity_context_core/application/asset_extraction_mapping.py +236 -0
- infinity_context_core/application/asset_upload_policy.py +952 -0
- infinity_context_core/application/auto_apply.py +72 -0
- infinity_context_core/application/auto_memory.py +527 -0
- infinity_context_core/application/capture_policy.py +61 -0
- infinity_context_core/application/chunker.py +93 -0
- infinity_context_core/application/context_action_role_evidence.py +890 -0
- infinity_context_core/application/context_action_role_labels.py +176 -0
- infinity_context_core/application/context_action_roles.py +2365 -0
- infinity_context_core/application/context_action_subject_policy.py +71 -0
- infinity_context_core/application/context_activity_companion.py +120 -0
- infinity_context_core/application/context_activity_duration_rerank.py +118 -0
- infinity_context_core/application/context_activity_participant_grounding.py +87 -0
- infinity_context_core/application/context_aggregation_answer_slots.py +586 -0
- infinity_context_core/application/context_aggregation_evidence_text.py +409 -0
- infinity_context_core/application/context_aggregation_rerank.py +145 -0
- infinity_context_core/application/context_aggregation_subject.py +137 -0
- infinity_context_core/application/context_allergy_condition_inference.py +146 -0
- infinity_context_core/application/context_anchor_identity.py +157 -0
- infinity_context_core/application/context_anchor_intent_ranking.py +84 -0
- infinity_context_core/application/context_anchor_relations.py +67 -0
- infinity_context_core/application/context_anchors.py +393 -0
- infinity_context_core/application/context_answer_evidence_types.py +14 -0
- infinity_context_core/application/context_answer_unit_shapes.py +207 -0
- infinity_context_core/application/context_artifact_evidence.py +893 -0
- infinity_context_core/application/context_attribution_lexicon.py +254 -0
- infinity_context_core/application/context_awareness_cause_rerank.py +109 -0
- infinity_context_core/application/context_baby_birth_evidence.py +91 -0
- infinity_context_core/application/context_birdwatching_schedule_rerank.py +130 -0
- infinity_context_core/application/context_bm25_ranking.py +450 -0
- infinity_context_core/application/context_book_author_preference_exact_turns.py +110 -0
- infinity_context_core/application/context_building_legacy_candidate_adapter.py +530 -0
- infinity_context_core/application/context_canonical_fact_retrieval.py +409 -0
- infinity_context_core/application/context_causal_reason_rerank.py +145 -0
- infinity_context_core/application/context_choice_reason_rerank.py +109 -0
- infinity_context_core/application/context_collectors.py +931 -0
- infinity_context_core/application/context_commonality_rerank.py +428 -0
- infinity_context_core/application/context_community_membership_inference.py +139 -0
- infinity_context_core/application/context_competition_count_exact_turns.py +383 -0
- infinity_context_core/application/context_conflicting_evidence_rerank.py +282 -0
- infinity_context_core/application/context_conversation_counterparty.py +260 -0
- infinity_context_core/application/context_count_cardinality.py +164 -0
- infinity_context_core/application/context_creative_work_count_exact_turns.py +517 -0
- infinity_context_core/application/context_diagnostics.py +55 -0
- infinity_context_core/application/context_diagnostics_bundle_keys.py +433 -0
- infinity_context_core/application/context_diagnostics_bundle_projection.py +711 -0
- infinity_context_core/application/context_diagnostics_item_projection.py +410 -0
- infinity_context_core/application/context_diagnostics_primitives.py +131 -0
- infinity_context_core/application/context_diagnostics_ranking.py +143 -0
- infinity_context_core/application/context_diagnostics_signals.py +209 -0
- infinity_context_core/application/context_diagnostics_sources.py +82 -0
- infinity_context_core/application/context_dialogue_authority.py +382 -0
- infinity_context_core/application/context_distinct_set_evidence.py +994 -0
- infinity_context_core/application/context_distinct_set_selection.py +335 -0
- infinity_context_core/application/context_domain_rerank_apply.py +310 -0
- infinity_context_core/application/context_domain_rerank_signals.py +2391 -0
- infinity_context_core/application/context_domain_rerank_types.py +14 -0
- infinity_context_core/application/context_english_activity_displacement_answer_support.py +128 -0
- infinity_context_core/application/context_english_lifestyle_inference.py +122 -0
- infinity_context_core/application/context_english_lifestyle_inference_answer_support.py +291 -0
- infinity_context_core/application/context_english_temporal_dates.py +53 -0
- infinity_context_core/application/context_evidence_priority.py +262 -0
- infinity_context_core/application/context_evidence_reservation_safety.py +208 -0
- infinity_context_core/application/context_exercise_performance_rerank.py +71 -0
- infinity_context_core/application/context_food_inventory_exact_turns.py +583 -0
- infinity_context_core/application/context_frequency_rerank.py +109 -0
- infinity_context_core/application/context_future_plan_timing_rerank.py +110 -0
- infinity_context_core/application/context_generic_behavior_inference.py +348 -0
- infinity_context_core/application/context_geo_residence_aliases.py +149 -0
- infinity_context_core/application/context_hydration.py +329 -0
- infinity_context_core/application/context_identity_fact_rerank.py +362 -0
- infinity_context_core/application/context_identity_rerank.py +76 -0
- infinity_context_core/application/context_identity_terms.py +15 -0
- infinity_context_core/application/context_inference_evidence.py +484 -0
- infinity_context_core/application/context_inference_evidence_terms.py +744 -0
- infinity_context_core/application/context_internal_diagnostics.py +61 -0
- infinity_context_core/application/context_item_evidence.py +108 -0
- infinity_context_core/application/context_item_purchase_evidence.py +49 -0
- infinity_context_core/application/context_keyword_aggregation_prefilter.py +63 -0
- infinity_context_core/application/context_keyword_ranking.py +178 -0
- infinity_context_core/application/context_lexical.py +750 -0
- infinity_context_core/application/context_lifecycle_rerank.py +502 -0
- infinity_context_core/application/context_link_candidate_policy.py +864 -0
- infinity_context_core/application/context_link_expansion.py +727 -0
- infinity_context_core/application/context_link_expansion_items.py +441 -0
- infinity_context_core/application/context_link_policy.py +451 -0
- infinity_context_core/application/context_link_source_enrichment.py +120 -0
- infinity_context_core/application/context_media_time.py +368 -0
- infinity_context_core/application/context_museum_visit_policy.py +66 -0
- infinity_context_core/application/context_named_person_preference.py +313 -0
- infinity_context_core/application/context_national_park_inference.py +93 -0
- infinity_context_core/application/context_object_attribute_rerank.py +416 -0
- infinity_context_core/application/context_object_mismatch.py +63 -0
- infinity_context_core/application/context_occupational_role_identity.py +961 -0
- infinity_context_core/application/context_ordinal_sequence.py +134 -0
- infinity_context_core/application/context_owner_grounding.py +408 -0
- infinity_context_core/application/context_packer.py +858 -0
- infinity_context_core/application/context_packer_answer_slots.py +733 -0
- infinity_context_core/application/context_packer_answer_support.py +3101 -0
- infinity_context_core/application/context_packer_answer_support_patterns.py +1267 -0
- infinity_context_core/application/context_packer_answer_support_slots.py +1209 -0
- infinity_context_core/application/context_packer_answer_support_utils.py +473 -0
- infinity_context_core/application/context_packer_diagnostics.py +48 -0
- infinity_context_core/application/context_packer_exact_literal_turns.py +697 -0
- infinity_context_core/application/context_packer_exact_prepasses.py +758 -0
- infinity_context_core/application/context_packer_exact_turn_utils.py +133 -0
- infinity_context_core/application/context_packer_identity_policy.py +155 -0
- infinity_context_core/application/context_packer_inference_reservation.py +113 -0
- infinity_context_core/application/context_packer_inventory_prepasses.py +359 -0
- infinity_context_core/application/context_packer_inventory_slots.py +771 -0
- infinity_context_core/application/context_packer_marker_coverage.py +409 -0
- infinity_context_core/application/context_packer_rendering.py +338 -0
- infinity_context_core/application/context_packer_selection.py +487 -0
- infinity_context_core/application/context_packer_source_policy.py +123 -0
- infinity_context_core/application/context_paired_evidence_requirements.py +78 -0
- infinity_context_core/application/context_paired_evidence_roles.py +64 -0
- infinity_context_core/application/context_person_activity_exact_turns.py +375 -0
- infinity_context_core/application/context_person_aliases.py +49 -0
- infinity_context_core/application/context_person_kinship.py +296 -0
- infinity_context_core/application/context_person_occupation.py +240 -0
- infinity_context_core/application/context_person_relation_inventory.py +755 -0
- infinity_context_core/application/context_person_residence.py +398 -0
- infinity_context_core/application/context_person_team_membership.py +305 -0
- infinity_context_core/application/context_pet_ownership.py +223 -0
- infinity_context_core/application/context_polarity_rerank.py +338 -0
- infinity_context_core/application/context_policy.py +107 -0
- infinity_context_core/application/context_political_inference.py +128 -0
- infinity_context_core/application/context_possession_source.py +161 -0
- infinity_context_core/application/context_precise_temporal_evidence.py +156 -0
- infinity_context_core/application/context_preference_goal_rerank.py +428 -0
- infinity_context_core/application/context_preference_inference.py +335 -0
- infinity_context_core/application/context_property_interaction_evidence.py +659 -0
- infinity_context_core/application/context_provider_retrieval_terms.py +95 -0
- infinity_context_core/application/context_quality.py +488 -0
- infinity_context_core/application/context_quantity_evidence_patterns.py +254 -0
- infinity_context_core/application/context_quantity_evidence_slots.py +750 -0
- infinity_context_core/application/context_quantity_pending_clothing.py +200 -0
- infinity_context_core/application/context_query_artifact_inventory_expansions.py +76 -0
- infinity_context_core/application/context_query_decomposition.py +879 -0
- infinity_context_core/application/context_query_decomposition_answer_policy.py +707 -0
- infinity_context_core/application/context_query_decomposition_contracts.py +28 -0
- infinity_context_core/application/context_query_decomposition_event_policy.py +535 -0
- infinity_context_core/application/context_query_decomposition_inventory_policy.py +767 -0
- infinity_context_core/application/context_query_decomposition_shared.py +300 -0
- infinity_context_core/application/context_query_duration.py +171 -0
- infinity_context_core/application/context_query_entity_relation_expansions.py +212 -0
- infinity_context_core/application/context_query_event_summary_expansions.py +80 -0
- infinity_context_core/application/context_query_expansion.py +200 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part1.py +1279 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part2.py +770 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part3.py +982 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part4.py +1334 -0
- infinity_context_core/application/context_query_expansion_rule_catalog_part5.py +517 -0
- infinity_context_core/application/context_query_expansion_rule_terms.py +269 -0
- infinity_context_core/application/context_query_expansion_rules.py +66 -0
- infinity_context_core/application/context_query_expansion_selection.py +892 -0
- infinity_context_core/application/context_query_financial_resources_inference.py +92 -0
- infinity_context_core/application/context_query_food_expansions.py +89 -0
- infinity_context_core/application/context_query_frequency.py +194 -0
- infinity_context_core/application/context_query_game_expansions.py +141 -0
- infinity_context_core/application/context_query_health_lifestyle_expansions.py +178 -0
- infinity_context_core/application/context_query_identity_terms.py +81 -0
- infinity_context_core/application/context_query_intent.py +33 -0
- infinity_context_core/application/context_query_intent_common.py +29 -0
- infinity_context_core/application/context_query_intent_contracts.py +92 -0
- infinity_context_core/application/context_query_intent_extraction.py +614 -0
- infinity_context_core/application/context_query_intent_keys.py +499 -0
- infinity_context_core/application/context_query_intent_matching.py +407 -0
- infinity_context_core/application/context_query_organization_summary_expansions.py +75 -0
- infinity_context_core/application/context_query_personal_fact_expansions.py +314 -0
- infinity_context_core/application/context_query_pet_activity_expansions.py +329 -0
- infinity_context_core/application/context_query_preference_expansions.py +97 -0
- infinity_context_core/application/context_query_project_summary_expansions.py +60 -0
- infinity_context_core/application/context_query_relevance_ranking.py +76 -0
- infinity_context_core/application/context_query_sports_expansions.py +48 -0
- infinity_context_core/application/context_query_state_transition.py +53 -0
- infinity_context_core/application/context_query_support_role.py +165 -0
- infinity_context_core/application/context_query_temporal_expansions.py +18 -0
- infinity_context_core/application/context_query_travel_expansions.py +134 -0
- infinity_context_core/application/context_query_vehicle_expansions.py +79 -0
- infinity_context_core/application/context_query_workflow_expansions.py +233 -0
- infinity_context_core/application/context_query_workflow_intent.py +65 -0
- infinity_context_core/application/context_quote_scanner.py +342 -0
- infinity_context_core/application/context_rank_dedupe.py +171 -0
- infinity_context_core/application/context_rank_fusion.py +191 -0
- infinity_context_core/application/context_ranked_activity_reservation.py +586 -0
- infinity_context_core/application/context_ranked_evidence_coverage_reservation.py +427 -0
- infinity_context_core/application/context_ranked_evidence_priority_reservation.py +37 -0
- infinity_context_core/application/context_ranked_evidence_selection.py +260 -0
- infinity_context_core/application/context_ranking.py +3681 -0
- infinity_context_core/application/context_ranking_reason_policy.py +31 -0
- infinity_context_core/application/context_ranking_reason_priorities.py +859 -0
- infinity_context_core/application/context_ranking_reason_scores.py +519 -0
- infinity_context_core/application/context_recommendation_answer_support.py +358 -0
- infinity_context_core/application/context_recommendation_exact_turns.py +360 -0
- infinity_context_core/application/context_relation_requirement.py +498 -0
- infinity_context_core/application/context_relationship_status_evidence.py +83 -0
- infinity_context_core/application/context_relative_duration_evidence.py +61 -0
- infinity_context_core/application/context_relevance.py +430 -0
- infinity_context_core/application/context_reported_obligation_attribution.py +416 -0
- infinity_context_core/application/context_reporting_frames.py +338 -0
- infinity_context_core/application/context_requirement_coverage.py +767 -0
- infinity_context_core/application/context_requirement_guard.py +503 -0
- infinity_context_core/application/context_requirement_patterns.py +943 -0
- infinity_context_core/application/context_requirement_ranking.py +181 -0
- infinity_context_core/application/context_requirement_signals.py +101 -0
- infinity_context_core/application/context_rerank_domain_heuristics.py +433 -0
- infinity_context_core/application/context_rerank_evidence_signals.py +400 -0
- infinity_context_core/application/context_rerank_relevance.py +131 -0
- infinity_context_core/application/context_retrieval_performance.py +153 -0
- infinity_context_core/application/context_review_items.py +338 -0
- infinity_context_core/application/context_score_signal_rerank.py +21 -0
- infinity_context_core/application/context_short_story_progress_evidence.py +119 -0
- infinity_context_core/application/context_snippets.py +545 -0
- infinity_context_core/application/context_social_education_inference.py +265 -0
- infinity_context_core/application/context_social_inventory_rerank.py +329 -0
- infinity_context_core/application/context_source_family.py +100 -0
- infinity_context_core/application/context_source_grounding.py +277 -0
- infinity_context_core/application/context_source_sibling_answer_evidence_repair.py +1983 -0
- infinity_context_core/application/context_source_sibling_contracts.py +35 -0
- infinity_context_core/application/context_source_sibling_evidence.py +405 -0
- infinity_context_core/application/context_source_sibling_evidence_rules.py +798 -0
- infinity_context_core/application/context_source_sibling_evidence_shared.py +449 -0
- infinity_context_core/application/context_source_sibling_identity.py +114 -0
- infinity_context_core/application/context_source_sibling_inventory_evidence.py +28 -0
- infinity_context_core/application/context_source_sibling_patterns.py +946 -0
- infinity_context_core/application/context_source_sibling_place_evidence.py +561 -0
- infinity_context_core/application/context_source_sibling_policy.py +988 -0
- infinity_context_core/application/context_source_sibling_scoring.py +721 -0
- infinity_context_core/application/context_source_siblings.py +363 -0
- infinity_context_core/application/context_speaker_attribution.py +574 -0
- infinity_context_core/application/context_speaker_disambiguation.py +108 -0
- infinity_context_core/application/context_stage_diagnostics.py +111 -0
- infinity_context_core/application/context_state_evidence.py +196 -0
- infinity_context_core/application/context_state_residence_inference.py +163 -0
- infinity_context_core/application/context_state_transition_pairing.py +401 -0
- infinity_context_core/application/context_temporal_answer_grounding.py +187 -0
- infinity_context_core/application/context_temporal_hints.py +485 -0
- infinity_context_core/application/context_temporal_intent_policy.py +146 -0
- infinity_context_core/application/context_temporal_interval_requirements.py +107 -0
- infinity_context_core/application/context_temporal_metadata.py +29 -0
- infinity_context_core/application/context_temporal_query.py +1358 -0
- infinity_context_core/application/context_temporal_ranges.py +471 -0
- infinity_context_core/application/context_temporal_session_order.py +439 -0
- infinity_context_core/application/context_temporal_source_identity.py +426 -0
- infinity_context_core/application/context_temporal_source_turn.py +1290 -0
- infinity_context_core/application/context_temporal_source_turn_labels.py +265 -0
- infinity_context_core/application/context_temporal_source_turn_patterns.py +186 -0
- infinity_context_core/application/context_temporal_source_turn_types.py +62 -0
- infinity_context_core/application/context_travel_hobby_writing_evidence.py +176 -0
- infinity_context_core/application/context_travel_place_evidence.py +23 -0
- infinity_context_core/application/document_fragments.py +206 -0
- infinity_context_core/application/document_text.py +203 -0
- infinity_context_core/application/dto.py +311 -0
- infinity_context_core/application/dto_anchors.py +143 -0
- infinity_context_core/application/dto_assets.py +234 -0
- infinity_context_core/application/dto_benchmark_runs.py +114 -0
- infinity_context_core/application/dto_context.py +176 -0
- infinity_context_core/application/dto_context_links.py +170 -0
- infinity_context_core/application/dto_facts.py +275 -0
- infinity_context_core/application/dto_suggestions_capture.py +199 -0
- infinity_context_core/application/dto_workspace.py +101 -0
- infinity_context_core/application/extraction_coordinates.py +56 -0
- infinity_context_core/application/extraction_resource_policy.py +796 -0
- infinity_context_core/application/extractor.py +147 -0
- infinity_context_core/application/memory_digest_renderer.py +215 -0
- infinity_context_core/application/multimodal_manifest.py +418 -0
- infinity_context_core/application/normalize.py +29 -0
- infinity_context_core/application/observed_anchor_resolution.py +243 -0
- infinity_context_core/application/related_facts.py +144 -0
- infinity_context_core/application/review_payloads.py +104 -0
- infinity_context_core/application/safe_payload.py +86 -0
- infinity_context_core/application/semantic_dedupe.py +943 -0
- infinity_context_core/application/sensitive_text.py +39 -0
- infinity_context_core/application/source_refs.py +263 -0
- infinity_context_core/application/storage_key_safety.py +13 -0
- infinity_context_core/application/temporal_validity.py +31 -0
- infinity_context_core/application/use_cases/__init__.py +1 -0
- infinity_context_core/application/use_cases/anchors.py +1165 -0
- infinity_context_core/application/use_cases/asset_extraction_support.py +273 -0
- infinity_context_core/application/use_cases/asset_extractions.py +1454 -0
- infinity_context_core/application/use_cases/assets.py +463 -0
- infinity_context_core/application/use_cases/benchmark_runs.py +877 -0
- infinity_context_core/application/use_cases/benchmark_unsealed_abort.py +147 -0
- infinity_context_core/application/use_cases/blob_storage_cleanup.py +289 -0
- infinity_context_core/application/use_cases/blob_storage_integrity.py +351 -0
- infinity_context_core/application/use_cases/build_context.py +995 -0
- infinity_context_core/application/use_cases/build_context_final_packing.py +59 -0
- infinity_context_core/application/use_cases/build_context_item_projection.py +839 -0
- infinity_context_core/application/use_cases/build_context_keyword_aggregation.py +908 -0
- infinity_context_core/application/use_cases/build_context_keyword_aggregation_seeds.py +132 -0
- infinity_context_core/application/use_cases/build_context_keyword_aggregation_selection.py +280 -0
- infinity_context_core/application/use_cases/build_context_keyword_aggregation_support.py +161 -0
- infinity_context_core/application/use_cases/build_context_requirement_guard.py +156 -0
- infinity_context_core/application/use_cases/build_context_source_selection.py +935 -0
- infinity_context_core/application/use_cases/build_memory_digest.py +203 -0
- infinity_context_core/application/use_cases/build_memory_insights.py +979 -0
- infinity_context_core/application/use_cases/consolidate_capture.py +806 -0
- infinity_context_core/application/use_cases/context_link_crud.py +196 -0
- infinity_context_core/application/use_cases/context_link_reviews.py +441 -0
- infinity_context_core/application/use_cases/context_link_suggestions.py +1060 -0
- infinity_context_core/application/use_cases/context_link_visibility.py +106 -0
- infinity_context_core/application/use_cases/context_links.py +33 -0
- infinity_context_core/application/use_cases/delete_document.py +71 -0
- infinity_context_core/application/use_cases/delete_thread_memory.py +55 -0
- infinity_context_core/application/use_cases/duplicate_merge_resolution.py +307 -0
- infinity_context_core/application/use_cases/ensure_scope.py +29 -0
- infinity_context_core/application/use_cases/expire_suggestions.py +36 -0
- infinity_context_core/application/use_cases/export_graph.py +684 -0
- infinity_context_core/application/use_cases/fact_relations.py +204 -0
- infinity_context_core/application/use_cases/forget_fact.py +43 -0
- infinity_context_core/application/use_cases/get_capabilities.py +213 -0
- infinity_context_core/application/use_cases/get_capture.py +16 -0
- infinity_context_core/application/use_cases/get_session_status.py +23 -0
- infinity_context_core/application/use_cases/ingest_document.py +376 -0
- infinity_context_core/application/use_cases/ingest_episode.py +263 -0
- infinity_context_core/application/use_cases/list_captures.py +25 -0
- infinity_context_core/application/use_cases/memory_browser.py +414 -0
- infinity_context_core/application/use_cases/operations_console.py +293 -0
- infinity_context_core/application/use_cases/process_document.py +83 -0
- infinity_context_core/application/use_cases/purge_capture.py +34 -0
- infinity_context_core/application/use_cases/query_documents.py +42 -0
- infinity_context_core/application/use_cases/query_facts.py +57 -0
- infinity_context_core/application/use_cases/receive_capture.py +238 -0
- infinity_context_core/application/use_cases/related_facts.py +47 -0
- infinity_context_core/application/use_cases/remember_fact.py +145 -0
- infinity_context_core/application/use_cases/spaces_memory_scopes.py +134 -0
- infinity_context_core/application/use_cases/suggestions.py +804 -0
- infinity_context_core/application/use_cases/update_fact.py +43 -0
- infinity_context_core/application/use_cases/usage.py +49 -0
- infinity_context_core/application/use_cases/users.py +138 -0
- infinity_context_core/domain/__init__.py +1 -0
- infinity_context_core/domain/aggregation_admission.py +200 -0
- infinity_context_core/domain/anchor_entities.py +316 -0
- infinity_context_core/domain/assets.py +654 -0
- infinity_context_core/domain/capture.py +321 -0
- infinity_context_core/domain/distinct_set_membership.py +69 -0
- infinity_context_core/domain/entities.py +103 -0
- infinity_context_core/domain/entity_policies.py +119 -0
- infinity_context_core/domain/entity_types.py +150 -0
- infinity_context_core/domain/errors.py +53 -0
- infinity_context_core/domain/events.py +14 -0
- infinity_context_core/domain/extraction.py +529 -0
- infinity_context_core/domain/idempotency.py +12 -0
- infinity_context_core/domain/memory_item_entities.py +426 -0
- infinity_context_core/domain/source_refs.py +91 -0
- infinity_context_core/domain/suggestion_entities.py +236 -0
- infinity_context_core/domain/taxonomy.py +121 -0
- infinity_context_core/domain/usage.py +221 -0
- infinity_context_core/domain/workspace_entities.py +269 -0
- infinity_context_core/features/__init__.py +7 -0
- infinity_context_core/features/context_building/__init__.py +3 -0
- infinity_context_core/features/context_building/application/__init__.py +92 -0
- infinity_context_core/features/context_building/application/candidate_fusion.py +136 -0
- infinity_context_core/features/context_building/application/coverage_reservation_selector.py +212 -0
- infinity_context_core/features/context_building/application/handlers.py +155 -0
- infinity_context_core/features/context_building/application/inference_evidence_reservation.py +592 -0
- infinity_context_core/features/context_building/application/provider_pipeline.py +61 -0
- infinity_context_core/features/context_building/application/queries.py +107 -0
- infinity_context_core/features/context_building/application/use_cases.py +78 -0
- infinity_context_core/features/context_building/domain/__init__.py +95 -0
- infinity_context_core/features/context_building/domain/budget.py +97 -0
- infinity_context_core/features/context_building/domain/context.py +157 -0
- infinity_context_core/features/context_building/domain/evidence_obligations.py +60 -0
- infinity_context_core/features/context_building/domain/feature.py +15 -0
- infinity_context_core/features/context_building/domain/prompt_sections.py +150 -0
- infinity_context_core/features/context_building/domain/query_pipeline.py +276 -0
- infinity_context_core/features/context_building/domain/rendering.py +102 -0
- infinity_context_core/features/context_building/ports/__init__.py +8 -0
- infinity_context_core/features/context_building/ports/candidates.py +36 -0
- infinity_context_core/features/context_building/public.py +165 -0
- infinity_context_core/features/context_building/tests/test_application_ports_public_skeleton.py +575 -0
- infinity_context_core/features/context_building/tests/test_domain_context_building_skeleton.py +402 -0
- infinity_context_core/features/document_ingestion/__init__.py +3 -0
- infinity_context_core/features/document_ingestion/application/__init__.py +31 -0
- infinity_context_core/features/document_ingestion/application/commands.py +62 -0
- infinity_context_core/features/document_ingestion/application/use_cases.py +273 -0
- infinity_context_core/features/document_ingestion/domain/__init__.py +61 -0
- infinity_context_core/features/document_ingestion/domain/chunking.py +297 -0
- infinity_context_core/features/document_ingestion/domain/errors.py +22 -0
- infinity_context_core/features/document_ingestion/domain/feature.py +18 -0
- infinity_context_core/features/document_ingestion/domain/source_document.py +228 -0
- infinity_context_core/features/document_ingestion/ports/__init__.py +21 -0
- infinity_context_core/features/document_ingestion/ports/indexing.py +51 -0
- infinity_context_core/features/document_ingestion/ports/repositories.py +56 -0
- infinity_context_core/features/document_ingestion/public.py +95 -0
- infinity_context_core/features/document_ingestion/tests/test_application_handlers.py +226 -0
- infinity_context_core/features/document_ingestion/tests/test_application_ports_public_skeleton.py +334 -0
- infinity_context_core/features/document_ingestion/tests/test_domain_chunking_skeleton.py +79 -0
- infinity_context_core/features/document_ingestion/tests/test_domain_source_document_skeleton.py +101 -0
- infinity_context_core/features/memory_facts/__init__.py +3 -0
- infinity_context_core/features/memory_facts/application/__init__.py +37 -0
- infinity_context_core/features/memory_facts/application/commands.py +89 -0
- infinity_context_core/features/memory_facts/application/handlers.py +241 -0
- infinity_context_core/features/memory_facts/application/use_cases.py +47 -0
- infinity_context_core/features/memory_facts/domain/__init__.py +35 -0
- infinity_context_core/features/memory_facts/domain/fact.py +98 -0
- infinity_context_core/features/memory_facts/domain/feature.py +15 -0
- infinity_context_core/features/memory_facts/ports/__init__.py +31 -0
- infinity_context_core/features/memory_facts/ports/clock.py +14 -0
- infinity_context_core/features/memory_facts/ports/ids.py +19 -0
- infinity_context_core/features/memory_facts/ports/outbox.py +26 -0
- infinity_context_core/features/memory_facts/ports/repositories.py +30 -0
- infinity_context_core/features/memory_facts/ports/unit_of_work.py +43 -0
- infinity_context_core/features/memory_facts/public.py +79 -0
- infinity_context_core/features/memory_facts/tests/test_application_handlers.py +332 -0
- infinity_context_core/features/memory_facts/tests/test_application_ports_public_skeleton.py +318 -0
- infinity_context_core/features/memory_facts/tests/test_domain_fact_skeleton.py +222 -0
- infinity_context_core/features/memory_scopes/__init__.py +3 -0
- infinity_context_core/features/memory_scopes/application/__init__.py +55 -0
- infinity_context_core/features/memory_scopes/application/commands.py +102 -0
- infinity_context_core/features/memory_scopes/application/errors.py +27 -0
- infinity_context_core/features/memory_scopes/application/handlers.py +226 -0
- infinity_context_core/features/memory_scopes/application/use_cases.py +68 -0
- infinity_context_core/features/memory_scopes/domain/__init__.py +59 -0
- infinity_context_core/features/memory_scopes/domain/errors.py +22 -0
- infinity_context_core/features/memory_scopes/domain/feature.py +18 -0
- infinity_context_core/features/memory_scopes/domain/policies.py +197 -0
- infinity_context_core/features/memory_scopes/domain/scope.py +178 -0
- infinity_context_core/features/memory_scopes/ports/__init__.py +25 -0
- infinity_context_core/features/memory_scopes/ports/clock.py +14 -0
- infinity_context_core/features/memory_scopes/ports/ids.py +13 -0
- infinity_context_core/features/memory_scopes/ports/repositories.py +40 -0
- infinity_context_core/features/memory_scopes/ports/unit_of_work.py +39 -0
- infinity_context_core/features/memory_scopes/public.py +111 -0
- infinity_context_core/features/memory_scopes/tests/test_application_ports_public_skeleton.py +824 -0
- infinity_context_core/features/memory_scopes/tests/test_domain_scope_skeleton.py +428 -0
- infinity_context_core/memory_scope_snapshot_preview.py +863 -0
- infinity_context_core/memory_scope_snapshots.py +206 -0
- infinity_context_core/ports/__init__.py +164 -0
- infinity_context_core/ports/adapters.py +217 -0
- infinity_context_core/ports/assets.py +270 -0
- infinity_context_core/ports/auth.py +68 -0
- infinity_context_core/ports/auto_memory.py +71 -0
- infinity_context_core/ports/benchmark_runs.py +205 -0
- infinity_context_core/ports/capabilities.py +324 -0
- infinity_context_core/ports/captures.py +53 -0
- infinity_context_core/ports/clock.py +11 -0
- infinity_context_core/ports/derived_projection_policy.py +72 -0
- infinity_context_core/ports/extraction.py +201 -0
- infinity_context_core/ports/graph_evidence.py +170 -0
- infinity_context_core/ports/ids.py +11 -0
- infinity_context_core/ports/projection_fence.py +27 -0
- infinity_context_core/ports/repositories.py +563 -0
- infinity_context_core/ports/transcription.py +63 -0
- infinity_context_core/ports/unit_of_work.py +77 -0
- infinity_context_core/ports/usage.py +36 -0
- infinity_context_core/ports/vector_projection_evidence.py +230 -0
- infinity_context_core/ports/vision.py +36 -0
- infinity_context_core/processes/__init__.py +3 -0
- infinity_context_core/processes/document_memory_pipeline/__init__.py +3 -0
- infinity_context_core/processes/document_memory_pipeline/contracts.py +44 -0
- infinity_context_core/processes/document_memory_pipeline/process.py +72 -0
- infinity_context_core/processes/document_memory_pipeline/public.py +21 -0
- infinity_context_core/reporting.py +105 -0
- infinity_context_mcp/__init__.py +5 -0
- infinity_context_mcp/__main__.py +6 -0
- infinity_context_mcp/adapters/__init__.py +1 -0
- infinity_context_mcp/adapters/http_gateway.py +940 -0
- infinity_context_mcp/agent_behavior_bench.py +1731 -0
- infinity_context_mcp/agent_behavior_bench_metrics.py +419 -0
- infinity_context_mcp/agent_behavior_bench_redaction.py +149 -0
- infinity_context_mcp/agent_behavior_bench_types.py +127 -0
- infinity_context_mcp/agent_behavior_scenarios.py +35 -0
- infinity_context_mcp/agent_behavior_scenarios_core.py +484 -0
- infinity_context_mcp/agent_behavior_scenarios_realistic.py +473 -0
- infinity_context_mcp/agent_behavior_scenarios_transcript.py +196 -0
- infinity_context_mcp/agent_behavior_transcripts.py +231 -0
- infinity_context_mcp/agent_behavior_types.py +66 -0
- infinity_context_mcp/agent_behavior_utils.py +29 -0
- infinity_context_mcp/application/__init__.py +1 -0
- infinity_context_mcp/application/context_link_review.py +109 -0
- infinity_context_mcp/application/local_runtime.py +473 -0
- infinity_context_mcp/application/normalization.py +36 -0
- infinity_context_mcp/application/obsidian.py +568 -0
- infinity_context_mcp/application/policy.py +160 -0
- infinity_context_mcp/application/ports.py +324 -0
- infinity_context_mcp/application/prepare.py +254 -0
- infinity_context_mcp/application/readiness.py +71 -0
- infinity_context_mcp/application/review_batch.py +62 -0
- infinity_context_mcp/application/service.py +701 -0
- infinity_context_mcp/application/service_base.py +29 -0
- infinity_context_mcp/application/service_constants.py +89 -0
- infinity_context_mcp/application/service_context_links.py +224 -0
- infinity_context_mcp/application/service_duplicates.py +62 -0
- infinity_context_mcp/application/service_facts.py +461 -0
- infinity_context_mcp/application/service_helpers.py +179 -0
- infinity_context_mcp/application/service_lifecycle.py +348 -0
- infinity_context_mcp/application/service_policy.py +74 -0
- infinity_context_mcp/application/service_query.py +384 -0
- infinity_context_mcp/application/service_resources.py +192 -0
- infinity_context_mcp/application/service_response.py +95 -0
- infinity_context_mcp/application/service_scope.py +132 -0
- infinity_context_mcp/application/service_suggestions.py +820 -0
- infinity_context_mcp/application/suggest_batch.py +71 -0
- infinity_context_mcp/application/usage_guide.py +74 -0
- infinity_context_mcp/bench.py +279 -0
- infinity_context_mcp/config.py +213 -0
- infinity_context_mcp/domain/__init__.py +1 -0
- infinity_context_mcp/domain/context_links.py +117 -0
- infinity_context_mcp/domain/local_runtime_models.py +56 -0
- infinity_context_mcp/domain/memory_browser.py +35 -0
- infinity_context_mcp/domain/models.py +1036 -0
- infinity_context_mcp/domain/obsidian_models.py +67 -0
- infinity_context_mcp/domain/policy.py +112 -0
- infinity_context_mcp/domain/prepare_models.py +24 -0
- infinity_context_mcp/plugin_hook.py +873 -0
- infinity_context_mcp/plugin_hook_settings.py +253 -0
- infinity_context_mcp/server.py +133 -0
- infinity_context_mcp/server_context_tools.py +404 -0
- infinity_context_mcp/server_fact_tools.py +928 -0
- infinity_context_mcp/server_hardening.py +54 -0
- infinity_context_mcp/server_local_runtime_tools.py +164 -0
- infinity_context_mcp/server_obsidian_tools.py +380 -0
- infinity_context_mcp/server_query_tools.py +626 -0
- infinity_context_mcp/server_request_mapping.py +73 -0
- infinity_context_mcp/server_resources.py +187 -0
- infinity_context_mcp/server_response.py +26 -0
- infinity_context_obsidian/__init__.py +5 -0
- infinity_context_obsidian/cli.py +594 -0
- infinity_context_obsidian/conflicts.py +110 -0
- infinity_context_obsidian/doctor.py +319 -0
- infinity_context_obsidian/domain.py +92 -0
- infinity_context_obsidian/frontmatter.py +68 -0
- infinity_context_obsidian/gateway.py +66 -0
- infinity_context_obsidian/layout.py +179 -0
- infinity_context_obsidian/note_format.py +159 -0
- infinity_context_obsidian/plugin_bundle/__init__.py +1 -0
- infinity_context_obsidian/plugin_bundle/main.js +5 -0
- infinity_context_obsidian/plugin_bundle/manifest.json +10 -0
- infinity_context_obsidian/plugin_bundle/styles.css +123 -0
- infinity_context_obsidian/plugin_install.py +139 -0
- infinity_context_obsidian/ports.py +72 -0
- infinity_context_obsidian/setup.py +202 -0
- infinity_context_obsidian/state.py +85 -0
- infinity_context_obsidian/sync.py +741 -0
- infinity_context_obsidian/vault.py +61 -0
- infinity_context_sdk/__init__.py +1049 -0
- infinity_context_sdk/_payloads.py +401 -0
- infinity_context_sdk/_redaction.py +31 -0
- infinity_context_sdk/anchors.py +249 -0
- infinity_context_sdk/assets.py +554 -0
- infinity_context_sdk/capabilities.py +199 -0
- infinity_context_sdk/context.py +540 -0
- infinity_context_sdk/context_bundle_diagnostics.py +905 -0
- infinity_context_sdk/context_payload_utils.py +219 -0
- infinity_context_sdk/export.py +123 -0
- infinity_context_sdk/scopes.py +74 -0
- infinity_context_sdk/thread_memory.py +55 -0
- infinity_context_server/__init__.py +5 -0
- infinity_context_server/__main__.py +19 -0
- infinity_context_server/admin.py +832 -0
- infinity_context_server/admin_invariants.py +388 -0
- infinity_context_server/admin_outbox.py +130 -0
- infinity_context_server/admin_projection_repair.py +374 -0
- infinity_context_server/api/__init__.py +1 -0
- infinity_context_server/api/auth.py +432 -0
- infinity_context_server/api/dependencies.py +9 -0
- infinity_context_server/api/errors.py +94 -0
- infinity_context_server/api/legacy_client.py +356 -0
- infinity_context_server/api/policy.py +35 -0
- infinity_context_server/api/public_payload.py +27 -0
- infinity_context_server/api/v1/__init__.py +54 -0
- infinity_context_server/api/v1/anchors.py +469 -0
- infinity_context_server/api/v1/assets.py +409 -0
- infinity_context_server/api/v1/capabilities.py +144 -0
- infinity_context_server/api/v1/captures.py +329 -0
- infinity_context_server/api/v1/context.py +362 -0
- infinity_context_server/api/v1/context_links.py +611 -0
- infinity_context_server/api/v1/diagnostics.py +333 -0
- infinity_context_server/api/v1/digest.py +107 -0
- infinity_context_server/api/v1/documents.py +164 -0
- infinity_context_server/api/v1/episodes.py +146 -0
- infinity_context_server/api/v1/export.py +184 -0
- infinity_context_server/api/v1/facts.py +265 -0
- infinity_context_server/api/v1/health.py +24 -0
- infinity_context_server/api/v1/insights.py +100 -0
- infinity_context_server/api/v1/internal_memory_comparison_runs.py +406 -0
- infinity_context_server/api/v1/memory_browser.py +183 -0
- infinity_context_server/api/v1/operations.py +81 -0
- infinity_context_server/api/v1/scope_resolution.py +389 -0
- infinity_context_server/api/v1/source_refs.py +111 -0
- infinity_context_server/api/v1/spaces_memory_scopes.py +141 -0
- infinity_context_server/api/v1/suggestions.py +237 -0
- infinity_context_server/api/v1/thread_memory.py +74 -0
- infinity_context_server/api/v1/usage.py +75 -0
- infinity_context_server/api/v1/users.py +164 -0
- infinity_context_server/auth_scope.py +492 -0
- infinity_context_server/auth_tokens.py +283 -0
- infinity_context_server/backpressure.py +47 -0
- infinity_context_server/benchmark_projection_absence.py +155 -0
- infinity_context_server/benchmark_projection_delete_outbox.py +162 -0
- infinity_context_server/composition.py +897 -0
- infinity_context_server/config.py +223 -0
- infinity_context_server/db.py +39 -0
- infinity_context_server/deployment_readiness.py +205 -0
- infinity_context_server/derived_identity_evidence.py +987 -0
- infinity_context_server/derived_identity_target.py +39 -0
- infinity_context_server/derived_projection_policy.py +85 -0
- infinity_context_server/diagnostics.py +536 -0
- infinity_context_server/doctor.py +71 -0
- infinity_context_server/eval.py +3066 -0
- infinity_context_server/eval_auto_memory.py +1735 -0
- infinity_context_server/eval_auto_memory_metrics.py +224 -0
- infinity_context_server/eval_auto_memory_types.py +75 -0
- infinity_context_server/eval_case_catalog.py +1590 -0
- infinity_context_server/eval_case_runner.py +1100 -0
- infinity_context_server/eval_common.py +336 -0
- infinity_context_server/eval_constants.py +310 -0
- infinity_context_server/eval_fixtures.py +150 -0
- infinity_context_server/eval_graph.py +92 -0
- infinity_context_server/eval_hybrid.py +99 -0
- infinity_context_server/eval_multimodal_offline.py +697 -0
- infinity_context_server/eval_prompt_contract.py +402 -0
- infinity_context_server/eval_scorecard.py +2627 -0
- infinity_context_server/eval_semantic_linking.py +1526 -0
- infinity_context_server/eval_semantic_retrieval_api_canary.py +405 -0
- infinity_context_server/eval_semantic_retrieval_canary.py +359 -0
- infinity_context_server/eval_types.py +88 -0
- infinity_context_server/evidence_bundle.py +523 -0
- infinity_context_server/extraction_capabilities.py +1234 -0
- infinity_context_server/features/__init__.py +3 -0
- infinity_context_server/features/context_building/__init__.py +5 -0
- infinity_context_server/features/context_building/benchmark_budget.py +29 -0
- infinity_context_server/features/context_building/composition.py +49 -0
- infinity_context_server/features/context_building/context_requests.py +151 -0
- infinity_context_server/features/context_building/contracts.py +96 -0
- infinity_context_server/features/context_building/digest_api_responses.py +225 -0
- infinity_context_server/features/context_building/digest_requests.py +65 -0
- infinity_context_server/features/context_building/insights_api_responses.py +132 -0
- infinity_context_server/features/context_building/legacy_api_responses.py +875 -0
- infinity_context_server/features/context_building/mappers.py +205 -0
- infinity_context_server/features/context_building/public.py +66 -0
- infinity_context_server/features/context_building/routes.py +44 -0
- infinity_context_server/features/document_ingestion/__init__.py +5 -0
- infinity_context_server/features/document_ingestion/asset_requests.py +45 -0
- infinity_context_server/features/document_ingestion/asset_responses.py +365 -0
- infinity_context_server/features/document_ingestion/composition.py +49 -0
- infinity_context_server/features/document_ingestion/contracts.py +104 -0
- infinity_context_server/features/document_ingestion/mappers.py +386 -0
- infinity_context_server/features/document_ingestion/public.py +58 -0
- infinity_context_server/features/document_ingestion/routes.py +44 -0
- infinity_context_server/features/memory_facts/__init__.py +7 -0
- infinity_context_server/features/memory_facts/compatibility.py +204 -0
- infinity_context_server/features/memory_facts/composition.py +72 -0
- infinity_context_server/features/memory_facts/contracts.py +187 -0
- infinity_context_server/features/memory_facts/mappers.py +620 -0
- infinity_context_server/features/memory_facts/public.py +168 -0
- infinity_context_server/features/memory_facts/routes.py +118 -0
- infinity_context_server/features/memory_facts/suggestion_requests.py +283 -0
- infinity_context_server/features/memory_facts/suggestion_responses.py +382 -0
- infinity_context_server/features/memory_scopes/__init__.py +5 -0
- infinity_context_server/features/memory_scopes/compatibility.py +231 -0
- infinity_context_server/features/memory_scopes/composition.py +49 -0
- infinity_context_server/features/memory_scopes/contracts.py +103 -0
- infinity_context_server/features/memory_scopes/graph_export_responses.py +93 -0
- infinity_context_server/features/memory_scopes/mappers.py +290 -0
- infinity_context_server/features/memory_scopes/public.py +136 -0
- infinity_context_server/features/memory_scopes/routes.py +185 -0
- infinity_context_server/features/memory_scopes/snapshot_compatibility.py +146 -0
- infinity_context_server/features/memory_scopes/thread_memory_requests.py +127 -0
- infinity_context_server/llm_provider_readiness.py +267 -0
- infinity_context_server/longmemeval_session_identity.py +167 -0
- infinity_context_server/main.py +68 -0
- infinity_context_server/mem0_benchmark_auth_challenge.py +160 -0
- infinity_context_server/memora_comparison.py +658 -0
- infinity_context_server/memory_comparison_answer_context.py +2442 -0
- infinity_context_server/memory_comparison_answer_context_backfill.py +1027 -0
- infinity_context_server/memory_comparison_answer_context_diagnostics.py +694 -0
- infinity_context_server/memory_comparison_answer_context_inspection.py +103 -0
- infinity_context_server/memory_comparison_answer_context_retrieval_slice.py +175 -0
- infinity_context_server/memory_comparison_answer_context_risks.py +223 -0
- infinity_context_server/memory_comparison_backend_target.py +41 -0
- infinity_context_server/memory_comparison_benchmark.py +651 -0
- infinity_context_server/memory_comparison_benchmark_compact.py +387 -0
- infinity_context_server/memory_comparison_benchmark_compact_fast_gate.py +387 -0
- infinity_context_server/memory_comparison_benchmark_compact_samples.py +931 -0
- infinity_context_server/memory_comparison_benchmark_config.py +105 -0
- infinity_context_server/memory_comparison_benchmark_control.py +215 -0
- infinity_context_server/memory_comparison_benchmark_execution.py +238 -0
- infinity_context_server/memory_comparison_benchmark_identity.py +65 -0
- infinity_context_server/memory_comparison_benchmark_metrics.py +686 -0
- infinity_context_server/memory_comparison_benchmark_replay.py +400 -0
- infinity_context_server/memory_comparison_benchmark_shared.py +284 -0
- infinity_context_server/memory_comparison_bounded_provider.py +295 -0
- infinity_context_server/memory_comparison_bundle_partial_support.py +107 -0
- infinity_context_server/memory_comparison_bundle_planner.py +3521 -0
- infinity_context_server/memory_comparison_bundle_source_windows.py +247 -0
- infinity_context_server/memory_comparison_candidate_features.py +2014 -0
- infinity_context_server/memory_comparison_candidate_fusion.py +893 -0
- infinity_context_server/memory_comparison_candidate_risks.py +124 -0
- infinity_context_server/memory_comparison_canonical_source_hash.py +109 -0
- infinity_context_server/memory_comparison_case_identity.py +100 -0
- infinity_context_server/memory_comparison_case_loader.py +123 -0
- infinity_context_server/memory_comparison_chat_completions.py +402 -0
- infinity_context_server/memory_comparison_clean_state.py +607 -0
- infinity_context_server/memory_comparison_clean_state_http.py +120 -0
- infinity_context_server/memory_comparison_clean_state_runner.py +103 -0
- infinity_context_server/memory_comparison_cli.py +295 -0
- infinity_context_server/memory_comparison_codex_canary.py +315 -0
- infinity_context_server/memory_comparison_codex_llm.py +345 -0
- infinity_context_server/memory_comparison_compact_gap_report.py +289 -0
- infinity_context_server/memory_comparison_comparative_preference.py +71 -0
- infinity_context_server/memory_comparison_conversation_ingestion.py +198 -0
- infinity_context_server/memory_comparison_evidence.py +877 -0
- infinity_context_server/memory_comparison_evidence_commitment.py +20 -0
- infinity_context_server/memory_comparison_failure_diagnostics.py +809 -0
- infinity_context_server/memory_comparison_full_canonical_evidence.py +746 -0
- infinity_context_server/memory_comparison_full_canonical_source_evidence_trust.py +450 -0
- infinity_context_server/memory_comparison_full_delete_evidence.py +670 -0
- infinity_context_server/memory_comparison_full_delete_evidence_trust.py +441 -0
- infinity_context_server/memory_comparison_full_delete_evidence_witnesses.py +308 -0
- infinity_context_server/memory_comparison_full_execution_validation.py +697 -0
- infinity_context_server/memory_comparison_full_execution_validation_slots.py +655 -0
- infinity_context_server/memory_comparison_full_methodology.py +556 -0
- infinity_context_server/memory_comparison_full_policy_component_validation.py +899 -0
- infinity_context_server/memory_comparison_full_profiles.py +398 -0
- infinity_context_server/memory_comparison_full_run_component_sets.py +304 -0
- infinity_context_server/memory_comparison_full_run_components.py +787 -0
- infinity_context_server/memory_comparison_full_run_evidence.py +759 -0
- infinity_context_server/memory_comparison_full_scope.py +244 -0
- infinity_context_server/memory_comparison_full_source_evidence.py +866 -0
- infinity_context_server/memory_comparison_full_verdict.py +252 -0
- infinity_context_server/memory_comparison_gold_blind.py +654 -0
- infinity_context_server/memory_comparison_gold_blind_answer_contract.py +492 -0
- infinity_context_server/memory_comparison_gold_blind_contract.py +760 -0
- infinity_context_server/memory_comparison_gold_blind_dispatch_models.py +34 -0
- infinity_context_server/memory_comparison_gold_blind_execution_validation.py +170 -0
- infinity_context_server/memory_comparison_gold_blind_judge_binding.py +167 -0
- infinity_context_server/memory_comparison_gold_blind_judge_capability.py +387 -0
- infinity_context_server/memory_comparison_gold_blind_retrieval_contract.py +413 -0
- infinity_context_server/memory_comparison_gold_blind_run_proof.py +880 -0
- infinity_context_server/memory_comparison_gold_blind_run_validation.py +109 -0
- infinity_context_server/memory_comparison_gold_blind_validation.py +319 -0
- infinity_context_server/memory_comparison_http.py +921 -0
- infinity_context_server/memory_comparison_http_ingest_observation.py +710 -0
- infinity_context_server/memory_comparison_http_ingest_request.py +204 -0
- infinity_context_server/memory_comparison_intent.py +2925 -0
- infinity_context_server/memory_comparison_latency.py +455 -0
- infinity_context_server/memory_comparison_llm.py +473 -0
- infinity_context_server/memory_comparison_location_roles.py +169 -0
- infinity_context_server/memory_comparison_locomo_cases.py +328 -0
- infinity_context_server/memory_comparison_locomo_expected_turn.py +297 -0
- infinity_context_server/memory_comparison_locomo_transport.py +873 -0
- infinity_context_server/memory_comparison_longmemeval_cases.py +339 -0
- infinity_context_server/memory_comparison_managed_attestation.py +771 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_abort_http.py +120 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_contracts.py +715 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_http.py +855 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_recovery_http.py +164 -0
- infinity_context_server/memory_comparison_managed_benchmark_registry_wire.py +890 -0
- infinity_context_server/memory_comparison_managed_composite_assembler.py +524 -0
- infinity_context_server/memory_comparison_managed_corpus_projection.py +653 -0
- infinity_context_server/memory_comparison_managed_execution_receipts.py +991 -0
- infinity_context_server/memory_comparison_managed_http_derived_evidence.py +724 -0
- infinity_context_server/memory_comparison_managed_http_exact_cleanup.py +476 -0
- infinity_context_server/memory_comparison_managed_http_execution.py +673 -0
- infinity_context_server/memory_comparison_managed_http_lifecycle.py +905 -0
- infinity_context_server/memory_comparison_managed_http_lifecycle_credentials.py +83 -0
- infinity_context_server/memory_comparison_managed_http_lifecycle_evidence.py +366 -0
- infinity_context_server/memory_comparison_managed_http_lifecycle_registration.py +106 -0
- infinity_context_server/memory_comparison_managed_http_policy_lifecycle.py +894 -0
- infinity_context_server/memory_comparison_managed_http_policy_material_projection.py +315 -0
- infinity_context_server/memory_comparison_managed_http_policy_receipts.py +219 -0
- infinity_context_server/memory_comparison_managed_http_policy_registry_evidence.py +177 -0
- infinity_context_server/memory_comparison_managed_http_policy_requirements.py +824 -0
- infinity_context_server/memory_comparison_managed_http_policy_support.py +108 -0
- infinity_context_server/memory_comparison_managed_http_policy_validation.py +762 -0
- infinity_context_server/memory_comparison_managed_ingest_manifest.py +449 -0
- infinity_context_server/memory_comparison_managed_live_admission.py +886 -0
- infinity_context_server/memory_comparison_managed_live_cli.py +536 -0
- infinity_context_server/memory_comparison_managed_live_composition.py +636 -0
- infinity_context_server/memory_comparison_managed_llm_execution.py +850 -0
- infinity_context_server/memory_comparison_managed_llm_execution_dispatch.py +269 -0
- infinity_context_server/memory_comparison_managed_llm_execution_ports.py +225 -0
- infinity_context_server/memory_comparison_managed_mem0_auth.py +65 -0
- infinity_context_server/memory_comparison_managed_mem0_runtime_authority.py +241 -0
- infinity_context_server/memory_comparison_managed_mem0_runtime_http.py +541 -0
- infinity_context_server/memory_comparison_managed_plan_builder.py +685 -0
- infinity_context_server/memory_comparison_managed_preflight.py +907 -0
- infinity_context_server/memory_comparison_managed_preflight_cli.py +431 -0
- infinity_context_server/memory_comparison_managed_production_cli.py +325 -0
- infinity_context_server/memory_comparison_managed_production_composition.py +140 -0
- infinity_context_server/memory_comparison_managed_production_ports.py +194 -0
- infinity_context_server/memory_comparison_managed_production_runner.py +450 -0
- infinity_context_server/memory_comparison_managed_projection_manifest.py +438 -0
- infinity_context_server/memory_comparison_managed_provider_calls.py +450 -0
- infinity_context_server/memory_comparison_managed_quality_projection.py +347 -0
- infinity_context_server/memory_comparison_managed_registry_policy_lifecycle.py +677 -0
- infinity_context_server/memory_comparison_managed_run.py +892 -0
- infinity_context_server/memory_comparison_managed_run_contract.py +454 -0
- infinity_context_server/memory_comparison_managed_run_ports.py +79 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials.py +916 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_capability.py +361 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_context.py +132 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_integrity.py +213 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_models.py +81 -0
- infinity_context_server/memory_comparison_managed_runtime_credentials_targets.py +28 -0
- infinity_context_server/memory_comparison_mem0_contract.py +491 -0
- infinity_context_server/memory_comparison_mem0_http_observation.py +296 -0
- infinity_context_server/memory_comparison_mem0_locomo_prompts.py +328 -0
- infinity_context_server/memory_comparison_mem0_longmemeval_prompts.py +365 -0
- infinity_context_server/memory_comparison_mem0_official_chat.py +504 -0
- infinity_context_server/memory_comparison_mem0_official_prompt_renderer.py +307 -0
- infinity_context_server/memory_comparison_mem0_oss_contract.py +456 -0
- infinity_context_server/memory_comparison_mem0_oss_manifest.py +563 -0
- infinity_context_server/memory_comparison_mem0_platform_contract.py +467 -0
- infinity_context_server/memory_comparison_mem0_runtime_attestation.py +861 -0
- infinity_context_server/memory_comparison_models.py +398 -0
- infinity_context_server/memory_comparison_openai_official_transport.py +525 -0
- infinity_context_server/memory_comparison_preflight.py +1147 -0
- infinity_context_server/memory_comparison_probe_transport.py +154 -0
- infinity_context_server/memory_comparison_prompt_policy.py +603 -0
- infinity_context_server/memory_comparison_provider_provenance.py +392 -0
- infinity_context_server/memory_comparison_quality_accessors.py +339 -0
- infinity_context_server/memory_comparison_quality_actionable_gaps.py +2038 -0
- infinity_context_server/memory_comparison_quality_answer_context_gaps.py +450 -0
- infinity_context_server/memory_comparison_quality_answer_context_risks.py +75 -0
- infinity_context_server/memory_comparison_quality_bundle_gaps.py +860 -0
- infinity_context_server/memory_comparison_quality_bundle_table.py +805 -0
- infinity_context_server/memory_comparison_quality_diagnostics.py +2798 -0
- infinity_context_server/memory_comparison_quality_fusion.py +241 -0
- infinity_context_server/memory_comparison_quality_query_plan_gaps.py +533 -0
- infinity_context_server/memory_comparison_quality_query_role_gaps.py +845 -0
- infinity_context_server/memory_comparison_quality_query_roles.py +815 -0
- infinity_context_server/memory_comparison_quality_rerank_gaps.py +492 -0
- infinity_context_server/memory_comparison_quality_selected_weakness.py +544 -0
- infinity_context_server/memory_comparison_quality_support.py +921 -0
- infinity_context_server/memory_comparison_query_integrity.py +301 -0
- infinity_context_server/memory_comparison_query_plan.py +524 -0
- infinity_context_server/memory_comparison_query_terms.py +2055 -0
- infinity_context_server/memory_comparison_relation_support.py +2100 -0
- infinity_context_server/memory_comparison_rerank.py +3209 -0
- infinity_context_server/memory_comparison_rerank_intents.py +405 -0
- infinity_context_server/memory_comparison_rerank_policies.py +1726 -0
- infinity_context_server/memory_comparison_rerank_policy.py +675 -0
- infinity_context_server/memory_comparison_rerank_shapes.py +152 -0
- infinity_context_server/memory_comparison_rerank_terms.py +973 -0
- infinity_context_server/memory_comparison_rerank_text.py +722 -0
- infinity_context_server/memory_comparison_retrieval_policy.py +108 -0
- infinity_context_server/memory_comparison_retrieval_width.py +383 -0
- infinity_context_server/memory_comparison_service_probe.py +278 -0
- infinity_context_server/memory_comparison_service_probes.py +547 -0
- infinity_context_server/memory_comparison_session_identity_contract.py +328 -0
- infinity_context_server/memory_comparison_source_identity.py +1655 -0
- infinity_context_server/memory_comparison_subscription_chat.py +717 -0
- infinity_context_server/memory_comparison_subscription_live_probe.py +323 -0
- infinity_context_server/memory_comparison_subscription_probe.py +368 -0
- infinity_context_server/memory_comparison_target_identity.py +42 -0
- infinity_context_server/memory_comparison_temporal_grounding.py +771 -0
- infinity_context_server/memory_comparison_token_budget_contract.py +665 -0
- infinity_context_server/memory_comparison_token_latency.py +136 -0
- infinity_context_server/memory_scope_transfer.py +933 -0
- infinity_context_server/memory_scope_transfer_assets.py +181 -0
- infinity_context_server/memory_scope_transfer_conflicts.py +565 -0
- infinity_context_server/memory_scope_transfer_context.py +295 -0
- infinity_context_server/memory_scope_transfer_extractions.py +390 -0
- infinity_context_server/memory_scope_transfer_facts.py +65 -0
- infinity_context_server/memory_scope_transfer_records.py +630 -0
- infinity_context_server/memory_scope_transfer_relations.py +84 -0
- infinity_context_server/memory_scope_transfer_remap.py +710 -0
- infinity_context_server/memory_scope_transfer_scope.py +267 -0
- infinity_context_server/memory_scope_transfer_support.py +108 -0
- infinity_context_server/memory_scope_transfer_temporal.py +24 -0
- infinity_context_server/metrics.py +264 -0
- infinity_context_server/official_public_benchmark.py +979 -0
- infinity_context_server/pagination.py +60 -0
- infinity_context_server/processes/__init__.py +38 -0
- infinity_context_server/processes/extractions.py +40 -0
- infinity_context_server/processes/outbox.py +47 -0
- infinity_context_server/processes/projections.py +372 -0
- infinity_context_server/provider_budget.py +59 -0
- infinity_context_server/provider_circuit.py +333 -0
- infinity_context_server/public_benchmark.py +2532 -0
- infinity_context_server/public_benchmark_artifacts.py +91 -0
- infinity_context_server/public_benchmark_case_diagnostics.py +231 -0
- infinity_context_server/public_benchmark_checkpoint.py +751 -0
- infinity_context_server/public_benchmark_environment.py +102 -0
- infinity_context_server/public_benchmark_execution.py +445 -0
- infinity_context_server/public_benchmark_http.py +39 -0
- infinity_context_server/public_benchmark_manifest.py +129 -0
- infinity_context_server/public_benchmark_metrics.py +645 -0
- infinity_context_server/public_benchmark_metrics_policy.py +117 -0
- infinity_context_server/public_benchmark_models.py +112 -0
- infinity_context_server/public_benchmark_progress.py +224 -0
- infinity_context_server/public_benchmark_results.py +76 -0
- infinity_context_server/public_benchmark_run_diagnostics.py +163 -0
- infinity_context_server/public_benchmark_selection.py +379 -0
- infinity_context_server/public_benchmark_transport.py +62 -0
- infinity_context_server/public_benchmark_unsupported.py +228 -0
- infinity_context_server/ranked_evidence_answer_support.py +665 -0
- infinity_context_server/ranked_evidence_document_seed_contract.py +30 -0
- infinity_context_server/ranked_evidence_evaluator_helpers.py +135 -0
- infinity_context_server/ranked_evidence_retrieval_request.py +36 -0
- infinity_context_server/ranked_evidence_seed_case.py +109 -0
- infinity_context_server/ranked_evidence_semantic_gate.py +980 -0
- infinity_context_server/ranked_evidence_semantic_gate_cli.py +137 -0
- infinity_context_server/ranked_evidence_semantic_gate_decision.py +163 -0
- infinity_context_server/ranked_evidence_semantic_metrics.py +375 -0
- infinity_context_server/ranked_evidence_session_identity.py +100 -0
- infinity_context_server/storage_maintenance.py +187 -0
- infinity_context_server/top_evidence_dataset_profile.py +442 -0
- infinity_context_server/top_evidence_policy.py +274 -0
- infinity_context_server/top_evidence_preflight.py +693 -0
- infinity_context_server/web/assets/memory-browser-capture.js +252 -0
- infinity_context_server/web/assets/memory-browser-operations.js +143 -0
- infinity_context_server/web/assets/memory-browser-review.js +687 -0
- infinity_context_server/web/assets/memory-browser.css +854 -0
- infinity_context_server/web/assets/memory-browser.js +3299 -0
- infinity_context_server/web/index.html +261 -0
- infinity_context_server/web_ui.py +29 -0
- infinity_context_server/worker.py +380 -0
|
@@ -0,0 +1,2798 @@
|
|
|
1
|
+
"""Aggregate quality diagnostics for memory-comparison benchmark reports."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from collections import Counter, defaultdict
|
|
7
|
+
from collections.abc import Mapping, Sequence
|
|
8
|
+
|
|
9
|
+
from infinity_context_server.memory_comparison_answer_context_risks import (
|
|
10
|
+
context_risk_reason_codes as _context_risk_reason_codes,
|
|
11
|
+
)
|
|
12
|
+
from infinity_context_server.memory_comparison_answer_context_risks import (
|
|
13
|
+
is_measured_low_answerability as _is_measured_low_answerability,
|
|
14
|
+
)
|
|
15
|
+
from infinity_context_server.memory_comparison_answer_context_risks import (
|
|
16
|
+
merge_risk_reason_codes as _merge_risk_reason_codes,
|
|
17
|
+
)
|
|
18
|
+
from infinity_context_server.memory_comparison_candidate_risks import (
|
|
19
|
+
payload_has_broad_summary,
|
|
20
|
+
payload_has_conflict_or_stale,
|
|
21
|
+
)
|
|
22
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
23
|
+
active_policy_reasons as _active_policy_reasons,
|
|
24
|
+
)
|
|
25
|
+
from infinity_context_server.memory_comparison_quality_accessors import avg as _avg
|
|
26
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
27
|
+
bundle_complete as _bundle_complete,
|
|
28
|
+
)
|
|
29
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
30
|
+
bundle_items as _bundle_items,
|
|
31
|
+
)
|
|
32
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
33
|
+
candidate_features as _candidate_features,
|
|
34
|
+
)
|
|
35
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
36
|
+
count_mapping as _count_mapping,
|
|
37
|
+
)
|
|
38
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
39
|
+
direct_source_refs_from_memory as _direct_source_refs_from_memory,
|
|
40
|
+
)
|
|
41
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
42
|
+
evidence_recall as _evidence_recall,
|
|
43
|
+
)
|
|
44
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
45
|
+
expected_recall as _expected_recall,
|
|
46
|
+
)
|
|
47
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
48
|
+
fusion_source_refs as _fusion_source_refs,
|
|
49
|
+
)
|
|
50
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
51
|
+
has_evidence_recall as _has_evidence_recall,
|
|
52
|
+
)
|
|
53
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
54
|
+
judgment_score as _judgment_score,
|
|
55
|
+
)
|
|
56
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
57
|
+
mapping as _mapping,
|
|
58
|
+
)
|
|
59
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
60
|
+
memory_diagnostics as _memory_diagnostics,
|
|
61
|
+
)
|
|
62
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
63
|
+
memory_id as _memory_id,
|
|
64
|
+
)
|
|
65
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
66
|
+
metric_value as _metric_value,
|
|
67
|
+
)
|
|
68
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
69
|
+
only_broad_bundle_evidence as _only_broad_bundle_evidence,
|
|
70
|
+
)
|
|
71
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
72
|
+
positive_int as _positive_int,
|
|
73
|
+
)
|
|
74
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
75
|
+
positive_policy_score as _positive_policy_score,
|
|
76
|
+
)
|
|
77
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
78
|
+
positive_signal_names as _positive_signal_names,
|
|
79
|
+
)
|
|
80
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
81
|
+
query_integrity as _query_integrity,
|
|
82
|
+
)
|
|
83
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
84
|
+
query_overlap_count as _query_overlap_count,
|
|
85
|
+
)
|
|
86
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
87
|
+
query_plan as _query_plan,
|
|
88
|
+
)
|
|
89
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
90
|
+
ratio as _ratio,
|
|
91
|
+
)
|
|
92
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
93
|
+
retrieval_metadata as _retrieval_metadata,
|
|
94
|
+
)
|
|
95
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
96
|
+
retrieval_results as _retrieval_results,
|
|
97
|
+
)
|
|
98
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
99
|
+
sequence as _sequence,
|
|
100
|
+
)
|
|
101
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
102
|
+
source_refs_from_bundle_item as _source_refs_from_bundle_item,
|
|
103
|
+
)
|
|
104
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
105
|
+
source_refs_from_memory as _source_refs_from_memory,
|
|
106
|
+
)
|
|
107
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
108
|
+
str_tuple as _str_tuple,
|
|
109
|
+
)
|
|
110
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
111
|
+
top_counts as _top_counts,
|
|
112
|
+
)
|
|
113
|
+
from infinity_context_server.memory_comparison_quality_accessors import (
|
|
114
|
+
top_signal_values as _top_signal_values,
|
|
115
|
+
)
|
|
116
|
+
from infinity_context_server.memory_comparison_quality_actionable_gaps import (
|
|
117
|
+
actionable_gap_summary as _actionable_gap_summary,
|
|
118
|
+
)
|
|
119
|
+
from infinity_context_server.memory_comparison_quality_answer_context_gaps import (
|
|
120
|
+
answer_context_support_gap_summary as _answer_context_support_gap_summary,
|
|
121
|
+
)
|
|
122
|
+
from infinity_context_server.memory_comparison_quality_answer_context_risks import (
|
|
123
|
+
answer_context_risk_sample as _answer_context_risk_sample,
|
|
124
|
+
)
|
|
125
|
+
from infinity_context_server.memory_comparison_quality_answer_context_risks import (
|
|
126
|
+
ranked_answer_context_risk_samples as _ranked_answer_context_risk_samples,
|
|
127
|
+
)
|
|
128
|
+
from infinity_context_server.memory_comparison_quality_bundle_gaps import (
|
|
129
|
+
bundle_gap_breakdown as _bundle_gap_breakdown,
|
|
130
|
+
)
|
|
131
|
+
from infinity_context_server.memory_comparison_quality_bundle_gaps import (
|
|
132
|
+
bundle_incomplete_diagnostics as _bundle_incomplete_diagnostics,
|
|
133
|
+
)
|
|
134
|
+
from infinity_context_server.memory_comparison_quality_bundle_gaps import (
|
|
135
|
+
evidence_bundle_gap_report as _evidence_bundle_gap_report,
|
|
136
|
+
)
|
|
137
|
+
from infinity_context_server.memory_comparison_quality_bundle_table import (
|
|
138
|
+
bundle_quality_failure_breakdown as _bundle_quality_failure_breakdown,
|
|
139
|
+
)
|
|
140
|
+
from infinity_context_server.memory_comparison_quality_bundle_table import (
|
|
141
|
+
bundle_quality_table as _bundle_quality_table,
|
|
142
|
+
)
|
|
143
|
+
from infinity_context_server.memory_comparison_quality_bundle_table import (
|
|
144
|
+
bundle_support_bundle_counts as _bundle_support_bundle_counts,
|
|
145
|
+
)
|
|
146
|
+
from infinity_context_server.memory_comparison_quality_bundle_table import (
|
|
147
|
+
bundle_support_counts as _bundle_support_counts,
|
|
148
|
+
)
|
|
149
|
+
from infinity_context_server.memory_comparison_quality_fusion import (
|
|
150
|
+
bundle_source_identity_summary as _bundle_source_identity_summary,
|
|
151
|
+
)
|
|
152
|
+
from infinity_context_server.memory_comparison_quality_fusion import (
|
|
153
|
+
bundle_source_proximity_summary as _bundle_source_proximity_summary,
|
|
154
|
+
)
|
|
155
|
+
from infinity_context_server.memory_comparison_quality_fusion import (
|
|
156
|
+
candidate_fusion_table as _candidate_fusion_table,
|
|
157
|
+
)
|
|
158
|
+
from infinity_context_server.memory_comparison_quality_query_plan_gaps import (
|
|
159
|
+
evidence_role_query_families as _evidence_role_query_families,
|
|
160
|
+
)
|
|
161
|
+
from infinity_context_server.memory_comparison_quality_query_plan_gaps import (
|
|
162
|
+
query_plan_gap_breakdown as _query_plan_gap_breakdown,
|
|
163
|
+
)
|
|
164
|
+
from infinity_context_server.memory_comparison_quality_query_role_gaps import (
|
|
165
|
+
query_role_gap_breakdown as _query_role_gap_breakdown,
|
|
166
|
+
)
|
|
167
|
+
from infinity_context_server.memory_comparison_quality_query_roles import (
|
|
168
|
+
query_role_effectiveness_table as _query_role_effectiveness_table,
|
|
169
|
+
)
|
|
170
|
+
from infinity_context_server.memory_comparison_quality_rerank_gaps import (
|
|
171
|
+
rerank_signal_gap_breakdown as _rerank_signal_gap_breakdown,
|
|
172
|
+
)
|
|
173
|
+
from infinity_context_server.memory_comparison_quality_selected_weakness import (
|
|
174
|
+
selected_evidence_weakness_breakdown as _selected_evidence_weakness_breakdown,
|
|
175
|
+
)
|
|
176
|
+
from infinity_context_server.memory_comparison_source_identity import (
|
|
177
|
+
looks_like_raw_source_ref as _looks_like_raw_source_ref,
|
|
178
|
+
)
|
|
179
|
+
from infinity_context_server.memory_comparison_source_identity import (
|
|
180
|
+
safe_item_id_for_output as _safe_item_id_for_output,
|
|
181
|
+
)
|
|
182
|
+
from infinity_context_server.memory_comparison_source_identity import (
|
|
183
|
+
safe_source_refs_for_output as _safe_source_refs_for_output,
|
|
184
|
+
)
|
|
185
|
+
from infinity_context_server.memory_comparison_source_identity import (
|
|
186
|
+
source_identity_refs_from_source_refs as _source_identity_refs_from_source_refs,
|
|
187
|
+
)
|
|
188
|
+
from infinity_context_server.memory_comparison_temporal_grounding import (
|
|
189
|
+
temporal_grounding_table as _temporal_grounding_table,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
_ANSWERABILITY_GAP_REASON_LIMIT = 6
|
|
193
|
+
_ANSWERABILITY_GAP_TEXT_VALUE_LIMIT = 120
|
|
194
|
+
_EVIDENCE_RECALL_GAP_SAMPLE_LIMIT = 10
|
|
195
|
+
_EVIDENCE_RECALL_MISSING_TERM_SAMPLE_LIMIT = 8
|
|
196
|
+
_ANSWER_CONTEXT_SAMPLE_IDENTITY_LIMIT = 8
|
|
197
|
+
_ANSWER_CONTEXT_SAMPLE_SOURCE_IDENTITY_ITEM_LIMIT = 3
|
|
198
|
+
_LOCOMO_TURN_REF_RE = re.compile(r"\bD\d+:\d+\b")
|
|
199
|
+
_LOCOMO_SESSION_TURN_IDENTITY_RE = re.compile(
|
|
200
|
+
r"^source_session_turn_refs:session_\d+:D\d+:\d+$",
|
|
201
|
+
re.IGNORECASE,
|
|
202
|
+
)
|
|
203
|
+
_LOCOMO_TURN_IDENTITY_RE = re.compile(
|
|
204
|
+
r"^source_turn_refs:D\d+:\d+$",
|
|
205
|
+
re.IGNORECASE,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def evidence_ref_rank_gate_metrics(
|
|
210
|
+
items: Sequence[Mapping[str, object]],
|
|
211
|
+
) -> dict[str, object]:
|
|
212
|
+
cutoffs = (1, 2, 3, 5)
|
|
213
|
+
cutoff_counts = {cutoff: 0 for cutoff in cutoffs}
|
|
214
|
+
focused_top5_count = 0
|
|
215
|
+
complete_count = 0
|
|
216
|
+
samples: list[dict[str, object]] = []
|
|
217
|
+
evidence_items = [
|
|
218
|
+
item
|
|
219
|
+
for item in items
|
|
220
|
+
if item.get("scored") is True
|
|
221
|
+
and _positive_int(_mapping(item.get("evidence_bundle")).get("evidence_term_count"))
|
|
222
|
+
]
|
|
223
|
+
for item in evidence_items:
|
|
224
|
+
bundle = _mapping(item.get("evidence_bundle"))
|
|
225
|
+
required_refs = _required_evidence_refs(item)
|
|
226
|
+
ref_positions, focused_ref_positions = _bundle_evidence_ref_positions(bundle)
|
|
227
|
+
complete = bool(required_refs) and all(ref in ref_positions for ref in required_refs)
|
|
228
|
+
if complete:
|
|
229
|
+
complete_count += 1
|
|
230
|
+
for cutoff in cutoffs:
|
|
231
|
+
if required_refs and all(
|
|
232
|
+
ref_positions.get(ref, 9999) <= cutoff for ref in required_refs
|
|
233
|
+
):
|
|
234
|
+
cutoff_counts[cutoff] += 1
|
|
235
|
+
if required_refs and all(
|
|
236
|
+
focused_ref_positions.get(ref, 9999) <= 5 for ref in required_refs
|
|
237
|
+
):
|
|
238
|
+
focused_top5_count += 1
|
|
239
|
+
if len(samples) < 10 and (
|
|
240
|
+
not complete or any(ref_positions.get(ref, 9999) > 5 for ref in required_refs)
|
|
241
|
+
):
|
|
242
|
+
samples.append(_evidence_ref_failure_sample(item, required_refs, ref_positions))
|
|
243
|
+
total = len(evidence_items)
|
|
244
|
+
return {
|
|
245
|
+
"evaluation_count": total,
|
|
246
|
+
"bundle_complete_count": complete_count,
|
|
247
|
+
"all_refs_top1_count": cutoff_counts[1],
|
|
248
|
+
"all_refs_top2_count": cutoff_counts[2],
|
|
249
|
+
"all_refs_top3_count": cutoff_counts[3],
|
|
250
|
+
"all_refs_top5_count": cutoff_counts[5],
|
|
251
|
+
"focused_refs_top5_count": focused_top5_count,
|
|
252
|
+
"all_refs_top1_rate": _ratio(cutoff_counts[1], total),
|
|
253
|
+
"all_refs_top2_rate": _ratio(cutoff_counts[2], total),
|
|
254
|
+
"all_refs_top3_rate": _ratio(cutoff_counts[3], total),
|
|
255
|
+
"all_refs_top5_rate": _ratio(cutoff_counts[5], total),
|
|
256
|
+
"focused_refs_top5_rate": _ratio(focused_top5_count, total),
|
|
257
|
+
"all_refs_top5_ok": bool(total) and cutoff_counts[5] == total,
|
|
258
|
+
"focused_refs_top5_ok": bool(total) and focused_top5_count == total,
|
|
259
|
+
"samples": samples,
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def quality_diagnostics(items: Sequence[Mapping[str, object]]) -> dict[str, object]:
|
|
264
|
+
bundle_incomplete = _bundle_incomplete_diagnostics(items)
|
|
265
|
+
bundle_gap_breakdown = _bundle_gap_breakdown(bundle_incomplete)
|
|
266
|
+
source_ref_provenance = _source_ref_provenance_table(items)
|
|
267
|
+
answer_context_provenance = _answer_context_provenance_table(items)
|
|
268
|
+
return {
|
|
269
|
+
"schema_version": "quality_diagnostics.v2",
|
|
270
|
+
"evaluation_count": len(items),
|
|
271
|
+
"per_intent": _per_intent_metrics(items),
|
|
272
|
+
"bundle_incomplete": bundle_incomplete,
|
|
273
|
+
"evidence_bundle_gap_report": _evidence_bundle_gap_report(
|
|
274
|
+
evaluation_count=sum(1 for item in items if item.get("scored") is True),
|
|
275
|
+
bundle_gap_breakdown=bundle_gap_breakdown,
|
|
276
|
+
source_ref_provenance=source_ref_provenance,
|
|
277
|
+
answer_context_provenance=answer_context_provenance,
|
|
278
|
+
),
|
|
279
|
+
"bundle_quality_table": _bundle_quality_table(items),
|
|
280
|
+
"evidence_recall_gap_summary": _evidence_recall_gap_summary(items),
|
|
281
|
+
"policy_contribution_table": _policy_contribution_table(items),
|
|
282
|
+
"evidence_feature_table": _evidence_feature_table(items),
|
|
283
|
+
"source_ref_provenance_table": source_ref_provenance,
|
|
284
|
+
"answer_context_provenance_table": answer_context_provenance,
|
|
285
|
+
"answer_context_support_gap_summary": _answer_context_support_gap_summary(
|
|
286
|
+
items
|
|
287
|
+
),
|
|
288
|
+
"temporal_grounding_table": _temporal_grounding_table(items),
|
|
289
|
+
"query_role_effectiveness_table": _query_role_effectiveness_table(items),
|
|
290
|
+
"query_plan_integrity_table": _query_plan_integrity_table(items),
|
|
291
|
+
"risk_flag_table": _risk_flag_table(items),
|
|
292
|
+
"rerank_lift_table": _rerank_lift_table(items),
|
|
293
|
+
"rerank_signal_gap_breakdown": _rerank_signal_gap_breakdown(items),
|
|
294
|
+
"false_positive_categories": _false_positive_categories(items),
|
|
295
|
+
"query_leakage_report": _query_leakage_report(items),
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def fast_gate_metrics(
|
|
300
|
+
items: Sequence[Mapping[str, object]],
|
|
301
|
+
*,
|
|
302
|
+
expected_case_count: int = 40,
|
|
303
|
+
) -> dict[str, object]:
|
|
304
|
+
expected_case_count = max(1, expected_case_count)
|
|
305
|
+
scored_count = sum(1 for item in items if item.get("scored") is True)
|
|
306
|
+
bundle_complete_count = sum(
|
|
307
|
+
1 for item in items if item.get("scored") is True and _bundle_complete(item)
|
|
308
|
+
)
|
|
309
|
+
ref_gate = evidence_ref_rank_gate_metrics(items)
|
|
310
|
+
query_overlap_count, profile_overlap_count, intent_overlap_count = (
|
|
311
|
+
_leakage_counts(items)
|
|
312
|
+
)
|
|
313
|
+
bundle_quality = _bundle_quality_table(items)
|
|
314
|
+
bundle_incomplete = _bundle_incomplete_diagnostics(items)
|
|
315
|
+
query_role_effectiveness = _query_role_effectiveness_table(items)
|
|
316
|
+
query_plan_integrity = _query_plan_integrity_table(items)
|
|
317
|
+
risk_flag_table = _risk_flag_table(items)
|
|
318
|
+
evidence_recall_gap_summary = _evidence_recall_gap_summary(items)
|
|
319
|
+
source_ref_provenance = _source_ref_provenance_table(items)
|
|
320
|
+
answer_context_provenance = _answer_context_provenance_table(items)
|
|
321
|
+
answer_context_support_gaps = _answer_context_support_gap_summary(items)
|
|
322
|
+
answerability_gap_breakdown = _answerability_gap_breakdown(items)
|
|
323
|
+
selected_evidence_weakness = _selected_evidence_weakness_breakdown(items)
|
|
324
|
+
temporal_grounding = _temporal_grounding_table(items)
|
|
325
|
+
candidate_fusion = _candidate_fusion_table(items)
|
|
326
|
+
rerank_signal_gaps = _rerank_signal_gap_breakdown(items)
|
|
327
|
+
query_role_gap_breakdown = _query_role_gap_breakdown(
|
|
328
|
+
query_role_effectiveness,
|
|
329
|
+
candidate_fusion_summary=candidate_fusion,
|
|
330
|
+
items=items,
|
|
331
|
+
)
|
|
332
|
+
query_plan_gap_breakdown = _query_plan_gap_breakdown(query_plan_integrity)
|
|
333
|
+
bundle_gap_breakdown = _bundle_gap_breakdown(bundle_incomplete)
|
|
334
|
+
bundle_quality_failure_breakdown = _bundle_quality_failure_breakdown(
|
|
335
|
+
bundle_quality,
|
|
336
|
+
expected_case_count=expected_case_count,
|
|
337
|
+
)
|
|
338
|
+
bundle_quality_count = _positive_int(bundle_quality.get("bundle_count")) or 0
|
|
339
|
+
medium_or_high_bundle_count = (
|
|
340
|
+
_positive_int(bundle_quality.get("medium_or_high_bundle_count")) or 0
|
|
341
|
+
)
|
|
342
|
+
gates = {
|
|
343
|
+
"case_count": _min_gate(scored_count, expected_case_count),
|
|
344
|
+
"query_profile_leakage_zero": _zero_gate(
|
|
345
|
+
query_overlap_count + profile_overlap_count + intent_overlap_count
|
|
346
|
+
),
|
|
347
|
+
"all_refs_top5": _min_gate(
|
|
348
|
+
_positive_int(ref_gate.get("all_refs_top5_count")) or 0,
|
|
349
|
+
expected_case_count,
|
|
350
|
+
),
|
|
351
|
+
"focused_refs_top5": _min_gate(
|
|
352
|
+
_positive_int(ref_gate.get("focused_refs_top5_count")) or 0,
|
|
353
|
+
expected_case_count,
|
|
354
|
+
),
|
|
355
|
+
"all_refs_top3": _min_gate(
|
|
356
|
+
_positive_int(ref_gate.get("all_refs_top3_count")) or 0,
|
|
357
|
+
max(0, expected_case_count - 1),
|
|
358
|
+
),
|
|
359
|
+
"all_refs_top2": _min_gate(
|
|
360
|
+
_positive_int(ref_gate.get("all_refs_top2_count")) or 0,
|
|
361
|
+
max(0, expected_case_count - 4),
|
|
362
|
+
),
|
|
363
|
+
"all_refs_top1": _min_gate(
|
|
364
|
+
_positive_int(ref_gate.get("all_refs_top1_count")) or 0,
|
|
365
|
+
max(0, expected_case_count - 10),
|
|
366
|
+
),
|
|
367
|
+
"evidence_bundle_complete": _min_gate(
|
|
368
|
+
bundle_complete_count,
|
|
369
|
+
expected_case_count,
|
|
370
|
+
),
|
|
371
|
+
"lifted_answerability_gaps_clear": _zero_gate(
|
|
372
|
+
_positive_int(
|
|
373
|
+
answerability_gap_breakdown.get("lifted_gap_candidate_count")
|
|
374
|
+
)
|
|
375
|
+
or 0
|
|
376
|
+
),
|
|
377
|
+
"query_plan_evidence_roles_clear": _zero_gate(
|
|
378
|
+
_positive_int(
|
|
379
|
+
query_plan_gap_breakdown.get(
|
|
380
|
+
"missing_evidence_role_query_family_total"
|
|
381
|
+
)
|
|
382
|
+
)
|
|
383
|
+
or 0
|
|
384
|
+
),
|
|
385
|
+
"selected_low_answerability_clear": _zero_gate(
|
|
386
|
+
_positive_int(
|
|
387
|
+
selected_evidence_weakness.get("low_answerability_item_count")
|
|
388
|
+
)
|
|
389
|
+
or 0
|
|
390
|
+
),
|
|
391
|
+
"selected_weak_source_locality_clear": _zero_gate(
|
|
392
|
+
_positive_int(
|
|
393
|
+
selected_evidence_weakness.get("weak_source_locality_item_count")
|
|
394
|
+
)
|
|
395
|
+
or 0
|
|
396
|
+
),
|
|
397
|
+
"selected_broad_summary_clear": _zero_gate(
|
|
398
|
+
_positive_int(
|
|
399
|
+
selected_evidence_weakness.get("broad_summary_item_count")
|
|
400
|
+
)
|
|
401
|
+
or 0
|
|
402
|
+
),
|
|
403
|
+
"selected_conflict_or_stale_clear": _zero_gate(
|
|
404
|
+
_positive_int(
|
|
405
|
+
selected_evidence_weakness.get("conflict_or_stale_item_count")
|
|
406
|
+
)
|
|
407
|
+
or 0
|
|
408
|
+
),
|
|
409
|
+
}
|
|
410
|
+
if bundle_quality_count:
|
|
411
|
+
gates["bundle_quality_present"] = _min_gate(
|
|
412
|
+
bundle_quality_count,
|
|
413
|
+
expected_case_count,
|
|
414
|
+
)
|
|
415
|
+
gates["bundle_quality_medium_or_high"] = _min_gate(
|
|
416
|
+
medium_or_high_bundle_count,
|
|
417
|
+
expected_case_count,
|
|
418
|
+
)
|
|
419
|
+
failed_gates = tuple(name for name, gate in gates.items() if not gate["passed"])
|
|
420
|
+
return {
|
|
421
|
+
"schema_version": "fast_gate.v1",
|
|
422
|
+
"expected_case_count": expected_case_count,
|
|
423
|
+
"evaluation_count": scored_count,
|
|
424
|
+
"evidence_ref_evaluation_count": ref_gate["evaluation_count"],
|
|
425
|
+
"passed": not failed_gates,
|
|
426
|
+
"ready_for_full_locomo": not failed_gates,
|
|
427
|
+
"failed_gates": list(failed_gates),
|
|
428
|
+
"query_overlap_count": query_overlap_count,
|
|
429
|
+
"profile_overlap_count": profile_overlap_count,
|
|
430
|
+
"bundle_quality_gate_applied": bool(bundle_quality_count),
|
|
431
|
+
"bundle_quality_count": bundle_quality_count,
|
|
432
|
+
"weak_bundle_count": _positive_int(bundle_quality.get("weak_bundle_count")) or 0,
|
|
433
|
+
"bundle_quality_failure_breakdown": bundle_quality_failure_breakdown,
|
|
434
|
+
"bundle_support_counts": _bundle_support_counts(bundle_quality),
|
|
435
|
+
"bundle_support_bundle_counts": _bundle_support_bundle_counts(bundle_quality),
|
|
436
|
+
"bundle_source_identity": _bundle_source_identity_summary(bundle_quality),
|
|
437
|
+
"bundle_source_proximity": _bundle_source_proximity_summary(bundle_quality),
|
|
438
|
+
"bundle_gap_breakdown": bundle_gap_breakdown,
|
|
439
|
+
"evidence_recall_gap_summary": evidence_recall_gap_summary,
|
|
440
|
+
"evidence_bundle_gap_report": _evidence_bundle_gap_report(
|
|
441
|
+
evaluation_count=scored_count,
|
|
442
|
+
bundle_gap_breakdown=bundle_gap_breakdown,
|
|
443
|
+
source_ref_provenance=source_ref_provenance,
|
|
444
|
+
answer_context_provenance=answer_context_provenance,
|
|
445
|
+
),
|
|
446
|
+
"answerability_gap_breakdown": answerability_gap_breakdown,
|
|
447
|
+
"selected_evidence_weakness": selected_evidence_weakness,
|
|
448
|
+
"query_role_gap_breakdown": query_role_gap_breakdown,
|
|
449
|
+
"query_plan_gap_breakdown": query_plan_gap_breakdown,
|
|
450
|
+
"source_ref_provenance": source_ref_provenance,
|
|
451
|
+
"answer_context_provenance": answer_context_provenance,
|
|
452
|
+
"answer_context_support_gap_summary": answer_context_support_gaps,
|
|
453
|
+
"temporal_grounding_table": temporal_grounding,
|
|
454
|
+
"candidate_fusion": candidate_fusion,
|
|
455
|
+
"rerank_signal_gap_breakdown": rerank_signal_gaps,
|
|
456
|
+
"risk_flag_table": risk_flag_table,
|
|
457
|
+
"actionable_gap_summary": _actionable_gap_summary(
|
|
458
|
+
evaluation_count=scored_count,
|
|
459
|
+
expected_case_count=expected_case_count,
|
|
460
|
+
failed_gates=failed_gates,
|
|
461
|
+
query_overlap_count=query_overlap_count,
|
|
462
|
+
profile_overlap_count=profile_overlap_count,
|
|
463
|
+
intent_overlap_count=intent_overlap_count,
|
|
464
|
+
ref_gate=ref_gate,
|
|
465
|
+
bundle_quality_failure_breakdown=bundle_quality_failure_breakdown,
|
|
466
|
+
bundle_gap_breakdown=bundle_gap_breakdown,
|
|
467
|
+
answerability_gap_breakdown=answerability_gap_breakdown,
|
|
468
|
+
selected_evidence_weakness=selected_evidence_weakness,
|
|
469
|
+
evidence_recall_gap_summary=evidence_recall_gap_summary,
|
|
470
|
+
query_role_gap_breakdown=query_role_gap_breakdown,
|
|
471
|
+
query_plan_gap_breakdown=query_plan_gap_breakdown,
|
|
472
|
+
rerank_signal_gap_breakdown=rerank_signal_gaps,
|
|
473
|
+
temporal_grounding=temporal_grounding,
|
|
474
|
+
source_ref_provenance=source_ref_provenance,
|
|
475
|
+
answer_context_provenance=answer_context_provenance,
|
|
476
|
+
answer_context_support_gap_summary=answer_context_support_gaps,
|
|
477
|
+
),
|
|
478
|
+
"gates": gates,
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def _per_intent_metrics(
|
|
483
|
+
items: Sequence[Mapping[str, object]],
|
|
484
|
+
) -> dict[str, dict[str, object]]:
|
|
485
|
+
groups: dict[str, list[Mapping[str, object]]] = defaultdict(list)
|
|
486
|
+
for item in items:
|
|
487
|
+
for key in _intent_keys(item):
|
|
488
|
+
groups[key].append(item)
|
|
489
|
+
return {
|
|
490
|
+
key: _intent_metric_payload(group_items)
|
|
491
|
+
for key, group_items in sorted(groups.items())
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def _intent_keys(item: Mapping[str, object]) -> tuple[str, ...]:
|
|
496
|
+
metadata = _retrieval_metadata(item)
|
|
497
|
+
payloads = _diagnostic_query_payloads(metadata)
|
|
498
|
+
evidence_need = _merged_payload_intent_values(payloads, "evidence_need")
|
|
499
|
+
bundle_evidence_roles = _merged_payload_intent_values(
|
|
500
|
+
payloads,
|
|
501
|
+
"bundle_evidence_roles",
|
|
502
|
+
)
|
|
503
|
+
relation_categories = tuple(
|
|
504
|
+
dict.fromkeys(
|
|
505
|
+
category
|
|
506
|
+
for payload in payloads
|
|
507
|
+
for category in (
|
|
508
|
+
_str_tuple(
|
|
509
|
+
_mapping(payload.get("query_profile")).get(
|
|
510
|
+
"relation_categories"
|
|
511
|
+
)
|
|
512
|
+
)
|
|
513
|
+
+ _relation_categories(_mapping(payload.get("retrieval_intent")))
|
|
514
|
+
)
|
|
515
|
+
)
|
|
516
|
+
)
|
|
517
|
+
time_kinds = tuple(
|
|
518
|
+
dict.fromkeys(
|
|
519
|
+
kind
|
|
520
|
+
for payload in payloads
|
|
521
|
+
for kind in (
|
|
522
|
+
str(
|
|
523
|
+
_mapping(
|
|
524
|
+
_mapping(payload.get("retrieval_intent")).get("time_intent")
|
|
525
|
+
).get("kind")
|
|
526
|
+
or ""
|
|
527
|
+
).strip(),
|
|
528
|
+
)
|
|
529
|
+
if kind and kind != "none"
|
|
530
|
+
)
|
|
531
|
+
)
|
|
532
|
+
keys = [f"need:{need}" for need in evidence_need]
|
|
533
|
+
keys.extend(f"role:{role}" for role in bundle_evidence_roles)
|
|
534
|
+
keys.extend(f"relation:{category}" for category in relation_categories)
|
|
535
|
+
keys.extend(f"time:{time_kind}" for time_kind in time_kinds)
|
|
536
|
+
if not keys:
|
|
537
|
+
keys.append("need:unknown")
|
|
538
|
+
return tuple(dict.fromkeys(keys))
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
def _relation_categories(intent: Mapping[str, object]) -> tuple[str, ...]:
|
|
542
|
+
relations = _mapping(intent.get("relations"))
|
|
543
|
+
categories: list[str] = []
|
|
544
|
+
for relation_intent in _sequence(relations.get("intents")):
|
|
545
|
+
payload = _mapping(relation_intent)
|
|
546
|
+
category = str(payload.get("category") or "").strip()
|
|
547
|
+
if category:
|
|
548
|
+
categories.append(category)
|
|
549
|
+
return tuple(dict.fromkeys(categories))
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def _merged_payload_intent_values(
|
|
553
|
+
payloads: Sequence[Mapping[str, object]],
|
|
554
|
+
key: str,
|
|
555
|
+
) -> tuple[str, ...]:
|
|
556
|
+
return tuple(
|
|
557
|
+
dict.fromkeys(
|
|
558
|
+
value
|
|
559
|
+
for payload in payloads
|
|
560
|
+
for value in (
|
|
561
|
+
_str_tuple(_mapping(payload.get("query_profile")).get(key))
|
|
562
|
+
+ _str_tuple(_mapping(payload.get("retrieval_intent")).get(key))
|
|
563
|
+
)
|
|
564
|
+
)
|
|
565
|
+
)
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
def _intent_metric_payload(items: Sequence[Mapping[str, object]]) -> dict[str, object]:
|
|
569
|
+
scored = [item for item in items if item.get("scored") is True]
|
|
570
|
+
passed = sum(1 for item in scored if _judgment_score(item) >= 1.0)
|
|
571
|
+
return {
|
|
572
|
+
"total": len(items),
|
|
573
|
+
"scored": len(scored),
|
|
574
|
+
"passed": passed,
|
|
575
|
+
"accuracy": _ratio(passed, len(scored)),
|
|
576
|
+
"avg_expected_term_recall": _avg(_expected_recall(item) for item in scored),
|
|
577
|
+
"avg_evidence_term_recall": _avg(
|
|
578
|
+
_evidence_recall(item)
|
|
579
|
+
for item in scored
|
|
580
|
+
if "evidence_term_recall" in _mapping(item.get("retrieval_quality"))
|
|
581
|
+
),
|
|
582
|
+
"bundle_complete_rate": _ratio(
|
|
583
|
+
sum(1 for item in scored if _bundle_complete(item)),
|
|
584
|
+
len(scored),
|
|
585
|
+
),
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
def _evidence_recall_gap_summary(
|
|
590
|
+
items: Sequence[Mapping[str, object]],
|
|
591
|
+
) -> dict[str, object]:
|
|
592
|
+
scored = [item for item in items if item.get("scored") is True]
|
|
593
|
+
measured = [item for item in scored if _has_evidence_recall(item)]
|
|
594
|
+
missing_ref_items = [
|
|
595
|
+
item
|
|
596
|
+
for item in scored
|
|
597
|
+
if _str_tuple(
|
|
598
|
+
_mapping(item.get("retrieval_quality")).get("missing_evidence_terms")
|
|
599
|
+
)
|
|
600
|
+
]
|
|
601
|
+
weak_recall_items = [item for item in measured if _evidence_recall(item) < 1.0]
|
|
602
|
+
gap_items = _dedupe_items((*missing_ref_items, *weak_recall_items))
|
|
603
|
+
missing_term_counts: Counter[str] = Counter()
|
|
604
|
+
for item in missing_ref_items:
|
|
605
|
+
missing_term_counts.update(
|
|
606
|
+
_safe_evidence_ref_terms(
|
|
607
|
+
_mapping(item.get("retrieval_quality")).get(
|
|
608
|
+
"missing_evidence_terms"
|
|
609
|
+
)
|
|
610
|
+
)
|
|
611
|
+
)
|
|
612
|
+
return {
|
|
613
|
+
"schema_version": "evidence_recall_gap_summary.v1",
|
|
614
|
+
"evaluation_count": len(scored),
|
|
615
|
+
"measured_evidence_recall_count": len(measured),
|
|
616
|
+
"missing_evidence_ref_case_count": len(missing_ref_items),
|
|
617
|
+
"weak_evidence_recall_case_count": len(weak_recall_items),
|
|
618
|
+
"zero_evidence_recall_case_count": sum(
|
|
619
|
+
1 for item in measured if _evidence_recall(item) <= 0
|
|
620
|
+
),
|
|
621
|
+
"avg_expected_term_recall": _avg(_expected_recall(item) for item in scored),
|
|
622
|
+
"avg_evidence_term_recall": _avg(_evidence_recall(item) for item in measured),
|
|
623
|
+
"top_missing_evidence_terms": _top_counts(missing_term_counts, limit=10),
|
|
624
|
+
"samples": _evidence_recall_gap_samples(gap_items),
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def _dedupe_items(
|
|
629
|
+
items: Sequence[Mapping[str, object]],
|
|
630
|
+
) -> tuple[Mapping[str, object], ...]:
|
|
631
|
+
deduped: list[Mapping[str, object]] = []
|
|
632
|
+
seen: set[int] = set()
|
|
633
|
+
for item in items:
|
|
634
|
+
key = id(item)
|
|
635
|
+
if key in seen:
|
|
636
|
+
continue
|
|
637
|
+
seen.add(key)
|
|
638
|
+
deduped.append(item)
|
|
639
|
+
return tuple(deduped)
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
def _evidence_recall_gap_samples(
|
|
643
|
+
items: Sequence[Mapping[str, object]],
|
|
644
|
+
) -> list[dict[str, object]]:
|
|
645
|
+
samples: list[dict[str, object]] = []
|
|
646
|
+
for item in sorted(
|
|
647
|
+
items,
|
|
648
|
+
key=lambda item: (
|
|
649
|
+
0
|
|
650
|
+
if _str_tuple(
|
|
651
|
+
_mapping(item.get("retrieval_quality")).get(
|
|
652
|
+
"missing_evidence_terms"
|
|
653
|
+
)
|
|
654
|
+
)
|
|
655
|
+
else 1,
|
|
656
|
+
_evidence_recall(item) if _has_evidence_recall(item) else 1.0,
|
|
657
|
+
-len(
|
|
658
|
+
_str_tuple(
|
|
659
|
+
_mapping(item.get("retrieval_quality")).get(
|
|
660
|
+
"missing_evidence_terms"
|
|
661
|
+
)
|
|
662
|
+
)
|
|
663
|
+
),
|
|
664
|
+
str(item.get("case_id") or ""),
|
|
665
|
+
),
|
|
666
|
+
)[:_EVIDENCE_RECALL_GAP_SAMPLE_LIMIT]:
|
|
667
|
+
quality = _mapping(item.get("retrieval_quality"))
|
|
668
|
+
measured = _has_evidence_recall(item)
|
|
669
|
+
missing_terms = _str_tuple(quality.get("missing_evidence_terms"))
|
|
670
|
+
sample_missing_terms = _safe_evidence_ref_terms(
|
|
671
|
+
missing_terms[:_EVIDENCE_RECALL_MISSING_TERM_SAMPLE_LIMIT]
|
|
672
|
+
)
|
|
673
|
+
sample: dict[str, object] = {
|
|
674
|
+
"case_id": str(item.get("case_id") or ""),
|
|
675
|
+
"group": str(item.get("group") or ""),
|
|
676
|
+
"expected_term_recall": round(_expected_recall(item), 6),
|
|
677
|
+
"evidence_term_recall_measured": measured,
|
|
678
|
+
"missing_evidence_term_count": len(missing_terms),
|
|
679
|
+
"missing_evidence_terms": list(sample_missing_terms),
|
|
680
|
+
"bundle_complete": _bundle_complete(item),
|
|
681
|
+
}
|
|
682
|
+
if measured:
|
|
683
|
+
sample["evidence_term_recall"] = round(_evidence_recall(item), 6)
|
|
684
|
+
samples.append(sample)
|
|
685
|
+
return samples
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def _safe_evidence_ref_terms(value: object) -> tuple[str, ...]:
|
|
689
|
+
terms: list[str] = []
|
|
690
|
+
for term in _str_tuple(value):
|
|
691
|
+
if not _looks_like_raw_source_ref(term):
|
|
692
|
+
terms.append(term)
|
|
693
|
+
continue
|
|
694
|
+
terms.extend(_safe_source_refs_for_output((term,)))
|
|
695
|
+
return tuple(dict.fromkeys(terms))
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
def _risk_flag_table(items: Sequence[Mapping[str, object]]) -> dict[str, object]:
|
|
699
|
+
groups: dict[str, list[Mapping[str, object]]] = defaultdict(list)
|
|
700
|
+
no_risk_count = 0
|
|
701
|
+
for item in items:
|
|
702
|
+
flags = _intent_risk_flags(item)
|
|
703
|
+
if not flags:
|
|
704
|
+
no_risk_count += 1
|
|
705
|
+
continue
|
|
706
|
+
for flag in flags:
|
|
707
|
+
groups[flag].append(item)
|
|
708
|
+
return {
|
|
709
|
+
"schema_version": "retrieval_intent_risk_flags.v1",
|
|
710
|
+
"evaluation_count": len(items),
|
|
711
|
+
"risk_flag_case_count": sum(
|
|
712
|
+
1 for item in items if _intent_risk_flags(item)
|
|
713
|
+
),
|
|
714
|
+
"no_risk_flag_case_count": no_risk_count,
|
|
715
|
+
"flag_counts": {
|
|
716
|
+
flag: len(flag_items) for flag, flag_items in sorted(groups.items())
|
|
717
|
+
},
|
|
718
|
+
"flag_stats": {
|
|
719
|
+
flag: _risk_flag_stats(flag_items)
|
|
720
|
+
for flag, flag_items in sorted(groups.items())
|
|
721
|
+
},
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
def _risk_flag_stats(items: Sequence[Mapping[str, object]]) -> dict[str, object]:
|
|
726
|
+
scored = [item for item in items if item.get("scored") is True]
|
|
727
|
+
passed = sum(1 for item in scored if _judgment_score(item) >= 1.0)
|
|
728
|
+
query_overlap_count = 0
|
|
729
|
+
profile_overlap_count = 0
|
|
730
|
+
intent_overlap_count = 0
|
|
731
|
+
for item in items:
|
|
732
|
+
integrity = _query_integrity(item)
|
|
733
|
+
query_overlap_count += (
|
|
734
|
+
_positive_int(integrity.get("expected_answer_query_overlap_count")) or 0
|
|
735
|
+
)
|
|
736
|
+
profile_overlap_count += (
|
|
737
|
+
_positive_int(
|
|
738
|
+
integrity.get("expected_answer_query_profile_overlap_count")
|
|
739
|
+
)
|
|
740
|
+
or 0
|
|
741
|
+
)
|
|
742
|
+
intent_overlap_count += (
|
|
743
|
+
_positive_int(
|
|
744
|
+
integrity.get("expected_answer_retrieval_intent_overlap_count")
|
|
745
|
+
)
|
|
746
|
+
or 0
|
|
747
|
+
)
|
|
748
|
+
query_leakage_count = (
|
|
749
|
+
query_overlap_count + profile_overlap_count + intent_overlap_count
|
|
750
|
+
)
|
|
751
|
+
return {
|
|
752
|
+
"case_count": len(items),
|
|
753
|
+
"scored": len(scored),
|
|
754
|
+
"passed": passed,
|
|
755
|
+
"accuracy": _ratio(passed, len(scored)),
|
|
756
|
+
"bundle_complete_count": sum(1 for item in scored if _bundle_complete(item)),
|
|
757
|
+
"bundle_complete_rate": _ratio(
|
|
758
|
+
sum(1 for item in scored if _bundle_complete(item)),
|
|
759
|
+
len(scored),
|
|
760
|
+
),
|
|
761
|
+
"query_overlap_count": query_overlap_count,
|
|
762
|
+
"profile_overlap_count": profile_overlap_count,
|
|
763
|
+
"retrieval_intent_overlap_count": intent_overlap_count,
|
|
764
|
+
"query_leakage_count": query_leakage_count,
|
|
765
|
+
"avg_expected_term_recall": _avg(_expected_recall(item) for item in scored),
|
|
766
|
+
"avg_evidence_term_recall": _avg(
|
|
767
|
+
_evidence_recall(item)
|
|
768
|
+
for item in scored
|
|
769
|
+
if "evidence_term_recall" in _mapping(item.get("retrieval_quality"))
|
|
770
|
+
),
|
|
771
|
+
"samples": [
|
|
772
|
+
{
|
|
773
|
+
"case_id": str(item.get("case_id") or ""),
|
|
774
|
+
"group": str(item.get("group") or ""),
|
|
775
|
+
"score": _judgment_score(item),
|
|
776
|
+
"bundle_complete": _bundle_complete(item),
|
|
777
|
+
"query_overlap_count": _query_overlap_count(item),
|
|
778
|
+
}
|
|
779
|
+
for item in items[:10]
|
|
780
|
+
],
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def _intent_risk_flags(item: Mapping[str, object]) -> tuple[str, ...]:
|
|
785
|
+
metadata = _retrieval_metadata(item)
|
|
786
|
+
query_decomposition = _mapping(metadata.get("query_decomposition"))
|
|
787
|
+
rerank = _mapping(metadata.get("benchmark_rerank"))
|
|
788
|
+
query_profile = _mapping(
|
|
789
|
+
query_decomposition.get("query_profile") or rerank.get("query_profile")
|
|
790
|
+
)
|
|
791
|
+
query_intent = _mapping(query_decomposition.get("retrieval_intent"))
|
|
792
|
+
rerank_intent = _mapping(rerank.get("retrieval_intent"))
|
|
793
|
+
integrity = _query_integrity(item)
|
|
794
|
+
return tuple(
|
|
795
|
+
dict.fromkeys(
|
|
796
|
+
(
|
|
797
|
+
*_str_tuple(query_profile.get("risk_flags")),
|
|
798
|
+
*_str_tuple(query_intent.get("risk_flags")),
|
|
799
|
+
*_str_tuple(rerank_intent.get("risk_flags")),
|
|
800
|
+
*_str_tuple(integrity.get("retrieval_intent_risk_flags")),
|
|
801
|
+
)
|
|
802
|
+
)
|
|
803
|
+
)
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
def _answerability_gap_breakdown(
|
|
807
|
+
items: Sequence[Mapping[str, object]],
|
|
808
|
+
) -> dict[str, object]:
|
|
809
|
+
reason_counts: Counter[str] = Counter()
|
|
810
|
+
lifted_reason_counts: Counter[str] = Counter()
|
|
811
|
+
category_counts: Counter[str] = Counter()
|
|
812
|
+
lifted_category_counts: Counter[str] = Counter()
|
|
813
|
+
case_ids: set[str] = set()
|
|
814
|
+
lifted_case_ids: set[str] = set()
|
|
815
|
+
low_answerability_case_ids: set[str] = set()
|
|
816
|
+
lifted_low_answerability_case_ids: set[str] = set()
|
|
817
|
+
candidate_count = 0
|
|
818
|
+
lifted_candidate_count = 0
|
|
819
|
+
low_answerability_candidate_count = 0
|
|
820
|
+
lifted_low_answerability_candidate_count = 0
|
|
821
|
+
samples: list[dict[str, object]] = []
|
|
822
|
+
low_answerability_samples: list[dict[str, object]] = []
|
|
823
|
+
for item in items:
|
|
824
|
+
case_id = str(item.get("case_id") or "")
|
|
825
|
+
group = str(item.get("group") or "")
|
|
826
|
+
retrieval = _mapping(item.get("retrieval"))
|
|
827
|
+
for memory in _sequence(retrieval.get("results")):
|
|
828
|
+
if not isinstance(memory, Mapping):
|
|
829
|
+
continue
|
|
830
|
+
features = _candidate_features(memory)
|
|
831
|
+
answerability_reason_codes = _compact_answerability_gap_values(
|
|
832
|
+
_str_tuple(features.get("answerability_reason_codes"))
|
|
833
|
+
)
|
|
834
|
+
reasons = tuple(
|
|
835
|
+
reason
|
|
836
|
+
for reason in answerability_reason_codes
|
|
837
|
+
if reason.startswith("missing_") and reason.endswith("_evidence")
|
|
838
|
+
)
|
|
839
|
+
diagnostics = _memory_diagnostics(memory)
|
|
840
|
+
lifted = _candidate_lifted(diagnostics)
|
|
841
|
+
answerability_score = _metric_value(features, "answerability_score")
|
|
842
|
+
low_answerability = _is_measured_low_answerability(answerability_score)
|
|
843
|
+
if low_answerability:
|
|
844
|
+
low_answerability_candidate_count += 1
|
|
845
|
+
if case_id:
|
|
846
|
+
low_answerability_case_ids.add(case_id)
|
|
847
|
+
if lifted:
|
|
848
|
+
lifted_low_answerability_case_ids.add(case_id)
|
|
849
|
+
if lifted:
|
|
850
|
+
lifted_low_answerability_candidate_count += 1
|
|
851
|
+
if len(low_answerability_samples) < 10:
|
|
852
|
+
sample = {
|
|
853
|
+
"case_id": case_id,
|
|
854
|
+
"group": group,
|
|
855
|
+
"memory_id": _safe_item_id_for_output(_memory_id(memory)),
|
|
856
|
+
"rank": _positive_int(memory.get("rank")),
|
|
857
|
+
"lifted": lifted,
|
|
858
|
+
"positive_policy_score": round(
|
|
859
|
+
_positive_policy_score(diagnostics),
|
|
860
|
+
6,
|
|
861
|
+
),
|
|
862
|
+
"answerability_score": round(answerability_score, 6),
|
|
863
|
+
"answerability_reason_codes": [
|
|
864
|
+
_compact_answerability_gap_text(reason)
|
|
865
|
+
for reason in answerability_reason_codes[
|
|
866
|
+
:_ANSWERABILITY_GAP_REASON_LIMIT
|
|
867
|
+
]
|
|
868
|
+
],
|
|
869
|
+
"answerability_reason_count": len(answerability_reason_codes),
|
|
870
|
+
"relation_categories": list(
|
|
871
|
+
_str_tuple(features.get("relation_categories"))
|
|
872
|
+
),
|
|
873
|
+
"relation_category_hits": list(
|
|
874
|
+
_str_tuple(features.get("relation_category_hits"))
|
|
875
|
+
),
|
|
876
|
+
"query_roles": list(_str_tuple(features.get("query_roles"))),
|
|
877
|
+
}
|
|
878
|
+
source_identity_refs = _answerability_sample_source_identity_refs(
|
|
879
|
+
memory
|
|
880
|
+
)
|
|
881
|
+
if source_identity_refs:
|
|
882
|
+
sample["source_identity_refs"] = list(source_identity_refs)
|
|
883
|
+
low_answerability_samples.append(sample)
|
|
884
|
+
if not reasons:
|
|
885
|
+
continue
|
|
886
|
+
candidate_count += 1
|
|
887
|
+
if case_id:
|
|
888
|
+
case_ids.add(case_id)
|
|
889
|
+
if lifted:
|
|
890
|
+
lifted_case_ids.add(case_id)
|
|
891
|
+
if lifted:
|
|
892
|
+
lifted_candidate_count += 1
|
|
893
|
+
lifted_reason_counts.update(reasons)
|
|
894
|
+
reason_counts.update(reasons)
|
|
895
|
+
for reason in reasons:
|
|
896
|
+
category = reason.removeprefix("missing_").removesuffix("_evidence")
|
|
897
|
+
if category:
|
|
898
|
+
category_counts[category] += 1
|
|
899
|
+
if lifted:
|
|
900
|
+
lifted_category_counts[category] += 1
|
|
901
|
+
if len(samples) < 10:
|
|
902
|
+
sample = {
|
|
903
|
+
"case_id": case_id,
|
|
904
|
+
"group": group,
|
|
905
|
+
"memory_id": _safe_item_id_for_output(_memory_id(memory)),
|
|
906
|
+
"rank": _positive_int(memory.get("rank")),
|
|
907
|
+
"reasons": list(reasons),
|
|
908
|
+
"answerability_reason_codes": [
|
|
909
|
+
_compact_answerability_gap_text(reason)
|
|
910
|
+
for reason in answerability_reason_codes[
|
|
911
|
+
:_ANSWERABILITY_GAP_REASON_LIMIT
|
|
912
|
+
]
|
|
913
|
+
],
|
|
914
|
+
"answerability_reason_count": len(answerability_reason_codes),
|
|
915
|
+
"lifted": lifted,
|
|
916
|
+
"positive_policy_score": round(
|
|
917
|
+
_positive_policy_score(diagnostics),
|
|
918
|
+
6,
|
|
919
|
+
),
|
|
920
|
+
"answerability_score": round(
|
|
921
|
+
answerability_score,
|
|
922
|
+
6,
|
|
923
|
+
),
|
|
924
|
+
"source_locality_score": round(
|
|
925
|
+
_metric_value(features, "source_locality_score"),
|
|
926
|
+
6,
|
|
927
|
+
),
|
|
928
|
+
"relation_categories": list(
|
|
929
|
+
_str_tuple(features.get("relation_categories"))
|
|
930
|
+
),
|
|
931
|
+
"relation_category_hits": list(
|
|
932
|
+
_str_tuple(features.get("relation_category_hits"))
|
|
933
|
+
),
|
|
934
|
+
"query_roles": list(_str_tuple(features.get("query_roles"))),
|
|
935
|
+
}
|
|
936
|
+
source_identity_refs = _answerability_sample_source_identity_refs(memory)
|
|
937
|
+
if source_identity_refs:
|
|
938
|
+
sample["source_identity_refs"] = list(source_identity_refs)
|
|
939
|
+
samples.append(sample)
|
|
940
|
+
return {
|
|
941
|
+
"schema_version": "answerability_gap_breakdown.v1",
|
|
942
|
+
"gap_candidate_count": candidate_count,
|
|
943
|
+
"gap_case_count": len(case_ids),
|
|
944
|
+
"lifted_gap_candidate_count": lifted_candidate_count,
|
|
945
|
+
"lifted_gap_case_count": len(lifted_case_ids),
|
|
946
|
+
"low_answerability_candidate_count": low_answerability_candidate_count,
|
|
947
|
+
"low_answerability_case_count": len(low_answerability_case_ids),
|
|
948
|
+
"lifted_low_answerability_candidate_count": (
|
|
949
|
+
lifted_low_answerability_candidate_count
|
|
950
|
+
),
|
|
951
|
+
"lifted_low_answerability_case_count": (
|
|
952
|
+
len(lifted_low_answerability_case_ids)
|
|
953
|
+
),
|
|
954
|
+
"reason_counts": dict(sorted(reason_counts.items())),
|
|
955
|
+
"lifted_reason_counts": dict(sorted(lifted_reason_counts.items())),
|
|
956
|
+
"category_counts": dict(sorted(category_counts.items())),
|
|
957
|
+
"lifted_category_counts": dict(sorted(lifted_category_counts.items())),
|
|
958
|
+
"samples": samples,
|
|
959
|
+
"low_answerability_samples": low_answerability_samples,
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
def _answerability_sample_source_identity_refs(
|
|
964
|
+
memory: Mapping[str, object],
|
|
965
|
+
) -> tuple[str, ...]:
|
|
966
|
+
return _source_identity_refs_from_source_refs(
|
|
967
|
+
_source_refs_from_memory(memory),
|
|
968
|
+
include_exact_turn_refs=True,
|
|
969
|
+
)[:_ANSWER_CONTEXT_SAMPLE_IDENTITY_LIMIT]
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
def _compact_answerability_gap_values(values: Sequence[str]) -> tuple[str, ...]:
|
|
973
|
+
return tuple(
|
|
974
|
+
dict.fromkeys(stripped for value in values if (stripped := value.strip()))
|
|
975
|
+
)
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
def _compact_answerability_gap_text(value: str) -> str:
|
|
979
|
+
stripped = value.strip()
|
|
980
|
+
if len(stripped) <= _ANSWERABILITY_GAP_TEXT_VALUE_LIMIT:
|
|
981
|
+
return stripped
|
|
982
|
+
return f"{stripped[:_ANSWERABILITY_GAP_TEXT_VALUE_LIMIT - 3]}..."
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
def _policy_contribution_table(
|
|
986
|
+
items: Sequence[Mapping[str, object]],
|
|
987
|
+
) -> dict[str, dict[str, object]]:
|
|
988
|
+
totals: dict[str, float] = defaultdict(float)
|
|
989
|
+
active_counts: Counter[str] = Counter()
|
|
990
|
+
reason_counts: dict[str, Counter[str]] = defaultdict(Counter)
|
|
991
|
+
for memory in _retrieval_results(items):
|
|
992
|
+
policy = _mapping(
|
|
993
|
+
_mapping(_mapping(memory.get("metadata")).get("diagnostics")).get(
|
|
994
|
+
"benchmark_rerank_policy"
|
|
995
|
+
)
|
|
996
|
+
)
|
|
997
|
+
for contribution in _sequence(policy.get("contributions")):
|
|
998
|
+
payload = _mapping(contribution)
|
|
999
|
+
name = str(payload.get("policy") or "unknown")
|
|
1000
|
+
score = _metric_value(payload, "score")
|
|
1001
|
+
totals[name] += score
|
|
1002
|
+
if score != 0:
|
|
1003
|
+
active_counts[name] += 1
|
|
1004
|
+
reason_counts[name].update(_str_tuple(payload.get("reason_codes")))
|
|
1005
|
+
return {
|
|
1006
|
+
name: {
|
|
1007
|
+
"active_count": active_counts[name],
|
|
1008
|
+
"total_score": round(total, 6),
|
|
1009
|
+
"avg_active_score": round(total / active_counts[name], 6)
|
|
1010
|
+
if active_counts[name]
|
|
1011
|
+
else 0.0,
|
|
1012
|
+
"reason_counts": dict(sorted(reason_counts[name].items())),
|
|
1013
|
+
}
|
|
1014
|
+
for name, total in sorted(totals.items())
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
def _evidence_feature_table(items: Sequence[Mapping[str, object]]) -> dict[str, object]:
|
|
1019
|
+
surface_counts: Counter[str] = Counter()
|
|
1020
|
+
source_type_counts: Counter[str] = Counter()
|
|
1021
|
+
retrieval_source_counts: Counter[str] = Counter()
|
|
1022
|
+
query_role_counts: Counter[str] = Counter()
|
|
1023
|
+
relation_category_counts: Counter[str] = Counter()
|
|
1024
|
+
relation_category_hit_counts: Counter[str] = Counter()
|
|
1025
|
+
relation_target_specificity_reason_counts: Counter[str] = Counter()
|
|
1026
|
+
answerability_reason_counts: Counter[str] = Counter()
|
|
1027
|
+
source_locality_reason_counts: Counter[str] = Counter()
|
|
1028
|
+
time_intent_kind_counts: Counter[str] = Counter()
|
|
1029
|
+
typed_temporal_surface_counts: Counter[str] = Counter()
|
|
1030
|
+
answerability_scores: list[float] = []
|
|
1031
|
+
source_locality_scores: list[float] = []
|
|
1032
|
+
for memory in _retrieval_results(items):
|
|
1033
|
+
features = _candidate_features(memory)
|
|
1034
|
+
if not features:
|
|
1035
|
+
continue
|
|
1036
|
+
answerability_scores.append(_metric_value(features, "answerability_score"))
|
|
1037
|
+
source_locality_scores.append(_metric_value(features, "source_locality_score"))
|
|
1038
|
+
source_type_counts.update(_feature_source_types(features))
|
|
1039
|
+
retrieval_source_counts.update(_str_tuple(features.get("retrieval_sources")))
|
|
1040
|
+
query_role_counts.update(_str_tuple(features.get("query_roles")))
|
|
1041
|
+
time_intent_kind = str(features.get("time_intent_kind") or "").strip()
|
|
1042
|
+
if time_intent_kind and time_intent_kind != "none":
|
|
1043
|
+
time_intent_kind_counts[time_intent_kind] += 1
|
|
1044
|
+
if features.get("bridge_query_hit") is True:
|
|
1045
|
+
surface_counts["bridge_query_hit"] += 1
|
|
1046
|
+
relation_category_counts.update(_str_tuple(features.get("relation_categories")))
|
|
1047
|
+
relation_category_hit_counts.update(
|
|
1048
|
+
_str_tuple(features.get("relation_category_hits"))
|
|
1049
|
+
)
|
|
1050
|
+
relation_target_specificity_reason_counts.update(
|
|
1051
|
+
_str_tuple(features.get("relation_target_specificity_reason_codes"))
|
|
1052
|
+
)
|
|
1053
|
+
answerability_reason_counts.update(
|
|
1054
|
+
_str_tuple(features.get("answerability_reason_codes"))
|
|
1055
|
+
)
|
|
1056
|
+
source_locality_reason_counts.update(
|
|
1057
|
+
_str_tuple(features.get("source_locality_reason_codes"))
|
|
1058
|
+
)
|
|
1059
|
+
for key in (
|
|
1060
|
+
"direct_speaker_turn",
|
|
1061
|
+
"negation_surface",
|
|
1062
|
+
"currentness_surface",
|
|
1063
|
+
"stale_surface",
|
|
1064
|
+
"contrast_surface",
|
|
1065
|
+
):
|
|
1066
|
+
if features.get(key) is True:
|
|
1067
|
+
surface_counts[key] += 1
|
|
1068
|
+
if payload_has_broad_summary(memory, features):
|
|
1069
|
+
surface_counts["broad_summary"] += 1
|
|
1070
|
+
if payload_has_conflict_or_stale(memory, features):
|
|
1071
|
+
surface_counts["conflict_or_stale"] += 1
|
|
1072
|
+
for key in (
|
|
1073
|
+
"has_duration_surface",
|
|
1074
|
+
"has_relative_time_surface",
|
|
1075
|
+
"has_explicit_time_surface",
|
|
1076
|
+
"has_explicit_time_content_surface",
|
|
1077
|
+
"has_temporal_sequence_surface",
|
|
1078
|
+
):
|
|
1079
|
+
if features.get(key) is True:
|
|
1080
|
+
typed_temporal_surface_counts[key] += 1
|
|
1081
|
+
low_answerability_count = sum(
|
|
1082
|
+
1 for score in answerability_scores if _is_measured_low_answerability(score)
|
|
1083
|
+
)
|
|
1084
|
+
measured_answerability_scores = [
|
|
1085
|
+
score for score in answerability_scores if score > 0
|
|
1086
|
+
]
|
|
1087
|
+
measured_source_locality_scores = [
|
|
1088
|
+
score for score in source_locality_scores if score > 0
|
|
1089
|
+
]
|
|
1090
|
+
return {
|
|
1091
|
+
"candidate_count": len(answerability_scores),
|
|
1092
|
+
"avg_answerability_score": _avg(answerability_scores),
|
|
1093
|
+
"avg_measured_answerability_score": _avg(measured_answerability_scores),
|
|
1094
|
+
"unmeasured_answerability_count": sum(
|
|
1095
|
+
1 for score in answerability_scores if score <= 0
|
|
1096
|
+
),
|
|
1097
|
+
"avg_source_locality_score": _avg(source_locality_scores),
|
|
1098
|
+
"avg_measured_source_locality_score": _avg(measured_source_locality_scores),
|
|
1099
|
+
"unmeasured_source_locality_count": sum(
|
|
1100
|
+
1 for score in source_locality_scores if score <= 0
|
|
1101
|
+
),
|
|
1102
|
+
"low_answerability_count": low_answerability_count,
|
|
1103
|
+
"surface_counts": dict(sorted(surface_counts.items())),
|
|
1104
|
+
"source_type_counts": dict(sorted(source_type_counts.items())),
|
|
1105
|
+
"retrieval_source_counts": dict(sorted(retrieval_source_counts.items())),
|
|
1106
|
+
"query_role_counts": dict(sorted(query_role_counts.items())),
|
|
1107
|
+
"bridge_query_hit_count": surface_counts.get("bridge_query_hit", 0),
|
|
1108
|
+
"time_intent_kind_counts": dict(sorted(time_intent_kind_counts.items())),
|
|
1109
|
+
"typed_temporal_surface_counts": dict(
|
|
1110
|
+
sorted(typed_temporal_surface_counts.items())
|
|
1111
|
+
),
|
|
1112
|
+
"relation_category_counts": dict(sorted(relation_category_counts.items())),
|
|
1113
|
+
"relation_category_hit_counts": dict(
|
|
1114
|
+
sorted(relation_category_hit_counts.items())
|
|
1115
|
+
),
|
|
1116
|
+
"relation_target_specificity_reason_counts": dict(
|
|
1117
|
+
sorted(relation_target_specificity_reason_counts.items())
|
|
1118
|
+
),
|
|
1119
|
+
"answerability_reason_counts": dict(sorted(answerability_reason_counts.items())),
|
|
1120
|
+
"source_locality_reason_counts": dict(
|
|
1121
|
+
sorted(source_locality_reason_counts.items())
|
|
1122
|
+
),
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
def _feature_source_types(features: Mapping[str, object]) -> tuple[str, ...]:
|
|
1127
|
+
source_types = _str_tuple(features.get("source_types"))
|
|
1128
|
+
if source_types:
|
|
1129
|
+
return source_types
|
|
1130
|
+
source_type = str(features.get("source_type") or "unknown").strip() or "unknown"
|
|
1131
|
+
return (source_type,)
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
def _source_ref_provenance_table(
|
|
1135
|
+
items: Sequence[Mapping[str, object]],
|
|
1136
|
+
) -> dict[str, object]:
|
|
1137
|
+
retrieval_candidate_count = 0
|
|
1138
|
+
retrieval_source_ref_candidate_count = 0
|
|
1139
|
+
retrieval_source_ref_count = 0
|
|
1140
|
+
fused_candidate_count = 0
|
|
1141
|
+
fused_source_ref_candidate_count = 0
|
|
1142
|
+
fused_source_ref_count = 0
|
|
1143
|
+
fused_ref_rescue_candidate_count = 0
|
|
1144
|
+
fused_ref_added_count = 0
|
|
1145
|
+
retrieval_source_ref_shape_counts: Counter[str] = Counter()
|
|
1146
|
+
fused_source_ref_shape_counts: Counter[str] = Counter()
|
|
1147
|
+
selected_bundle_source_ref_shape_counts: Counter[str] = Counter()
|
|
1148
|
+
selected_bundle_item_count = 0
|
|
1149
|
+
selected_bundle_source_ref_item_count = 0
|
|
1150
|
+
selected_bundle_source_ref_count = 0
|
|
1151
|
+
source_refless_selected_samples: list[dict[str, object]] = []
|
|
1152
|
+
|
|
1153
|
+
for item in items:
|
|
1154
|
+
for memory in _sequence(_mapping(item.get("retrieval")).get("results")):
|
|
1155
|
+
if not isinstance(memory, Mapping):
|
|
1156
|
+
continue
|
|
1157
|
+
retrieval_candidate_count += 1
|
|
1158
|
+
direct_memory_refs = _direct_source_refs_from_memory(memory)
|
|
1159
|
+
memory_refs = _source_refs_from_memory(memory)
|
|
1160
|
+
if memory_refs:
|
|
1161
|
+
retrieval_source_ref_candidate_count += 1
|
|
1162
|
+
retrieval_source_ref_count += len(memory_refs)
|
|
1163
|
+
retrieval_source_ref_shape_counts.update(
|
|
1164
|
+
_source_ref_shape(ref) for ref in memory_refs
|
|
1165
|
+
)
|
|
1166
|
+
|
|
1167
|
+
fusion_refs = _fusion_source_refs(memory)
|
|
1168
|
+
if fusion_refs:
|
|
1169
|
+
fused_candidate_count += 1
|
|
1170
|
+
fused_source_ref_candidate_count += 1
|
|
1171
|
+
fused_source_ref_count += len(fusion_refs)
|
|
1172
|
+
fused_source_ref_shape_counts.update(
|
|
1173
|
+
_source_ref_shape(ref) for ref in fusion_refs
|
|
1174
|
+
)
|
|
1175
|
+
added_refs = tuple(
|
|
1176
|
+
ref for ref in fusion_refs if ref not in direct_memory_refs
|
|
1177
|
+
)
|
|
1178
|
+
if added_refs:
|
|
1179
|
+
fused_ref_rescue_candidate_count += 1
|
|
1180
|
+
fused_ref_added_count += len(added_refs)
|
|
1181
|
+
elif _mapping(_memory_diagnostics(memory).get("benchmark_candidate_fusion")):
|
|
1182
|
+
fused_candidate_count += 1
|
|
1183
|
+
|
|
1184
|
+
for bundle_item in _bundle_items(_mapping(item.get("evidence_bundle"))):
|
|
1185
|
+
selected_bundle_item_count += 1
|
|
1186
|
+
source_refs = _source_refs_from_bundle_item(bundle_item)
|
|
1187
|
+
if source_refs:
|
|
1188
|
+
selected_bundle_source_ref_item_count += 1
|
|
1189
|
+
selected_bundle_source_ref_count += len(source_refs)
|
|
1190
|
+
selected_bundle_source_ref_shape_counts.update(
|
|
1191
|
+
_source_ref_shape(ref) for ref in source_refs
|
|
1192
|
+
)
|
|
1193
|
+
continue
|
|
1194
|
+
if len(source_refless_selected_samples) < 10:
|
|
1195
|
+
source_refless_selected_samples.append(
|
|
1196
|
+
{
|
|
1197
|
+
"case_id": str(item.get("case_id") or ""),
|
|
1198
|
+
"item_id": _safe_item_id_for_output(
|
|
1199
|
+
bundle_item.get("id") or bundle_item.get("item_id")
|
|
1200
|
+
),
|
|
1201
|
+
"role": str(bundle_item.get("role") or ""),
|
|
1202
|
+
"retrieval_order": (
|
|
1203
|
+
_positive_int(bundle_item.get("retrieval_order"))
|
|
1204
|
+
or _positive_int(bundle_item.get("rank"))
|
|
1205
|
+
or 0
|
|
1206
|
+
),
|
|
1207
|
+
}
|
|
1208
|
+
)
|
|
1209
|
+
|
|
1210
|
+
return {
|
|
1211
|
+
"schema_version": "source_ref_provenance.v1",
|
|
1212
|
+
"retrieval_candidate_count": retrieval_candidate_count,
|
|
1213
|
+
"retrieval_source_ref_candidate_count": retrieval_source_ref_candidate_count,
|
|
1214
|
+
"retrieval_source_ref_count": retrieval_source_ref_count,
|
|
1215
|
+
"retrieval_source_ref_shape_counts": dict(
|
|
1216
|
+
sorted(retrieval_source_ref_shape_counts.items())
|
|
1217
|
+
),
|
|
1218
|
+
"retrieval_source_refless_candidate_count": (
|
|
1219
|
+
retrieval_candidate_count - retrieval_source_ref_candidate_count
|
|
1220
|
+
),
|
|
1221
|
+
"retrieval_source_ref_coverage_rate": _ratio(
|
|
1222
|
+
retrieval_source_ref_candidate_count,
|
|
1223
|
+
retrieval_candidate_count,
|
|
1224
|
+
),
|
|
1225
|
+
"fused_candidate_count": fused_candidate_count,
|
|
1226
|
+
"fused_source_ref_candidate_count": fused_source_ref_candidate_count,
|
|
1227
|
+
"fused_source_ref_count": fused_source_ref_count,
|
|
1228
|
+
"fused_source_ref_shape_counts": dict(
|
|
1229
|
+
sorted(fused_source_ref_shape_counts.items())
|
|
1230
|
+
),
|
|
1231
|
+
"fused_ref_rescue_candidate_count": fused_ref_rescue_candidate_count,
|
|
1232
|
+
"fused_ref_added_count": fused_ref_added_count,
|
|
1233
|
+
"selected_bundle_item_count": selected_bundle_item_count,
|
|
1234
|
+
"selected_bundle_source_ref_item_count": selected_bundle_source_ref_item_count,
|
|
1235
|
+
"selected_bundle_source_ref_count": selected_bundle_source_ref_count,
|
|
1236
|
+
"selected_bundle_source_ref_shape_counts": dict(
|
|
1237
|
+
sorted(selected_bundle_source_ref_shape_counts.items())
|
|
1238
|
+
),
|
|
1239
|
+
"selected_bundle_source_refless_item_count": (
|
|
1240
|
+
selected_bundle_item_count - selected_bundle_source_ref_item_count
|
|
1241
|
+
),
|
|
1242
|
+
"selected_bundle_source_ref_coverage_rate": _ratio(
|
|
1243
|
+
selected_bundle_source_ref_item_count,
|
|
1244
|
+
selected_bundle_item_count,
|
|
1245
|
+
),
|
|
1246
|
+
"source_refless_selected_samples": source_refless_selected_samples,
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
def _source_ref_shape(source_ref: str) -> str:
|
|
1251
|
+
value = str(source_ref or "").strip()
|
|
1252
|
+
if not value:
|
|
1253
|
+
return "empty_source_ref"
|
|
1254
|
+
if _LOCOMO_SESSION_TURN_IDENTITY_RE.fullmatch(value):
|
|
1255
|
+
return "locomo_session_turn_identity"
|
|
1256
|
+
if _LOCOMO_TURN_IDENTITY_RE.fullmatch(value):
|
|
1257
|
+
return "locomo_turn_identity"
|
|
1258
|
+
if _LOCOMO_TURN_REF_RE.fullmatch(value):
|
|
1259
|
+
return "locomo_turn_ref"
|
|
1260
|
+
if _LOCOMO_TURN_REF_RE.search(value):
|
|
1261
|
+
return "locomo_embedded_turn_ref"
|
|
1262
|
+
return "opaque_source_ref"
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
def _answer_context_provenance_table(
|
|
1266
|
+
items: Sequence[Mapping[str, object]],
|
|
1267
|
+
) -> dict[str, object]:
|
|
1268
|
+
context_count = 0
|
|
1269
|
+
evidence_bundle_context_count = 0
|
|
1270
|
+
source_ref_context_count = 0
|
|
1271
|
+
source_refless_context_count = 0
|
|
1272
|
+
mixed_source_context_count = 0
|
|
1273
|
+
memory_count = 0
|
|
1274
|
+
source_ref_count = 0
|
|
1275
|
+
source_ref_item_count = 0
|
|
1276
|
+
source_refless_item_count = 0
|
|
1277
|
+
backfilled_context_count = 0
|
|
1278
|
+
duplicate_source_bundle_skip_context_count = 0
|
|
1279
|
+
noisy_overlap_bundle_skip_context_count = 0
|
|
1280
|
+
backfill_skip_context_count = 0
|
|
1281
|
+
backfilled_retrieval_item_count = 0
|
|
1282
|
+
skipped_duplicate_source_bundle_item_count = 0
|
|
1283
|
+
skipped_noisy_overlap_bundle_item_count = 0
|
|
1284
|
+
skipped_redundant_risky_backfill_count = 0
|
|
1285
|
+
skipped_redundant_source_backfill_count = 0
|
|
1286
|
+
skipped_redundant_role_backfill_count = 0
|
|
1287
|
+
backfilled_broad_summary_count = 0
|
|
1288
|
+
backfilled_conflict_or_stale_count = 0
|
|
1289
|
+
backfilled_precise_source_overlap_count = 0
|
|
1290
|
+
backfilled_low_answerability_count = 0
|
|
1291
|
+
backfilled_weak_source_locality_count = 0
|
|
1292
|
+
backfilled_low_answerability_role_counts: Counter[str] = Counter()
|
|
1293
|
+
backfilled_weak_source_locality_role_counts: Counter[str] = Counter()
|
|
1294
|
+
backfilled_source_proximity_support_count = 0
|
|
1295
|
+
backfilled_chained_source_proximity_support_count = 0
|
|
1296
|
+
backfilled_source_proximity_closest_distances: list[int] = []
|
|
1297
|
+
fallback_context_count = 0
|
|
1298
|
+
source_type_diversities: list[int] = []
|
|
1299
|
+
retrieval_source_diversities: list[int] = []
|
|
1300
|
+
source_type_support_diversities: list[int] = []
|
|
1301
|
+
retrieval_source_support_diversities: list[int] = []
|
|
1302
|
+
answerability_scores: list[float] = []
|
|
1303
|
+
measured_answerability_scores: list[float] = []
|
|
1304
|
+
unmeasured_answerability_count = 0
|
|
1305
|
+
source_locality_scores: list[float] = []
|
|
1306
|
+
measured_source_locality_scores: list[float] = []
|
|
1307
|
+
unmeasured_source_locality_count = 0
|
|
1308
|
+
source_counts: Counter[str] = Counter()
|
|
1309
|
+
fallback_reason_counts: Counter[str] = Counter()
|
|
1310
|
+
missing_required_role_counts: Counter[str] = Counter()
|
|
1311
|
+
backfilled_missing_required_role_counts: Counter[str] = Counter()
|
|
1312
|
+
risk_reason_counts: Counter[str] = Counter()
|
|
1313
|
+
risk_reason_source_counts: defaultdict[str, Counter[str]] = defaultdict(Counter)
|
|
1314
|
+
risk_reason_context_count = 0
|
|
1315
|
+
fallback_risk_context_count = 0
|
|
1316
|
+
missing_required_role_context_count = 0
|
|
1317
|
+
source_refless_context_samples: list[dict[str, object]] = []
|
|
1318
|
+
backfilled_context_samples: list[dict[str, object]] = []
|
|
1319
|
+
duplicate_source_bundle_skip_context_samples: list[dict[str, object]] = []
|
|
1320
|
+
noisy_overlap_bundle_skip_context_samples: list[dict[str, object]] = []
|
|
1321
|
+
backfill_skip_context_samples: list[dict[str, object]] = []
|
|
1322
|
+
mixed_source_context_samples: list[dict[str, object]] = []
|
|
1323
|
+
risk_reason_context_samples: list[dict[str, object]] = []
|
|
1324
|
+
|
|
1325
|
+
for item in items:
|
|
1326
|
+
for cutoff, context in _answer_contexts(item):
|
|
1327
|
+
context_count += 1
|
|
1328
|
+
source = str(context.get("source") or "unknown").strip() or "unknown"
|
|
1329
|
+
source_counts[source] += 1
|
|
1330
|
+
if source == "evidence_bundle":
|
|
1331
|
+
evidence_bundle_context_count += 1
|
|
1332
|
+
else:
|
|
1333
|
+
fallback_context_count += 1
|
|
1334
|
+
fallback_reason = str(context.get("fallback_reason") or "").strip()
|
|
1335
|
+
if fallback_reason:
|
|
1336
|
+
fallback_reason_counts[fallback_reason] += 1
|
|
1337
|
+
|
|
1338
|
+
context_memory_count = _positive_int(context.get("memory_count")) or 0
|
|
1339
|
+
context_source_ref_count = (
|
|
1340
|
+
_positive_int(context.get("source_ref_count")) or 0
|
|
1341
|
+
)
|
|
1342
|
+
context_source_ref_item_count = (
|
|
1343
|
+
_positive_int(context.get("source_ref_item_count")) or 0
|
|
1344
|
+
)
|
|
1345
|
+
context_source_refless_item_count = (
|
|
1346
|
+
_positive_int(context.get("source_refless_item_count")) or 0
|
|
1347
|
+
)
|
|
1348
|
+
context_backfilled_count = (
|
|
1349
|
+
_positive_int(context.get("backfilled_retrieval_item_count")) or 0
|
|
1350
|
+
)
|
|
1351
|
+
context_skipped_duplicate_source_bundle_item_count = (
|
|
1352
|
+
_positive_int(
|
|
1353
|
+
context.get("skipped_duplicate_source_bundle_item_count")
|
|
1354
|
+
)
|
|
1355
|
+
or 0
|
|
1356
|
+
)
|
|
1357
|
+
context_skipped_noisy_overlap_bundle_item_count = (
|
|
1358
|
+
_positive_int(
|
|
1359
|
+
context.get("skipped_noisy_overlap_bundle_item_count")
|
|
1360
|
+
)
|
|
1361
|
+
or 0
|
|
1362
|
+
)
|
|
1363
|
+
context_skipped_redundant_risky_backfill_count = (
|
|
1364
|
+
_positive_int(
|
|
1365
|
+
context.get("skipped_redundant_risky_backfill_count")
|
|
1366
|
+
)
|
|
1367
|
+
or 0
|
|
1368
|
+
)
|
|
1369
|
+
context_skipped_redundant_source_backfill_count = (
|
|
1370
|
+
_positive_int(
|
|
1371
|
+
context.get("skipped_redundant_source_backfill_count")
|
|
1372
|
+
)
|
|
1373
|
+
or 0
|
|
1374
|
+
)
|
|
1375
|
+
context_skipped_redundant_role_backfill_count = (
|
|
1376
|
+
_positive_int(
|
|
1377
|
+
context.get("skipped_redundant_role_backfill_count")
|
|
1378
|
+
)
|
|
1379
|
+
or 0
|
|
1380
|
+
)
|
|
1381
|
+
context_backfilled_broad_summary_count = (
|
|
1382
|
+
_positive_int(context.get("backfilled_broad_summary_count")) or 0
|
|
1383
|
+
)
|
|
1384
|
+
context_backfilled_conflict_or_stale_count = (
|
|
1385
|
+
_positive_int(context.get("backfilled_conflict_or_stale_count")) or 0
|
|
1386
|
+
)
|
|
1387
|
+
context_backfilled_precise_source_overlap_count = (
|
|
1388
|
+
_positive_int(
|
|
1389
|
+
context.get("backfilled_precise_source_overlap_count")
|
|
1390
|
+
)
|
|
1391
|
+
or 0
|
|
1392
|
+
)
|
|
1393
|
+
context_backfilled_low_answerability_count = (
|
|
1394
|
+
_positive_int(context.get("backfilled_low_answerability_count")) or 0
|
|
1395
|
+
)
|
|
1396
|
+
context_backfilled_weak_source_locality_count = (
|
|
1397
|
+
_positive_int(context.get("backfilled_weak_source_locality_count"))
|
|
1398
|
+
or 0
|
|
1399
|
+
)
|
|
1400
|
+
context_backfilled_low_answerability_role_counts = _count_mapping(
|
|
1401
|
+
context.get("backfilled_low_answerability_role_counts")
|
|
1402
|
+
)
|
|
1403
|
+
context_backfilled_weak_source_locality_role_counts = _count_mapping(
|
|
1404
|
+
context.get("backfilled_weak_source_locality_role_counts")
|
|
1405
|
+
)
|
|
1406
|
+
context_backfilled_source_proximity_support_count = (
|
|
1407
|
+
_positive_int(
|
|
1408
|
+
context.get("backfilled_source_proximity_support_count")
|
|
1409
|
+
)
|
|
1410
|
+
or 0
|
|
1411
|
+
)
|
|
1412
|
+
context_backfilled_chained_source_proximity_support_count = (
|
|
1413
|
+
_positive_int(
|
|
1414
|
+
context.get(
|
|
1415
|
+
"backfilled_chained_source_proximity_support_count"
|
|
1416
|
+
)
|
|
1417
|
+
)
|
|
1418
|
+
or 0
|
|
1419
|
+
)
|
|
1420
|
+
context_backfilled_source_proximity_closest_distance = _positive_int(
|
|
1421
|
+
context.get("backfilled_source_proximity_closest_distance")
|
|
1422
|
+
)
|
|
1423
|
+
if context_backfilled_source_proximity_closest_distance is not None:
|
|
1424
|
+
backfilled_source_proximity_closest_distances.append(
|
|
1425
|
+
context_backfilled_source_proximity_closest_distance
|
|
1426
|
+
)
|
|
1427
|
+
source_type_diversities.append(
|
|
1428
|
+
_positive_int(context.get("bundle_source_type_diversity")) or 0
|
|
1429
|
+
)
|
|
1430
|
+
retrieval_source_diversities.append(
|
|
1431
|
+
_positive_int(context.get("bundle_retrieval_source_diversity")) or 0
|
|
1432
|
+
)
|
|
1433
|
+
source_type_support_diversities.append(
|
|
1434
|
+
_positive_int(context.get("bundle_source_type_support_diversity"))
|
|
1435
|
+
or 0
|
|
1436
|
+
)
|
|
1437
|
+
retrieval_source_support_diversities.append(
|
|
1438
|
+
_positive_int(
|
|
1439
|
+
context.get("bundle_retrieval_source_support_diversity")
|
|
1440
|
+
)
|
|
1441
|
+
or 0
|
|
1442
|
+
)
|
|
1443
|
+
answerability_score = _metric_value(context, "avg_answerability_score")
|
|
1444
|
+
answerability_scores.append(answerability_score)
|
|
1445
|
+
measured_answerability_score = _metric_value(
|
|
1446
|
+
context,
|
|
1447
|
+
"avg_measured_answerability_score",
|
|
1448
|
+
)
|
|
1449
|
+
if measured_answerability_score > 0:
|
|
1450
|
+
measured_answerability_scores.append(measured_answerability_score)
|
|
1451
|
+
unmeasured_answerability_count += (
|
|
1452
|
+
_positive_int(context.get("unmeasured_answerability_count")) or 0
|
|
1453
|
+
)
|
|
1454
|
+
source_locality_score = _metric_value(
|
|
1455
|
+
context,
|
|
1456
|
+
"avg_source_locality_score",
|
|
1457
|
+
)
|
|
1458
|
+
source_locality_scores.append(source_locality_score)
|
|
1459
|
+
measured_source_locality_score = _metric_value(
|
|
1460
|
+
context,
|
|
1461
|
+
"avg_measured_source_locality_score",
|
|
1462
|
+
)
|
|
1463
|
+
if measured_source_locality_score > 0:
|
|
1464
|
+
measured_source_locality_scores.append(measured_source_locality_score)
|
|
1465
|
+
unmeasured_source_locality_count += (
|
|
1466
|
+
_positive_int(context.get("unmeasured_source_locality_count")) or 0
|
|
1467
|
+
)
|
|
1468
|
+
missing_required_roles = _str_tuple(context.get("missing_required_roles"))
|
|
1469
|
+
if missing_required_roles:
|
|
1470
|
+
missing_required_role_context_count += 1
|
|
1471
|
+
missing_required_role_counts.update(missing_required_roles)
|
|
1472
|
+
if context_backfilled_count > 0:
|
|
1473
|
+
backfilled_missing_required_role_counts.update(
|
|
1474
|
+
missing_required_roles
|
|
1475
|
+
)
|
|
1476
|
+
risk_reasons = _answer_context_risk_reasons(
|
|
1477
|
+
context,
|
|
1478
|
+
skipped_duplicate_source_bundle_item_count=(
|
|
1479
|
+
context_skipped_duplicate_source_bundle_item_count
|
|
1480
|
+
),
|
|
1481
|
+
skipped_noisy_overlap_bundle_item_count=(
|
|
1482
|
+
context_skipped_noisy_overlap_bundle_item_count
|
|
1483
|
+
),
|
|
1484
|
+
backfilled_retrieval_item_count=context_backfilled_count,
|
|
1485
|
+
skipped_redundant_risky_backfill_count=(
|
|
1486
|
+
context_skipped_redundant_risky_backfill_count
|
|
1487
|
+
),
|
|
1488
|
+
skipped_redundant_source_backfill_count=(
|
|
1489
|
+
context_skipped_redundant_source_backfill_count
|
|
1490
|
+
),
|
|
1491
|
+
skipped_redundant_role_backfill_count=(
|
|
1492
|
+
context_skipped_redundant_role_backfill_count
|
|
1493
|
+
),
|
|
1494
|
+
backfill_risk_stats={
|
|
1495
|
+
"backfilled_broad_summary_count": (
|
|
1496
|
+
context_backfilled_broad_summary_count
|
|
1497
|
+
),
|
|
1498
|
+
"backfilled_conflict_or_stale_count": (
|
|
1499
|
+
context_backfilled_conflict_or_stale_count
|
|
1500
|
+
),
|
|
1501
|
+
"backfilled_low_answerability_count": (
|
|
1502
|
+
context_backfilled_low_answerability_count
|
|
1503
|
+
),
|
|
1504
|
+
"backfilled_weak_source_locality_count": (
|
|
1505
|
+
context_backfilled_weak_source_locality_count
|
|
1506
|
+
),
|
|
1507
|
+
},
|
|
1508
|
+
)
|
|
1509
|
+
risk_reason_counts.update(risk_reasons)
|
|
1510
|
+
for reason in risk_reasons:
|
|
1511
|
+
risk_reason_source_counts[reason][source] += 1
|
|
1512
|
+
if risk_reasons:
|
|
1513
|
+
risk_reason_context_count += 1
|
|
1514
|
+
if fallback_reason:
|
|
1515
|
+
fallback_risk_context_count += 1
|
|
1516
|
+
risk_reason_context_samples.append(
|
|
1517
|
+
_answer_context_risk_sample(
|
|
1518
|
+
item=item,
|
|
1519
|
+
cutoff=cutoff,
|
|
1520
|
+
source=source,
|
|
1521
|
+
context=context,
|
|
1522
|
+
risk_reasons=risk_reasons,
|
|
1523
|
+
missing_required_roles=missing_required_roles,
|
|
1524
|
+
)
|
|
1525
|
+
)
|
|
1526
|
+
memory_count += context_memory_count
|
|
1527
|
+
source_ref_count += context_source_ref_count
|
|
1528
|
+
source_ref_item_count += context_source_ref_item_count
|
|
1529
|
+
source_refless_item_count += context_source_refless_item_count
|
|
1530
|
+
backfilled_retrieval_item_count += context_backfilled_count
|
|
1531
|
+
skipped_duplicate_source_bundle_item_count += (
|
|
1532
|
+
context_skipped_duplicate_source_bundle_item_count
|
|
1533
|
+
)
|
|
1534
|
+
skipped_noisy_overlap_bundle_item_count += (
|
|
1535
|
+
context_skipped_noisy_overlap_bundle_item_count
|
|
1536
|
+
)
|
|
1537
|
+
skipped_redundant_risky_backfill_count += (
|
|
1538
|
+
context_skipped_redundant_risky_backfill_count
|
|
1539
|
+
)
|
|
1540
|
+
skipped_redundant_source_backfill_count += (
|
|
1541
|
+
context_skipped_redundant_source_backfill_count
|
|
1542
|
+
)
|
|
1543
|
+
skipped_redundant_role_backfill_count += (
|
|
1544
|
+
context_skipped_redundant_role_backfill_count
|
|
1545
|
+
)
|
|
1546
|
+
backfilled_broad_summary_count += context_backfilled_broad_summary_count
|
|
1547
|
+
backfilled_conflict_or_stale_count += (
|
|
1548
|
+
context_backfilled_conflict_or_stale_count
|
|
1549
|
+
)
|
|
1550
|
+
backfilled_precise_source_overlap_count += (
|
|
1551
|
+
context_backfilled_precise_source_overlap_count
|
|
1552
|
+
)
|
|
1553
|
+
backfilled_low_answerability_count += (
|
|
1554
|
+
context_backfilled_low_answerability_count
|
|
1555
|
+
)
|
|
1556
|
+
backfilled_weak_source_locality_count += (
|
|
1557
|
+
context_backfilled_weak_source_locality_count
|
|
1558
|
+
)
|
|
1559
|
+
backfilled_low_answerability_role_counts.update(
|
|
1560
|
+
context_backfilled_low_answerability_role_counts
|
|
1561
|
+
)
|
|
1562
|
+
backfilled_weak_source_locality_role_counts.update(
|
|
1563
|
+
context_backfilled_weak_source_locality_role_counts
|
|
1564
|
+
)
|
|
1565
|
+
backfilled_source_proximity_support_count += (
|
|
1566
|
+
context_backfilled_source_proximity_support_count
|
|
1567
|
+
)
|
|
1568
|
+
backfilled_chained_source_proximity_support_count += (
|
|
1569
|
+
context_backfilled_chained_source_proximity_support_count
|
|
1570
|
+
)
|
|
1571
|
+
if context_backfilled_count > 0:
|
|
1572
|
+
backfilled_context_count += 1
|
|
1573
|
+
if context_skipped_duplicate_source_bundle_item_count > 0:
|
|
1574
|
+
duplicate_source_bundle_skip_context_count += 1
|
|
1575
|
+
if context_skipped_noisy_overlap_bundle_item_count > 0:
|
|
1576
|
+
noisy_overlap_bundle_skip_context_count += 1
|
|
1577
|
+
context_backfill_skip_count = (
|
|
1578
|
+
context_skipped_redundant_risky_backfill_count
|
|
1579
|
+
+ context_skipped_redundant_source_backfill_count
|
|
1580
|
+
+ context_skipped_redundant_role_backfill_count
|
|
1581
|
+
)
|
|
1582
|
+
if context_backfill_skip_count > 0:
|
|
1583
|
+
backfill_skip_context_count += 1
|
|
1584
|
+
if context_source_ref_count > 0 or context_source_ref_item_count > 0:
|
|
1585
|
+
source_ref_context_count += 1
|
|
1586
|
+
if context_source_refless_item_count > 0:
|
|
1587
|
+
source_refless_context_count += 1
|
|
1588
|
+
if (
|
|
1589
|
+
(context_source_ref_count > 0 or context_source_ref_item_count > 0)
|
|
1590
|
+
and context_source_refless_item_count > 0
|
|
1591
|
+
):
|
|
1592
|
+
mixed_source_context_count += 1
|
|
1593
|
+
if (
|
|
1594
|
+
context_skipped_duplicate_source_bundle_item_count > 0
|
|
1595
|
+
and len(duplicate_source_bundle_skip_context_samples) < 10
|
|
1596
|
+
):
|
|
1597
|
+
duplicate_source_bundle_skip_context_samples.append(
|
|
1598
|
+
{
|
|
1599
|
+
"case_id": str(item.get("case_id") or ""),
|
|
1600
|
+
"cutoff": cutoff,
|
|
1601
|
+
"source": source,
|
|
1602
|
+
"memory_count": context_memory_count,
|
|
1603
|
+
"skipped_duplicate_source_bundle_item_count": (
|
|
1604
|
+
context_skipped_duplicate_source_bundle_item_count
|
|
1605
|
+
),
|
|
1606
|
+
"source_ref_count": context_source_ref_count,
|
|
1607
|
+
"source_ref_item_count": context_source_ref_item_count,
|
|
1608
|
+
**(
|
|
1609
|
+
{"risk_reason_codes": list(risk_reasons)}
|
|
1610
|
+
if risk_reasons
|
|
1611
|
+
else {}
|
|
1612
|
+
),
|
|
1613
|
+
}
|
|
1614
|
+
)
|
|
1615
|
+
if (
|
|
1616
|
+
context_skipped_noisy_overlap_bundle_item_count > 0
|
|
1617
|
+
and len(noisy_overlap_bundle_skip_context_samples) < 10
|
|
1618
|
+
):
|
|
1619
|
+
noisy_overlap_bundle_skip_context_samples.append(
|
|
1620
|
+
{
|
|
1621
|
+
"case_id": str(item.get("case_id") or ""),
|
|
1622
|
+
"cutoff": cutoff,
|
|
1623
|
+
"source": source,
|
|
1624
|
+
"memory_count": context_memory_count,
|
|
1625
|
+
"skipped_noisy_overlap_bundle_item_count": (
|
|
1626
|
+
context_skipped_noisy_overlap_bundle_item_count
|
|
1627
|
+
),
|
|
1628
|
+
"source_ref_count": context_source_ref_count,
|
|
1629
|
+
"source_ref_item_count": context_source_ref_item_count,
|
|
1630
|
+
**(
|
|
1631
|
+
{"risk_reason_codes": list(risk_reasons)}
|
|
1632
|
+
if risk_reasons
|
|
1633
|
+
else {}
|
|
1634
|
+
),
|
|
1635
|
+
}
|
|
1636
|
+
)
|
|
1637
|
+
if (
|
|
1638
|
+
context_backfill_skip_count > 0
|
|
1639
|
+
and len(backfill_skip_context_samples) < 10
|
|
1640
|
+
):
|
|
1641
|
+
backfill_skip_context_samples.append(
|
|
1642
|
+
{
|
|
1643
|
+
"case_id": str(item.get("case_id") or ""),
|
|
1644
|
+
"cutoff": cutoff,
|
|
1645
|
+
"source": source,
|
|
1646
|
+
"memory_count": context_memory_count,
|
|
1647
|
+
"backfilled_retrieval_item_count": (
|
|
1648
|
+
context_backfilled_count
|
|
1649
|
+
),
|
|
1650
|
+
"skipped_redundant_risky_backfill_count": (
|
|
1651
|
+
context_skipped_redundant_risky_backfill_count
|
|
1652
|
+
),
|
|
1653
|
+
"skipped_redundant_source_backfill_count": (
|
|
1654
|
+
context_skipped_redundant_source_backfill_count
|
|
1655
|
+
),
|
|
1656
|
+
"skipped_redundant_role_backfill_count": (
|
|
1657
|
+
context_skipped_redundant_role_backfill_count
|
|
1658
|
+
),
|
|
1659
|
+
"missing_required_roles": list(missing_required_roles),
|
|
1660
|
+
**(
|
|
1661
|
+
{"risk_reason_codes": list(risk_reasons)}
|
|
1662
|
+
if risk_reasons
|
|
1663
|
+
else {}
|
|
1664
|
+
),
|
|
1665
|
+
}
|
|
1666
|
+
)
|
|
1667
|
+
if context_backfilled_count > 0 and len(backfilled_context_samples) < 10:
|
|
1668
|
+
backfilled_context_samples.append(
|
|
1669
|
+
{
|
|
1670
|
+
"case_id": str(item.get("case_id") or ""),
|
|
1671
|
+
"cutoff": cutoff,
|
|
1672
|
+
"source": source,
|
|
1673
|
+
"memory_count": context_memory_count,
|
|
1674
|
+
"backfilled_retrieval_item_count": (
|
|
1675
|
+
context_backfilled_count
|
|
1676
|
+
),
|
|
1677
|
+
"skipped_duplicate_source_bundle_item_count": (
|
|
1678
|
+
context_skipped_duplicate_source_bundle_item_count
|
|
1679
|
+
),
|
|
1680
|
+
"skipped_noisy_overlap_bundle_item_count": (
|
|
1681
|
+
context_skipped_noisy_overlap_bundle_item_count
|
|
1682
|
+
),
|
|
1683
|
+
"skipped_redundant_risky_backfill_count": (
|
|
1684
|
+
context_skipped_redundant_risky_backfill_count
|
|
1685
|
+
),
|
|
1686
|
+
"skipped_redundant_source_backfill_count": (
|
|
1687
|
+
context_skipped_redundant_source_backfill_count
|
|
1688
|
+
),
|
|
1689
|
+
"skipped_redundant_role_backfill_count": (
|
|
1690
|
+
context_skipped_redundant_role_backfill_count
|
|
1691
|
+
),
|
|
1692
|
+
"backfilled_broad_summary_count": (
|
|
1693
|
+
context_backfilled_broad_summary_count
|
|
1694
|
+
),
|
|
1695
|
+
"backfilled_conflict_or_stale_count": (
|
|
1696
|
+
context_backfilled_conflict_or_stale_count
|
|
1697
|
+
),
|
|
1698
|
+
"backfilled_precise_source_overlap_count": (
|
|
1699
|
+
context_backfilled_precise_source_overlap_count
|
|
1700
|
+
),
|
|
1701
|
+
"backfilled_low_answerability_count": (
|
|
1702
|
+
context_backfilled_low_answerability_count
|
|
1703
|
+
),
|
|
1704
|
+
"backfilled_weak_source_locality_count": (
|
|
1705
|
+
context_backfilled_weak_source_locality_count
|
|
1706
|
+
),
|
|
1707
|
+
**(
|
|
1708
|
+
{
|
|
1709
|
+
"backfilled_low_answerability_role_counts": dict(
|
|
1710
|
+
sorted(
|
|
1711
|
+
context_backfilled_low_answerability_role_counts.items()
|
|
1712
|
+
)
|
|
1713
|
+
)
|
|
1714
|
+
}
|
|
1715
|
+
if context_backfilled_low_answerability_role_counts
|
|
1716
|
+
else {}
|
|
1717
|
+
),
|
|
1718
|
+
**(
|
|
1719
|
+
{
|
|
1720
|
+
"backfilled_weak_source_locality_role_counts": dict(
|
|
1721
|
+
sorted(
|
|
1722
|
+
context_backfilled_weak_source_locality_role_counts.items()
|
|
1723
|
+
)
|
|
1724
|
+
)
|
|
1725
|
+
}
|
|
1726
|
+
if context_backfilled_weak_source_locality_role_counts
|
|
1727
|
+
else {}
|
|
1728
|
+
),
|
|
1729
|
+
"backfilled_source_proximity_support_count": (
|
|
1730
|
+
context_backfilled_source_proximity_support_count
|
|
1731
|
+
),
|
|
1732
|
+
"backfilled_chained_source_proximity_support_count": (
|
|
1733
|
+
context_backfilled_chained_source_proximity_support_count
|
|
1734
|
+
),
|
|
1735
|
+
"backfilled_source_proximity_closest_distance": (
|
|
1736
|
+
context_backfilled_source_proximity_closest_distance
|
|
1737
|
+
),
|
|
1738
|
+
"missing_required_roles": list(missing_required_roles),
|
|
1739
|
+
**_answer_context_sample_identity(context),
|
|
1740
|
+
**(
|
|
1741
|
+
{"risk_reason_codes": list(risk_reasons)}
|
|
1742
|
+
if risk_reasons
|
|
1743
|
+
else {}
|
|
1744
|
+
),
|
|
1745
|
+
}
|
|
1746
|
+
)
|
|
1747
|
+
if context_source_refless_item_count > 0 and len(
|
|
1748
|
+
source_refless_context_samples
|
|
1749
|
+
) < 10:
|
|
1750
|
+
source_refless_context_samples.append(
|
|
1751
|
+
{
|
|
1752
|
+
"case_id": str(item.get("case_id") or ""),
|
|
1753
|
+
"cutoff": cutoff,
|
|
1754
|
+
"source": source,
|
|
1755
|
+
"memory_count": context_memory_count,
|
|
1756
|
+
"source_refless_item_count": (
|
|
1757
|
+
context_source_refless_item_count
|
|
1758
|
+
),
|
|
1759
|
+
"fallback_reason": fallback_reason,
|
|
1760
|
+
**(
|
|
1761
|
+
{"source_ref_count": context_source_ref_count}
|
|
1762
|
+
if context_source_ref_count
|
|
1763
|
+
else {}
|
|
1764
|
+
),
|
|
1765
|
+
**(
|
|
1766
|
+
{"source_ref_item_count": context_source_ref_item_count}
|
|
1767
|
+
if context_source_ref_item_count
|
|
1768
|
+
else {}
|
|
1769
|
+
),
|
|
1770
|
+
**_answer_context_sample_identity(context),
|
|
1771
|
+
**(
|
|
1772
|
+
{"missing_required_roles": list(missing_required_roles)}
|
|
1773
|
+
if missing_required_roles
|
|
1774
|
+
else {}
|
|
1775
|
+
),
|
|
1776
|
+
**(
|
|
1777
|
+
{"risk_reason_codes": list(risk_reasons)}
|
|
1778
|
+
if risk_reasons
|
|
1779
|
+
else {}
|
|
1780
|
+
),
|
|
1781
|
+
}
|
|
1782
|
+
)
|
|
1783
|
+
if (
|
|
1784
|
+
(context_source_ref_count > 0 or context_source_ref_item_count > 0)
|
|
1785
|
+
and context_source_refless_item_count > 0
|
|
1786
|
+
and len(mixed_source_context_samples) < 10
|
|
1787
|
+
):
|
|
1788
|
+
mixed_source_context_samples.append(
|
|
1789
|
+
{
|
|
1790
|
+
"case_id": str(item.get("case_id") or ""),
|
|
1791
|
+
"cutoff": cutoff,
|
|
1792
|
+
"source": source,
|
|
1793
|
+
"memory_count": context_memory_count,
|
|
1794
|
+
"source_ref_count": context_source_ref_count,
|
|
1795
|
+
"source_ref_item_count": context_source_ref_item_count,
|
|
1796
|
+
"source_refless_item_count": (
|
|
1797
|
+
context_source_refless_item_count
|
|
1798
|
+
),
|
|
1799
|
+
"fallback_reason": fallback_reason,
|
|
1800
|
+
**_answer_context_sample_identity(context),
|
|
1801
|
+
**(
|
|
1802
|
+
{"missing_required_roles": list(missing_required_roles)}
|
|
1803
|
+
if missing_required_roles
|
|
1804
|
+
else {}
|
|
1805
|
+
),
|
|
1806
|
+
**(
|
|
1807
|
+
{"risk_reason_codes": list(risk_reasons)}
|
|
1808
|
+
if risk_reasons
|
|
1809
|
+
else {}
|
|
1810
|
+
),
|
|
1811
|
+
}
|
|
1812
|
+
)
|
|
1813
|
+
|
|
1814
|
+
return {
|
|
1815
|
+
"schema_version": "answer_context_provenance.v1",
|
|
1816
|
+
"context_count": context_count,
|
|
1817
|
+
"evidence_bundle_context_count": evidence_bundle_context_count,
|
|
1818
|
+
"fallback_context_count": fallback_context_count,
|
|
1819
|
+
"source_ref_context_count": source_ref_context_count,
|
|
1820
|
+
"source_refless_context_count": source_refless_context_count,
|
|
1821
|
+
"mixed_source_context_count": mixed_source_context_count,
|
|
1822
|
+
"memory_count": memory_count,
|
|
1823
|
+
"source_ref_count": source_ref_count,
|
|
1824
|
+
"source_ref_item_count": source_ref_item_count,
|
|
1825
|
+
"source_refless_item_count": source_refless_item_count,
|
|
1826
|
+
"backfilled_context_count": backfilled_context_count,
|
|
1827
|
+
"duplicate_source_bundle_skip_context_count": (
|
|
1828
|
+
duplicate_source_bundle_skip_context_count
|
|
1829
|
+
),
|
|
1830
|
+
"noisy_overlap_bundle_skip_context_count": (
|
|
1831
|
+
noisy_overlap_bundle_skip_context_count
|
|
1832
|
+
),
|
|
1833
|
+
"backfill_skip_context_count": backfill_skip_context_count,
|
|
1834
|
+
"backfilled_retrieval_item_count": backfilled_retrieval_item_count,
|
|
1835
|
+
"skipped_duplicate_source_bundle_item_count": (
|
|
1836
|
+
skipped_duplicate_source_bundle_item_count
|
|
1837
|
+
),
|
|
1838
|
+
"avg_skipped_duplicate_source_bundle_item_count": _ratio(
|
|
1839
|
+
skipped_duplicate_source_bundle_item_count,
|
|
1840
|
+
context_count,
|
|
1841
|
+
),
|
|
1842
|
+
"skipped_noisy_overlap_bundle_item_count": (
|
|
1843
|
+
skipped_noisy_overlap_bundle_item_count
|
|
1844
|
+
),
|
|
1845
|
+
"avg_skipped_noisy_overlap_bundle_item_count": _ratio(
|
|
1846
|
+
skipped_noisy_overlap_bundle_item_count,
|
|
1847
|
+
context_count,
|
|
1848
|
+
),
|
|
1849
|
+
"skipped_redundant_risky_backfill_count": (
|
|
1850
|
+
skipped_redundant_risky_backfill_count
|
|
1851
|
+
),
|
|
1852
|
+
"avg_skipped_redundant_risky_backfill_count": _ratio(
|
|
1853
|
+
skipped_redundant_risky_backfill_count,
|
|
1854
|
+
context_count,
|
|
1855
|
+
),
|
|
1856
|
+
"skipped_redundant_source_backfill_count": (
|
|
1857
|
+
skipped_redundant_source_backfill_count
|
|
1858
|
+
),
|
|
1859
|
+
"avg_skipped_redundant_source_backfill_count": _ratio(
|
|
1860
|
+
skipped_redundant_source_backfill_count,
|
|
1861
|
+
context_count,
|
|
1862
|
+
),
|
|
1863
|
+
"skipped_redundant_role_backfill_count": (
|
|
1864
|
+
skipped_redundant_role_backfill_count
|
|
1865
|
+
),
|
|
1866
|
+
"avg_skipped_redundant_role_backfill_count": _ratio(
|
|
1867
|
+
skipped_redundant_role_backfill_count,
|
|
1868
|
+
context_count,
|
|
1869
|
+
),
|
|
1870
|
+
"backfilled_broad_summary_count": backfilled_broad_summary_count,
|
|
1871
|
+
"backfilled_conflict_or_stale_count": backfilled_conflict_or_stale_count,
|
|
1872
|
+
"backfilled_precise_source_overlap_count": (
|
|
1873
|
+
backfilled_precise_source_overlap_count
|
|
1874
|
+
),
|
|
1875
|
+
"avg_backfilled_precise_source_overlap_count": _ratio(
|
|
1876
|
+
backfilled_precise_source_overlap_count,
|
|
1877
|
+
context_count,
|
|
1878
|
+
),
|
|
1879
|
+
"backfilled_low_answerability_count": backfilled_low_answerability_count,
|
|
1880
|
+
"avg_backfilled_low_answerability_count": _ratio(
|
|
1881
|
+
backfilled_low_answerability_count,
|
|
1882
|
+
context_count,
|
|
1883
|
+
),
|
|
1884
|
+
"backfilled_weak_source_locality_count": (
|
|
1885
|
+
backfilled_weak_source_locality_count
|
|
1886
|
+
),
|
|
1887
|
+
"avg_backfilled_weak_source_locality_count": _ratio(
|
|
1888
|
+
backfilled_weak_source_locality_count,
|
|
1889
|
+
context_count,
|
|
1890
|
+
),
|
|
1891
|
+
"backfilled_low_answerability_role_counts": dict(
|
|
1892
|
+
sorted(backfilled_low_answerability_role_counts.items())
|
|
1893
|
+
),
|
|
1894
|
+
"backfilled_weak_source_locality_role_counts": dict(
|
|
1895
|
+
sorted(backfilled_weak_source_locality_role_counts.items())
|
|
1896
|
+
),
|
|
1897
|
+
"backfilled_source_proximity_support_count": (
|
|
1898
|
+
backfilled_source_proximity_support_count
|
|
1899
|
+
),
|
|
1900
|
+
"avg_backfilled_source_proximity_support_count": _ratio(
|
|
1901
|
+
backfilled_source_proximity_support_count,
|
|
1902
|
+
context_count,
|
|
1903
|
+
),
|
|
1904
|
+
"backfilled_chained_source_proximity_support_count": (
|
|
1905
|
+
backfilled_chained_source_proximity_support_count
|
|
1906
|
+
),
|
|
1907
|
+
"avg_backfilled_chained_source_proximity_support_count": _ratio(
|
|
1908
|
+
backfilled_chained_source_proximity_support_count,
|
|
1909
|
+
context_count,
|
|
1910
|
+
),
|
|
1911
|
+
"avg_backfilled_source_proximity_closest_distance": _avg(
|
|
1912
|
+
backfilled_source_proximity_closest_distances
|
|
1913
|
+
),
|
|
1914
|
+
"min_backfilled_source_proximity_closest_distance": (
|
|
1915
|
+
min(backfilled_source_proximity_closest_distances)
|
|
1916
|
+
if backfilled_source_proximity_closest_distances
|
|
1917
|
+
else None
|
|
1918
|
+
),
|
|
1919
|
+
"avg_backfilled_retrieval_item_count": _ratio(
|
|
1920
|
+
backfilled_retrieval_item_count,
|
|
1921
|
+
context_count,
|
|
1922
|
+
),
|
|
1923
|
+
"source_ref_context_rate": _ratio(source_ref_context_count, context_count),
|
|
1924
|
+
"source_ref_item_coverage_rate": _ratio(
|
|
1925
|
+
source_ref_item_count,
|
|
1926
|
+
memory_count,
|
|
1927
|
+
),
|
|
1928
|
+
"avg_context_answerability_score": _avg(answerability_scores),
|
|
1929
|
+
"avg_measured_context_answerability_score": _avg(
|
|
1930
|
+
measured_answerability_scores
|
|
1931
|
+
),
|
|
1932
|
+
"total_unmeasured_context_answerability_count": (
|
|
1933
|
+
unmeasured_answerability_count
|
|
1934
|
+
),
|
|
1935
|
+
"avg_context_source_locality_score": _avg(source_locality_scores),
|
|
1936
|
+
"avg_measured_context_source_locality_score": _avg(
|
|
1937
|
+
measured_source_locality_scores
|
|
1938
|
+
),
|
|
1939
|
+
"total_unmeasured_context_source_locality_count": (
|
|
1940
|
+
unmeasured_source_locality_count
|
|
1941
|
+
),
|
|
1942
|
+
"avg_bundle_source_type_diversity": _avg(source_type_diversities),
|
|
1943
|
+
"max_bundle_source_type_diversity": (
|
|
1944
|
+
max(source_type_diversities) if source_type_diversities else 0
|
|
1945
|
+
),
|
|
1946
|
+
"avg_bundle_retrieval_source_diversity": _avg(
|
|
1947
|
+
retrieval_source_diversities
|
|
1948
|
+
),
|
|
1949
|
+
"max_bundle_retrieval_source_diversity": (
|
|
1950
|
+
max(retrieval_source_diversities)
|
|
1951
|
+
if retrieval_source_diversities
|
|
1952
|
+
else 0
|
|
1953
|
+
),
|
|
1954
|
+
"avg_bundle_source_type_support_diversity": _avg(
|
|
1955
|
+
source_type_support_diversities
|
|
1956
|
+
),
|
|
1957
|
+
"max_bundle_source_type_support_diversity": (
|
|
1958
|
+
max(source_type_support_diversities)
|
|
1959
|
+
if source_type_support_diversities
|
|
1960
|
+
else 0
|
|
1961
|
+
),
|
|
1962
|
+
"avg_bundle_retrieval_source_support_diversity": _avg(
|
|
1963
|
+
retrieval_source_support_diversities
|
|
1964
|
+
),
|
|
1965
|
+
"max_bundle_retrieval_source_support_diversity": (
|
|
1966
|
+
max(retrieval_source_support_diversities)
|
|
1967
|
+
if retrieval_source_support_diversities
|
|
1968
|
+
else 0
|
|
1969
|
+
),
|
|
1970
|
+
"source_counts": dict(sorted(source_counts.items())),
|
|
1971
|
+
"fallback_reason_counts": dict(sorted(fallback_reason_counts.items())),
|
|
1972
|
+
"missing_required_role_context_count": missing_required_role_context_count,
|
|
1973
|
+
"missing_required_role_total": sum(missing_required_role_counts.values()),
|
|
1974
|
+
"missing_required_role_counts": _top_counts(missing_required_role_counts),
|
|
1975
|
+
"backfilled_missing_required_role_counts": _top_counts(
|
|
1976
|
+
backfilled_missing_required_role_counts
|
|
1977
|
+
),
|
|
1978
|
+
"risk_reason_context_count": risk_reason_context_count,
|
|
1979
|
+
"fallback_risk_context_count": fallback_risk_context_count,
|
|
1980
|
+
"risk_reason_counts": _top_counts(risk_reason_counts),
|
|
1981
|
+
"risk_reason_source_counts": {
|
|
1982
|
+
reason: dict(sorted(source_counts.items()))
|
|
1983
|
+
for reason, source_counts in sorted(risk_reason_source_counts.items())
|
|
1984
|
+
},
|
|
1985
|
+
"risk_reason_context_samples": _ranked_answer_context_risk_samples(
|
|
1986
|
+
risk_reason_context_samples
|
|
1987
|
+
),
|
|
1988
|
+
"backfilled_context_samples": backfilled_context_samples,
|
|
1989
|
+
"backfill_skip_context_samples": backfill_skip_context_samples,
|
|
1990
|
+
"duplicate_source_bundle_skip_context_samples": (
|
|
1991
|
+
duplicate_source_bundle_skip_context_samples
|
|
1992
|
+
),
|
|
1993
|
+
"noisy_overlap_bundle_skip_context_samples": (
|
|
1994
|
+
noisy_overlap_bundle_skip_context_samples
|
|
1995
|
+
),
|
|
1996
|
+
"source_refless_context_samples": source_refless_context_samples,
|
|
1997
|
+
"mixed_source_context_samples": mixed_source_context_samples,
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
def _answer_context_risk_reasons(
|
|
2002
|
+
context: Mapping[str, object],
|
|
2003
|
+
*,
|
|
2004
|
+
skipped_duplicate_source_bundle_item_count: int,
|
|
2005
|
+
skipped_noisy_overlap_bundle_item_count: int,
|
|
2006
|
+
backfilled_retrieval_item_count: int,
|
|
2007
|
+
skipped_redundant_risky_backfill_count: int,
|
|
2008
|
+
skipped_redundant_source_backfill_count: int,
|
|
2009
|
+
skipped_redundant_role_backfill_count: int,
|
|
2010
|
+
backfill_risk_stats: Mapping[str, object],
|
|
2011
|
+
) -> tuple[str, ...]:
|
|
2012
|
+
explicit = _str_tuple(context.get("risk_reason_codes"))
|
|
2013
|
+
derived = _context_risk_reason_codes(
|
|
2014
|
+
bundle_risk_reason_codes=_str_tuple(context.get("bundle_risk_reason_codes")),
|
|
2015
|
+
skipped_duplicate_source_bundle_item_count=(
|
|
2016
|
+
skipped_duplicate_source_bundle_item_count
|
|
2017
|
+
),
|
|
2018
|
+
skipped_noisy_overlap_bundle_item_count=(
|
|
2019
|
+
skipped_noisy_overlap_bundle_item_count
|
|
2020
|
+
),
|
|
2021
|
+
backfilled_retrieval_item_count=backfilled_retrieval_item_count,
|
|
2022
|
+
skipped_redundant_risky_backfill_count=(
|
|
2023
|
+
skipped_redundant_risky_backfill_count
|
|
2024
|
+
),
|
|
2025
|
+
skipped_redundant_source_backfill_count=(
|
|
2026
|
+
skipped_redundant_source_backfill_count
|
|
2027
|
+
),
|
|
2028
|
+
skipped_redundant_role_backfill_count=(
|
|
2029
|
+
skipped_redundant_role_backfill_count
|
|
2030
|
+
),
|
|
2031
|
+
backfill_risk_stats=backfill_risk_stats,
|
|
2032
|
+
memory_metadata=(),
|
|
2033
|
+
)
|
|
2034
|
+
return _merge_risk_reason_codes(explicit, derived)
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
def _answer_contexts(
|
|
2038
|
+
item: Mapping[str, object],
|
|
2039
|
+
) -> tuple[tuple[str, Mapping[str, object]], ...]:
|
|
2040
|
+
contexts: list[tuple[str, Mapping[str, object]]] = []
|
|
2041
|
+
for cutoff, payload in _mapping(item.get("cutoff_results")).items():
|
|
2042
|
+
context = _mapping(_mapping(payload).get("answer_context"))
|
|
2043
|
+
if not context:
|
|
2044
|
+
continue
|
|
2045
|
+
contexts.append((str(cutoff), context))
|
|
2046
|
+
return tuple(
|
|
2047
|
+
sorted(
|
|
2048
|
+
contexts,
|
|
2049
|
+
key=lambda pair: (
|
|
2050
|
+
_positive_int(pair[0]) or 999999,
|
|
2051
|
+
pair[0],
|
|
2052
|
+
),
|
|
2053
|
+
)
|
|
2054
|
+
)
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
def _answer_context_sample_identity(context: Mapping[str, object]) -> dict[str, object]:
|
|
2058
|
+
item_ids = tuple(
|
|
2059
|
+
item_id
|
|
2060
|
+
for raw_item_id in _str_tuple(context.get("item_ids"))
|
|
2061
|
+
for item_id in (_safe_item_id_for_output(raw_item_id),)
|
|
2062
|
+
if item_id
|
|
2063
|
+
)[:_ANSWER_CONTEXT_SAMPLE_IDENTITY_LIMIT]
|
|
2064
|
+
retrieval_orders = tuple(
|
|
2065
|
+
order
|
|
2066
|
+
for raw_order in _sequence(context.get("retrieval_orders"))
|
|
2067
|
+
for order in (_positive_int(raw_order),)
|
|
2068
|
+
if order is not None
|
|
2069
|
+
)[:_ANSWER_CONTEXT_SAMPLE_IDENTITY_LIMIT]
|
|
2070
|
+
identity: dict[str, object] = {}
|
|
2071
|
+
if item_ids:
|
|
2072
|
+
identity["item_ids"] = list(item_ids)
|
|
2073
|
+
if retrieval_orders:
|
|
2074
|
+
identity["retrieval_orders"] = list(retrieval_orders)
|
|
2075
|
+
source_identity_refs = _safe_answer_context_source_identity_refs(
|
|
2076
|
+
context.get("source_identity_refs")
|
|
2077
|
+
)
|
|
2078
|
+
source_identity_ref_count = _positive_int(context.get("source_identity_ref_count"))
|
|
2079
|
+
if source_identity_ref_count is not None or source_identity_refs:
|
|
2080
|
+
identity["source_identity_ref_count"] = (
|
|
2081
|
+
source_identity_ref_count or len(source_identity_refs)
|
|
2082
|
+
)
|
|
2083
|
+
source_identity_item_count = _positive_int(
|
|
2084
|
+
context.get("source_identity_item_count")
|
|
2085
|
+
)
|
|
2086
|
+
if source_identity_item_count is not None:
|
|
2087
|
+
identity["source_identity_item_count"] = source_identity_item_count
|
|
2088
|
+
if source_identity_refs:
|
|
2089
|
+
identity["source_identity_refs"] = list(source_identity_refs)
|
|
2090
|
+
source_identity_items = _safe_answer_context_source_identity_items(
|
|
2091
|
+
context.get("source_identity_items")
|
|
2092
|
+
)
|
|
2093
|
+
if source_identity_items:
|
|
2094
|
+
identity["source_identity_items"] = list(source_identity_items)
|
|
2095
|
+
return identity
|
|
2096
|
+
|
|
2097
|
+
|
|
2098
|
+
def _safe_answer_context_source_identity_refs(value: object) -> tuple[str, ...]:
|
|
2099
|
+
refs = tuple(
|
|
2100
|
+
dict.fromkeys(
|
|
2101
|
+
ref
|
|
2102
|
+
for raw_ref in _sequence(value)
|
|
2103
|
+
for ref in (_safe_answer_context_source_identity_ref(raw_ref),)
|
|
2104
|
+
if ref
|
|
2105
|
+
)
|
|
2106
|
+
)
|
|
2107
|
+
return refs[:_ANSWER_CONTEXT_SAMPLE_IDENTITY_LIMIT]
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
def _safe_answer_context_source_identity_items(
|
|
2111
|
+
value: object,
|
|
2112
|
+
) -> tuple[dict[str, object], ...]:
|
|
2113
|
+
items: list[dict[str, object]] = []
|
|
2114
|
+
for raw_item in _sequence(value):
|
|
2115
|
+
item = _mapping(raw_item)
|
|
2116
|
+
refs = _safe_answer_context_source_identity_refs(
|
|
2117
|
+
item.get("source_identity_refs")
|
|
2118
|
+
)
|
|
2119
|
+
if not refs:
|
|
2120
|
+
continue
|
|
2121
|
+
compact: dict[str, object] = {"source_identity_refs": list(refs[:4])}
|
|
2122
|
+
item_id = _safe_item_id_for_output(item.get("item_id"))
|
|
2123
|
+
if item_id:
|
|
2124
|
+
compact["item_id"] = item_id
|
|
2125
|
+
retrieval_order = _positive_int(item.get("retrieval_order"))
|
|
2126
|
+
if retrieval_order is not None:
|
|
2127
|
+
compact["retrieval_order"] = retrieval_order
|
|
2128
|
+
items.append(compact)
|
|
2129
|
+
if len(items) >= _ANSWER_CONTEXT_SAMPLE_SOURCE_IDENTITY_ITEM_LIMIT:
|
|
2130
|
+
break
|
|
2131
|
+
return tuple(items)
|
|
2132
|
+
|
|
2133
|
+
|
|
2134
|
+
def _safe_answer_context_source_identity_ref(value: object) -> str | None:
|
|
2135
|
+
ref = str(value or "").strip()
|
|
2136
|
+
if not ref or len(ref) > 80:
|
|
2137
|
+
return None
|
|
2138
|
+
session_match = _LOCOMO_SESSION_TURN_IDENTITY_RE.fullmatch(ref)
|
|
2139
|
+
if session_match:
|
|
2140
|
+
prefix, session, day, turn = ref.split(":")
|
|
2141
|
+
return f"{prefix.lower()}:{session.lower()}:{day.upper()}:{turn}"
|
|
2142
|
+
turn_match = _LOCOMO_TURN_IDENTITY_RE.fullmatch(ref)
|
|
2143
|
+
if turn_match:
|
|
2144
|
+
prefix, day, turn = ref.split(":")
|
|
2145
|
+
return f"{prefix.lower()}:{day.upper()}:{turn}"
|
|
2146
|
+
return None
|
|
2147
|
+
|
|
2148
|
+
|
|
2149
|
+
def _query_plan_integrity_table(
|
|
2150
|
+
items: Sequence[Mapping[str, object]],
|
|
2151
|
+
) -> dict[str, object]:
|
|
2152
|
+
plan_count = 0
|
|
2153
|
+
plan_gap_case_count = 0
|
|
2154
|
+
selected_query_counts: list[int] = []
|
|
2155
|
+
dropped_query_count = 0
|
|
2156
|
+
fanout_limit_hit_count = 0
|
|
2157
|
+
type_limit_hit_count = 0
|
|
2158
|
+
empty_query_candidate_count = 0
|
|
2159
|
+
max_selected_query_token_count = 0
|
|
2160
|
+
missing_recommended_counts: Counter[str] = Counter()
|
|
2161
|
+
recommended_counts: Counter[str] = Counter()
|
|
2162
|
+
selected_family_counts: Counter[str] = Counter()
|
|
2163
|
+
dropped_family_counts: Counter[str] = Counter()
|
|
2164
|
+
role_family_counts: Counter[str] = Counter()
|
|
2165
|
+
selected_type_counts: Counter[str] = Counter()
|
|
2166
|
+
candidate_type_counts: Counter[str] = Counter()
|
|
2167
|
+
dropped_type_limit_role_counts: Counter[str] = Counter()
|
|
2168
|
+
replaced_type_limit_role_counts: Counter[str] = Counter()
|
|
2169
|
+
type_limit_replacement_role_counts: Counter[str] = Counter()
|
|
2170
|
+
required_evidence_role_counts: Counter[str] = Counter()
|
|
2171
|
+
missing_evidence_role_query_family_counts: Counter[str] = Counter()
|
|
2172
|
+
query_profile_flag_counts: Counter[str] = Counter()
|
|
2173
|
+
gap_reason_counts: Counter[str] = Counter()
|
|
2174
|
+
samples: list[dict[str, object]] = []
|
|
2175
|
+
|
|
2176
|
+
for item in items:
|
|
2177
|
+
query_plan = _query_plan(item)
|
|
2178
|
+
if not query_plan:
|
|
2179
|
+
continue
|
|
2180
|
+
plan_count += 1
|
|
2181
|
+
query_profile_flag_counts.update(_query_profile_flags(item))
|
|
2182
|
+
selected_query_counts.append(
|
|
2183
|
+
_positive_int(query_plan.get("selected_query_count")) or 0
|
|
2184
|
+
)
|
|
2185
|
+
dropped_count = _positive_int(query_plan.get("dropped_query_count")) or 0
|
|
2186
|
+
dropped_query_count += dropped_count
|
|
2187
|
+
|
|
2188
|
+
recommended_counts.update(
|
|
2189
|
+
_str_tuple(query_plan.get("recommended_role_families"))
|
|
2190
|
+
)
|
|
2191
|
+
required_evidence_roles = _required_evidence_roles(item)
|
|
2192
|
+
required_evidence_role_counts.update(required_evidence_roles)
|
|
2193
|
+
missing_recommended = _str_tuple(
|
|
2194
|
+
query_plan.get("missing_recommended_role_families")
|
|
2195
|
+
)
|
|
2196
|
+
missing_recommended_counts.update(missing_recommended)
|
|
2197
|
+
role_family_counts.update(
|
|
2198
|
+
_count_mapping_or_values(
|
|
2199
|
+
query_plan.get("role_family_counts"),
|
|
2200
|
+
query_plan.get("role_families"),
|
|
2201
|
+
)
|
|
2202
|
+
)
|
|
2203
|
+
selected_family_counts.update(
|
|
2204
|
+
_count_mapping_or_values(
|
|
2205
|
+
query_plan.get("selected_role_family_counts"),
|
|
2206
|
+
query_plan.get("selected_role_families"),
|
|
2207
|
+
)
|
|
2208
|
+
)
|
|
2209
|
+
dropped_family_counts.update(
|
|
2210
|
+
_count_mapping_or_values(
|
|
2211
|
+
query_plan.get("dropped_role_family_counts"),
|
|
2212
|
+
query_plan.get("dropped_role_families"),
|
|
2213
|
+
)
|
|
2214
|
+
)
|
|
2215
|
+
selected_type_counts.update(
|
|
2216
|
+
_count_mapping(query_plan.get("selected_type_counts"))
|
|
2217
|
+
)
|
|
2218
|
+
candidate_type_counts.update(
|
|
2219
|
+
_count_mapping(query_plan.get("candidate_type_counts"))
|
|
2220
|
+
)
|
|
2221
|
+
dropped_type_limit_role_counts.update(
|
|
2222
|
+
_str_tuple(query_plan.get("dropped_type_limit_roles"))
|
|
2223
|
+
)
|
|
2224
|
+
replaced_type_limit_roles = _str_tuple(
|
|
2225
|
+
query_plan.get("replaced_type_limit_roles")
|
|
2226
|
+
)
|
|
2227
|
+
replaced_type_limit_role_counts.update(replaced_type_limit_roles)
|
|
2228
|
+
type_limit_replacement_role_counts.update(
|
|
2229
|
+
_str_tuple(query_plan.get("type_limit_replacement_roles"))
|
|
2230
|
+
)
|
|
2231
|
+
selected_role_families = _str_tuple(query_plan.get("selected_role_families"))
|
|
2232
|
+
missing_evidence_role_query_families = (
|
|
2233
|
+
_missing_evidence_role_query_families(
|
|
2234
|
+
required_evidence_roles,
|
|
2235
|
+
selected_role_families=selected_role_families,
|
|
2236
|
+
)
|
|
2237
|
+
)
|
|
2238
|
+
missing_evidence_role_query_family_counts.update(
|
|
2239
|
+
missing_evidence_role_query_families
|
|
2240
|
+
)
|
|
2241
|
+
|
|
2242
|
+
fanout = _mapping(query_plan.get("fanout_integrity"))
|
|
2243
|
+
empty_count = (
|
|
2244
|
+
_positive_int(fanout.get("empty_query_candidate_count"))
|
|
2245
|
+
or _positive_int(query_plan.get("empty_query_candidate_count"))
|
|
2246
|
+
or 0
|
|
2247
|
+
)
|
|
2248
|
+
empty_query_candidate_count += empty_count
|
|
2249
|
+
token_count = _positive_int(fanout.get("max_selected_query_token_count")) or 0
|
|
2250
|
+
max_selected_query_token_count = max(max_selected_query_token_count, token_count)
|
|
2251
|
+
|
|
2252
|
+
gap_reasons: list[str] = []
|
|
2253
|
+
if missing_recommended:
|
|
2254
|
+
gap_reasons.append("missing_recommended_role_family")
|
|
2255
|
+
if missing_evidence_role_query_families:
|
|
2256
|
+
gap_reasons.append("missing_evidence_role_query_family")
|
|
2257
|
+
if dropped_count:
|
|
2258
|
+
gap_reasons.append("dropped_queries")
|
|
2259
|
+
if fanout.get("fanout_limit_hit") is True:
|
|
2260
|
+
fanout_limit_hit_count += 1
|
|
2261
|
+
gap_reasons.append("fanout_limit_hit")
|
|
2262
|
+
if fanout.get("type_limit_hit") is True:
|
|
2263
|
+
type_limit_hit_count += 1
|
|
2264
|
+
gap_reasons.append("type_limit_hit")
|
|
2265
|
+
if replaced_type_limit_roles:
|
|
2266
|
+
gap_reasons.append("type_limit_replacement")
|
|
2267
|
+
if empty_count:
|
|
2268
|
+
gap_reasons.append("empty_query_candidate")
|
|
2269
|
+
gap_reason_counts.update(gap_reasons)
|
|
2270
|
+
if gap_reasons:
|
|
2271
|
+
plan_gap_case_count += 1
|
|
2272
|
+
if len(samples) < 10:
|
|
2273
|
+
samples.append(
|
|
2274
|
+
_query_plan_gap_sample(
|
|
2275
|
+
item,
|
|
2276
|
+
query_plan,
|
|
2277
|
+
missing_recommended=missing_recommended,
|
|
2278
|
+
required_evidence_roles=required_evidence_roles,
|
|
2279
|
+
missing_evidence_role_query_families=(
|
|
2280
|
+
missing_evidence_role_query_families
|
|
2281
|
+
),
|
|
2282
|
+
gap_reasons=tuple(gap_reasons),
|
|
2283
|
+
fanout=fanout,
|
|
2284
|
+
)
|
|
2285
|
+
)
|
|
2286
|
+
|
|
2287
|
+
return {
|
|
2288
|
+
"schema_version": "query_plan_integrity.v1",
|
|
2289
|
+
"plan_count": plan_count,
|
|
2290
|
+
"plan_gap_case_count": plan_gap_case_count,
|
|
2291
|
+
"avg_selected_query_count": _avg(selected_query_counts),
|
|
2292
|
+
"dropped_query_count": dropped_query_count,
|
|
2293
|
+
"fanout_limit_hit_count": fanout_limit_hit_count,
|
|
2294
|
+
"type_limit_hit_count": type_limit_hit_count,
|
|
2295
|
+
"empty_query_candidate_count": empty_query_candidate_count,
|
|
2296
|
+
"max_selected_query_token_count": max_selected_query_token_count,
|
|
2297
|
+
"missing_recommended_role_family_total": sum(
|
|
2298
|
+
missing_recommended_counts.values()
|
|
2299
|
+
),
|
|
2300
|
+
"recommended_role_family_counts": _top_counts(recommended_counts),
|
|
2301
|
+
"missing_recommended_role_family_counts": _top_counts(
|
|
2302
|
+
missing_recommended_counts
|
|
2303
|
+
),
|
|
2304
|
+
"required_evidence_role_counts": _top_counts(required_evidence_role_counts),
|
|
2305
|
+
"missing_evidence_role_query_family_total": sum(
|
|
2306
|
+
missing_evidence_role_query_family_counts.values()
|
|
2307
|
+
),
|
|
2308
|
+
"missing_evidence_role_query_family_counts": _top_counts(
|
|
2309
|
+
missing_evidence_role_query_family_counts
|
|
2310
|
+
),
|
|
2311
|
+
"query_profile_flag_counts": _top_counts(query_profile_flag_counts),
|
|
2312
|
+
"role_family_counts": _top_counts(role_family_counts),
|
|
2313
|
+
"selected_role_family_counts": _top_counts(selected_family_counts),
|
|
2314
|
+
"dropped_role_family_counts": _top_counts(dropped_family_counts),
|
|
2315
|
+
"selected_type_counts": _top_counts(selected_type_counts),
|
|
2316
|
+
"candidate_type_counts": _top_counts(candidate_type_counts),
|
|
2317
|
+
"dropped_type_limit_role_counts": _top_counts(
|
|
2318
|
+
dropped_type_limit_role_counts
|
|
2319
|
+
),
|
|
2320
|
+
"replaced_type_limit_role_counts": _top_counts(
|
|
2321
|
+
replaced_type_limit_role_counts
|
|
2322
|
+
),
|
|
2323
|
+
"type_limit_replacement_role_counts": _top_counts(
|
|
2324
|
+
type_limit_replacement_role_counts
|
|
2325
|
+
),
|
|
2326
|
+
"gap_reason_counts": _top_counts(gap_reason_counts),
|
|
2327
|
+
"samples": samples,
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
|
|
2331
|
+
def _query_profile_flags(item: Mapping[str, object]) -> tuple[str, ...]:
|
|
2332
|
+
metadata = _retrieval_metadata(item)
|
|
2333
|
+
flags: list[str] = []
|
|
2334
|
+
for payload in _diagnostic_query_payloads(metadata):
|
|
2335
|
+
query_profile = _mapping(payload.get("query_profile"))
|
|
2336
|
+
if query_profile.get("comparative_option_preference_query") is True:
|
|
2337
|
+
flags.append("comparative_option_preference_query")
|
|
2338
|
+
return tuple(dict.fromkeys(flags))
|
|
2339
|
+
|
|
2340
|
+
|
|
2341
|
+
def _query_plan_gap_sample(
|
|
2342
|
+
item: Mapping[str, object],
|
|
2343
|
+
query_plan: Mapping[str, object],
|
|
2344
|
+
*,
|
|
2345
|
+
missing_recommended: Sequence[str],
|
|
2346
|
+
required_evidence_roles: Sequence[str],
|
|
2347
|
+
missing_evidence_role_query_families: Sequence[str],
|
|
2348
|
+
gap_reasons: Sequence[str],
|
|
2349
|
+
fanout: Mapping[str, object],
|
|
2350
|
+
) -> dict[str, object]:
|
|
2351
|
+
return {
|
|
2352
|
+
"case_id": str(item.get("case_id") or ""),
|
|
2353
|
+
"group": str(item.get("group") or ""),
|
|
2354
|
+
"gap_reasons": list(gap_reasons),
|
|
2355
|
+
"selected_query_count": _positive_int(
|
|
2356
|
+
query_plan.get("selected_query_count")
|
|
2357
|
+
)
|
|
2358
|
+
or 0,
|
|
2359
|
+
"dropped_query_count": _positive_int(query_plan.get("dropped_query_count"))
|
|
2360
|
+
or 0,
|
|
2361
|
+
"selected_roles": _str_tuple(query_plan.get("selected_roles")),
|
|
2362
|
+
"dropped_roles": _str_tuple(query_plan.get("dropped_roles")),
|
|
2363
|
+
"dropped_type_limit_roles": _str_tuple(
|
|
2364
|
+
query_plan.get("dropped_type_limit_roles")
|
|
2365
|
+
),
|
|
2366
|
+
"replaced_type_limit_roles": _str_tuple(
|
|
2367
|
+
query_plan.get("replaced_type_limit_roles")
|
|
2368
|
+
),
|
|
2369
|
+
"type_limit_replacement_roles": _str_tuple(
|
|
2370
|
+
query_plan.get("type_limit_replacement_roles")
|
|
2371
|
+
),
|
|
2372
|
+
"recommended_role_families": _str_tuple(
|
|
2373
|
+
query_plan.get("recommended_role_families")
|
|
2374
|
+
),
|
|
2375
|
+
"selected_role_families": _str_tuple(
|
|
2376
|
+
query_plan.get("selected_role_families")
|
|
2377
|
+
),
|
|
2378
|
+
"missing_recommended_role_families": tuple(missing_recommended),
|
|
2379
|
+
"required_evidence_roles": tuple(required_evidence_roles),
|
|
2380
|
+
"missing_evidence_role_query_families": tuple(
|
|
2381
|
+
missing_evidence_role_query_families
|
|
2382
|
+
),
|
|
2383
|
+
"selected_type_counts": _count_mapping(query_plan.get("selected_type_counts")),
|
|
2384
|
+
"candidate_type_counts": _count_mapping(
|
|
2385
|
+
query_plan.get("candidate_type_counts")
|
|
2386
|
+
),
|
|
2387
|
+
"fanout_limit_hit": fanout.get("fanout_limit_hit") is True,
|
|
2388
|
+
"type_limit_hit": fanout.get("type_limit_hit") is True,
|
|
2389
|
+
"empty_query_candidate_count": (
|
|
2390
|
+
_positive_int(fanout.get("empty_query_candidate_count")) or 0
|
|
2391
|
+
),
|
|
2392
|
+
"max_selected_query_token_count": (
|
|
2393
|
+
_positive_int(fanout.get("max_selected_query_token_count")) or 0
|
|
2394
|
+
),
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
|
|
2398
|
+
def _required_evidence_roles(item: Mapping[str, object]) -> tuple[str, ...]:
|
|
2399
|
+
bundle = _mapping(item.get("evidence_bundle"))
|
|
2400
|
+
roles = _str_tuple(bundle.get("required_roles"))
|
|
2401
|
+
if roles:
|
|
2402
|
+
return roles
|
|
2403
|
+
metadata = _retrieval_metadata(item)
|
|
2404
|
+
payloads = _diagnostic_query_payloads(metadata)
|
|
2405
|
+
return tuple(
|
|
2406
|
+
dict.fromkeys(
|
|
2407
|
+
role
|
|
2408
|
+
for payload in payloads
|
|
2409
|
+
for role in (
|
|
2410
|
+
_str_tuple(
|
|
2411
|
+
_mapping(payload.get("query_profile")).get(
|
|
2412
|
+
"bundle_evidence_roles"
|
|
2413
|
+
)
|
|
2414
|
+
)
|
|
2415
|
+
+ _str_tuple(
|
|
2416
|
+
_mapping(payload.get("retrieval_intent")).get(
|
|
2417
|
+
"bundle_evidence_roles"
|
|
2418
|
+
)
|
|
2419
|
+
)
|
|
2420
|
+
)
|
|
2421
|
+
)
|
|
2422
|
+
)
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
def _count_mapping_or_values(
|
|
2426
|
+
count_value: object,
|
|
2427
|
+
sequence_value: object,
|
|
2428
|
+
) -> Mapping[str, int]:
|
|
2429
|
+
counts = _count_mapping(count_value)
|
|
2430
|
+
if counts:
|
|
2431
|
+
return counts
|
|
2432
|
+
return Counter(_str_tuple(sequence_value))
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
def _diagnostic_query_payloads(
|
|
2436
|
+
metadata: Mapping[str, object],
|
|
2437
|
+
) -> tuple[Mapping[str, object], ...]:
|
|
2438
|
+
return (
|
|
2439
|
+
_mapping(metadata.get("query_decomposition")),
|
|
2440
|
+
_mapping(metadata.get("query_expansion")),
|
|
2441
|
+
_mapping(metadata.get("benchmark_rerank")),
|
|
2442
|
+
)
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
def _missing_evidence_role_query_families(
|
|
2446
|
+
required_evidence_roles: Sequence[str],
|
|
2447
|
+
*,
|
|
2448
|
+
selected_role_families: Sequence[str],
|
|
2449
|
+
) -> tuple[str, ...]:
|
|
2450
|
+
selected = set(selected_role_families)
|
|
2451
|
+
missing: list[str] = []
|
|
2452
|
+
for role in required_evidence_roles:
|
|
2453
|
+
role_key = str(role).strip()
|
|
2454
|
+
if not role_key:
|
|
2455
|
+
continue
|
|
2456
|
+
acceptable_families = _evidence_role_query_families(role_key)
|
|
2457
|
+
if acceptable_families and selected.intersection(acceptable_families):
|
|
2458
|
+
continue
|
|
2459
|
+
if not acceptable_families and selected:
|
|
2460
|
+
continue
|
|
2461
|
+
missing.append(role_key)
|
|
2462
|
+
return tuple(dict.fromkeys(missing))
|
|
2463
|
+
|
|
2464
|
+
|
|
2465
|
+
def _rerank_lift_table(items: Sequence[Mapping[str, object]]) -> dict[str, object]:
|
|
2466
|
+
boosted_count = 0
|
|
2467
|
+
positive_policy_scores: list[float] = []
|
|
2468
|
+
signal_counts: Counter[str] = Counter()
|
|
2469
|
+
policy_counts: Counter[str] = Counter()
|
|
2470
|
+
reason_counts: Counter[str] = Counter()
|
|
2471
|
+
safety_reason_counts: Counter[str] = Counter()
|
|
2472
|
+
relation_category_hit_counts: Counter[str] = Counter()
|
|
2473
|
+
low_answerability_lift_count = 0
|
|
2474
|
+
broad_summary_lift_count = 0
|
|
2475
|
+
conflict_or_stale_lift_count = 0
|
|
2476
|
+
direct_speaker_lift_count = 0
|
|
2477
|
+
provenance_safety_cap_count = 0
|
|
2478
|
+
samples: list[dict[str, object]] = []
|
|
2479
|
+
|
|
2480
|
+
for item in items:
|
|
2481
|
+
for memory in _sequence(_mapping(item.get("retrieval")).get("results")):
|
|
2482
|
+
if not isinstance(memory, Mapping):
|
|
2483
|
+
continue
|
|
2484
|
+
diagnostics = _memory_diagnostics(memory)
|
|
2485
|
+
features = _candidate_features(memory)
|
|
2486
|
+
score_signals = _mapping(diagnostics.get("score_signals"))
|
|
2487
|
+
positive_policy_score = _positive_policy_score(diagnostics)
|
|
2488
|
+
signal_names = _positive_signal_names(score_signals)
|
|
2489
|
+
lifted = _candidate_lifted(diagnostics)
|
|
2490
|
+
if not lifted:
|
|
2491
|
+
continue
|
|
2492
|
+
|
|
2493
|
+
boosted_count += 1
|
|
2494
|
+
positive_policy_scores.append(positive_policy_score)
|
|
2495
|
+
signal_counts.update(signal_names)
|
|
2496
|
+
relation_category_hit_counts.update(
|
|
2497
|
+
_str_tuple(features.get("relation_category_hits"))
|
|
2498
|
+
)
|
|
2499
|
+
|
|
2500
|
+
policy_reasons = _active_policy_reasons(diagnostics)
|
|
2501
|
+
policy_counts.update(policy_reasons.keys())
|
|
2502
|
+
for reasons in policy_reasons.values():
|
|
2503
|
+
reason_counts.update(reasons)
|
|
2504
|
+
|
|
2505
|
+
answerability_score = _metric_value(features, "answerability_score")
|
|
2506
|
+
if _is_measured_low_answerability(answerability_score):
|
|
2507
|
+
low_answerability_lift_count += 1
|
|
2508
|
+
if payload_has_broad_summary(memory, features):
|
|
2509
|
+
broad_summary_lift_count += 1
|
|
2510
|
+
if payload_has_conflict_or_stale(memory, features):
|
|
2511
|
+
conflict_or_stale_lift_count += 1
|
|
2512
|
+
if features.get("direct_speaker_turn") is True:
|
|
2513
|
+
direct_speaker_lift_count += 1
|
|
2514
|
+
safety_reason_codes = _str_tuple(
|
|
2515
|
+
score_signals.get("benchmark_provenance_safety_reason_codes")
|
|
2516
|
+
)
|
|
2517
|
+
if score_signals.get("benchmark_provenance_safety_cap_applied") is True:
|
|
2518
|
+
provenance_safety_cap_count += 1
|
|
2519
|
+
safety_reason_counts.update(safety_reason_codes)
|
|
2520
|
+
|
|
2521
|
+
if len(samples) < 10:
|
|
2522
|
+
samples.append(
|
|
2523
|
+
_rerank_lift_sample(
|
|
2524
|
+
item,
|
|
2525
|
+
memory,
|
|
2526
|
+
features=features,
|
|
2527
|
+
score_signals=score_signals,
|
|
2528
|
+
positive_policy_score=positive_policy_score,
|
|
2529
|
+
policy_reasons=policy_reasons,
|
|
2530
|
+
)
|
|
2531
|
+
)
|
|
2532
|
+
|
|
2533
|
+
return {
|
|
2534
|
+
"boosted_candidate_count": boosted_count,
|
|
2535
|
+
"avg_positive_policy_score": _avg(positive_policy_scores),
|
|
2536
|
+
"top_signal_counts": _top_counts(signal_counts),
|
|
2537
|
+
"top_policy_counts": _top_counts(policy_counts),
|
|
2538
|
+
"top_policy_reason_counts": _top_counts(reason_counts),
|
|
2539
|
+
"relation_category_hit_counts": _top_counts(relation_category_hit_counts),
|
|
2540
|
+
"low_answerability_lift_count": low_answerability_lift_count,
|
|
2541
|
+
"broad_summary_lift_count": broad_summary_lift_count,
|
|
2542
|
+
"conflict_or_stale_lift_count": conflict_or_stale_lift_count,
|
|
2543
|
+
"direct_speaker_lift_count": direct_speaker_lift_count,
|
|
2544
|
+
"provenance_safety_cap_count": provenance_safety_cap_count,
|
|
2545
|
+
"provenance_safety_reason_counts": _top_counts(safety_reason_counts),
|
|
2546
|
+
"samples": samples,
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
|
|
2550
|
+
def _rerank_lift_sample(
|
|
2551
|
+
item: Mapping[str, object],
|
|
2552
|
+
memory: Mapping[str, object],
|
|
2553
|
+
*,
|
|
2554
|
+
features: Mapping[str, object],
|
|
2555
|
+
score_signals: Mapping[str, object],
|
|
2556
|
+
positive_policy_score: float,
|
|
2557
|
+
policy_reasons: Mapping[str, tuple[str, ...]],
|
|
2558
|
+
) -> dict[str, object]:
|
|
2559
|
+
sample: dict[str, object] = {
|
|
2560
|
+
"case_id": str(item.get("case_id") or ""),
|
|
2561
|
+
"group": str(item.get("group") or ""),
|
|
2562
|
+
"item_id": _safe_item_id_for_output(_memory_id(memory)),
|
|
2563
|
+
"rank": _positive_int(memory.get("rank")) or 0,
|
|
2564
|
+
"score": round(_metric_value(memory, "score"), 6),
|
|
2565
|
+
"positive_policy_score": round(positive_policy_score, 6),
|
|
2566
|
+
"policy_reasons": {
|
|
2567
|
+
policy: list(reasons) for policy, reasons in sorted(policy_reasons.items())
|
|
2568
|
+
},
|
|
2569
|
+
"top_signals": _top_signal_values(score_signals),
|
|
2570
|
+
"relation_category_hits": _str_tuple(features.get("relation_category_hits")),
|
|
2571
|
+
"answerability_score": round(
|
|
2572
|
+
_metric_value(features, "answerability_score"),
|
|
2573
|
+
6,
|
|
2574
|
+
),
|
|
2575
|
+
"source_type": str(features.get("source_type") or "unknown"),
|
|
2576
|
+
"direct_speaker_turn": features.get("direct_speaker_turn") is True,
|
|
2577
|
+
"broad_summary": payload_has_broad_summary(memory, features),
|
|
2578
|
+
"conflict_or_stale": payload_has_conflict_or_stale(memory, features),
|
|
2579
|
+
}
|
|
2580
|
+
safety_reason_codes = _str_tuple(
|
|
2581
|
+
score_signals.get("benchmark_provenance_safety_reason_codes")
|
|
2582
|
+
)
|
|
2583
|
+
if score_signals.get("benchmark_provenance_safety_cap_applied") is True:
|
|
2584
|
+
sample["provenance_safety_cap_applied"] = True
|
|
2585
|
+
sample["provenance_safety_reason_codes"] = safety_reason_codes
|
|
2586
|
+
sample["effective_boost_cap"] = round(
|
|
2587
|
+
_metric_value(score_signals, "benchmark_effective_boost_cap"),
|
|
2588
|
+
6,
|
|
2589
|
+
)
|
|
2590
|
+
sample["uncapped_boost_cap"] = round(
|
|
2591
|
+
_metric_value(score_signals, "benchmark_uncapped_boost_cap"),
|
|
2592
|
+
6,
|
|
2593
|
+
)
|
|
2594
|
+
query_roles = _str_tuple(features.get("query_roles"))
|
|
2595
|
+
if query_roles:
|
|
2596
|
+
sample["query_roles"] = query_roles
|
|
2597
|
+
if features.get("bridge_query_hit") is True:
|
|
2598
|
+
sample["bridge_query_hit"] = True
|
|
2599
|
+
return sample
|
|
2600
|
+
|
|
2601
|
+
|
|
2602
|
+
def _candidate_lifted(diagnostics: Mapping[str, object]) -> bool:
|
|
2603
|
+
score_signals = _mapping(diagnostics.get("score_signals"))
|
|
2604
|
+
return (
|
|
2605
|
+
diagnostics.get("benchmark_rerank_boosted") is True
|
|
2606
|
+
or _positive_policy_score(diagnostics) > 0
|
|
2607
|
+
or bool(_positive_signal_names(score_signals))
|
|
2608
|
+
)
|
|
2609
|
+
|
|
2610
|
+
|
|
2611
|
+
def _false_positive_categories(
|
|
2612
|
+
items: Sequence[Mapping[str, object]],
|
|
2613
|
+
) -> dict[str, int]:
|
|
2614
|
+
counts: Counter[str] = Counter()
|
|
2615
|
+
for item in items:
|
|
2616
|
+
if item.get("scored") is not True:
|
|
2617
|
+
continue
|
|
2618
|
+
if _judgment_score(item) >= 1.0 and _expected_recall(item) >= 1.0:
|
|
2619
|
+
continue
|
|
2620
|
+
counts.update(_failure_categories(item))
|
|
2621
|
+
return dict(sorted(counts.items()))
|
|
2622
|
+
|
|
2623
|
+
|
|
2624
|
+
def _failure_categories(item: Mapping[str, object]) -> tuple[str, ...]:
|
|
2625
|
+
categories: list[str] = []
|
|
2626
|
+
if _expected_recall(item) < 1.0:
|
|
2627
|
+
categories.append("expected_terms_missing")
|
|
2628
|
+
if _evidence_recall(item) < 1.0 and _has_evidence_recall(item):
|
|
2629
|
+
categories.append("evidence_refs_missing")
|
|
2630
|
+
if not _bundle_complete(item):
|
|
2631
|
+
categories.append("bundle_incomplete")
|
|
2632
|
+
if _query_overlap_count(item) > 0:
|
|
2633
|
+
categories.append("query_leakage_risk")
|
|
2634
|
+
if _only_broad_bundle_evidence(item):
|
|
2635
|
+
categories.append("only_broad_bundle_evidence")
|
|
2636
|
+
if not _policy_contribution_table((item,)):
|
|
2637
|
+
categories.append("no_policy_diagnostics")
|
|
2638
|
+
return tuple(dict.fromkeys(categories or ("judge_failed_despite_retrieval",)))
|
|
2639
|
+
|
|
2640
|
+
|
|
2641
|
+
def _query_leakage_report(
|
|
2642
|
+
items: Sequence[Mapping[str, object]],
|
|
2643
|
+
) -> dict[str, object]:
|
|
2644
|
+
query_overlap = []
|
|
2645
|
+
profile_overlap = []
|
|
2646
|
+
intent_overlap = []
|
|
2647
|
+
for item in items:
|
|
2648
|
+
integrity = _query_integrity(item)
|
|
2649
|
+
query_count = _positive_int(
|
|
2650
|
+
integrity.get("expected_answer_query_overlap_count")
|
|
2651
|
+
) or 0
|
|
2652
|
+
profile_count = _positive_int(
|
|
2653
|
+
integrity.get("expected_answer_query_profile_overlap_count")
|
|
2654
|
+
) or 0
|
|
2655
|
+
intent_count = _positive_int(
|
|
2656
|
+
integrity.get("expected_answer_retrieval_intent_overlap_count")
|
|
2657
|
+
) or 0
|
|
2658
|
+
if query_count:
|
|
2659
|
+
query_overlap.append((item, query_count))
|
|
2660
|
+
if profile_count:
|
|
2661
|
+
profile_overlap.append((item, profile_count))
|
|
2662
|
+
if intent_count:
|
|
2663
|
+
intent_overlap.append((item, intent_count))
|
|
2664
|
+
return {
|
|
2665
|
+
"query_overlap_case_count": len(query_overlap),
|
|
2666
|
+
"profile_overlap_case_count": len(profile_overlap),
|
|
2667
|
+
"retrieval_intent_overlap_case_count": len(intent_overlap),
|
|
2668
|
+
"clean": not query_overlap and not profile_overlap and not intent_overlap,
|
|
2669
|
+
"query_overlap_samples": _overlap_samples(query_overlap),
|
|
2670
|
+
"profile_overlap_samples": _overlap_samples(profile_overlap),
|
|
2671
|
+
"retrieval_intent_overlap_samples": _overlap_samples(intent_overlap),
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2674
|
+
|
|
2675
|
+
def _leakage_counts(items: Sequence[Mapping[str, object]]) -> tuple[int, int, int]:
|
|
2676
|
+
query_overlap_count = 0
|
|
2677
|
+
profile_overlap_count = 0
|
|
2678
|
+
intent_overlap_count = 0
|
|
2679
|
+
for item in items:
|
|
2680
|
+
integrity = _query_integrity(item)
|
|
2681
|
+
query_overlap_count += (
|
|
2682
|
+
_positive_int(integrity.get("expected_answer_query_overlap_count")) or 0
|
|
2683
|
+
)
|
|
2684
|
+
profile_overlap_count += (
|
|
2685
|
+
_positive_int(
|
|
2686
|
+
integrity.get("expected_answer_query_profile_overlap_count")
|
|
2687
|
+
)
|
|
2688
|
+
or 0
|
|
2689
|
+
)
|
|
2690
|
+
intent_overlap_count += (
|
|
2691
|
+
_positive_int(
|
|
2692
|
+
integrity.get("expected_answer_retrieval_intent_overlap_count")
|
|
2693
|
+
)
|
|
2694
|
+
or 0
|
|
2695
|
+
)
|
|
2696
|
+
return query_overlap_count, profile_overlap_count, intent_overlap_count
|
|
2697
|
+
|
|
2698
|
+
|
|
2699
|
+
def _min_gate(actual: int, target: int) -> dict[str, object]:
|
|
2700
|
+
return {
|
|
2701
|
+
"passed": actual >= target,
|
|
2702
|
+
"actual": actual,
|
|
2703
|
+
"target": target,
|
|
2704
|
+
"mode": "min",
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
|
|
2708
|
+
def _zero_gate(actual: int) -> dict[str, object]:
|
|
2709
|
+
return {
|
|
2710
|
+
"passed": actual == 0,
|
|
2711
|
+
"actual": actual,
|
|
2712
|
+
"target": 0,
|
|
2713
|
+
"mode": "zero",
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
|
|
2717
|
+
def _overlap_samples(
|
|
2718
|
+
ranked: Sequence[tuple[Mapping[str, object], int]],
|
|
2719
|
+
) -> list[dict[str, object]]:
|
|
2720
|
+
samples: list[dict[str, object]] = []
|
|
2721
|
+
for item, count in sorted(ranked, key=lambda pair: pair[1], reverse=True)[:10]:
|
|
2722
|
+
integrity = _query_integrity(item)
|
|
2723
|
+
samples.append(
|
|
2724
|
+
{
|
|
2725
|
+
"case_id": str(item.get("case_id") or ""),
|
|
2726
|
+
"overlap_count": count,
|
|
2727
|
+
"query_terms": _str_tuple(
|
|
2728
|
+
integrity.get("expected_answer_query_overlap_terms")
|
|
2729
|
+
),
|
|
2730
|
+
"profile_terms": _str_tuple(
|
|
2731
|
+
integrity.get("expected_answer_query_profile_overlap_terms")
|
|
2732
|
+
),
|
|
2733
|
+
}
|
|
2734
|
+
)
|
|
2735
|
+
return samples
|
|
2736
|
+
|
|
2737
|
+
|
|
2738
|
+
def _evidence_ref_failure_sample(
|
|
2739
|
+
item: Mapping[str, object],
|
|
2740
|
+
required_refs: Sequence[str],
|
|
2741
|
+
ref_positions: Mapping[str, int],
|
|
2742
|
+
) -> dict[str, object]:
|
|
2743
|
+
missing_refs = [ref for ref in required_refs if ref not in ref_positions]
|
|
2744
|
+
return {
|
|
2745
|
+
"case_id": str(item.get("case_id") or ""),
|
|
2746
|
+
"required_refs": list(_safe_evidence_ref_terms(required_refs)),
|
|
2747
|
+
"found_refs": sorted(_safe_evidence_ref_terms(tuple(ref_positions))),
|
|
2748
|
+
"missing_refs": list(_safe_evidence_ref_terms(missing_refs)),
|
|
2749
|
+
"ref_positions": _safe_ref_positions_for_output(ref_positions),
|
|
2750
|
+
}
|
|
2751
|
+
|
|
2752
|
+
|
|
2753
|
+
def _safe_ref_positions_for_output(
|
|
2754
|
+
ref_positions: Mapping[str, int],
|
|
2755
|
+
) -> dict[str, int]:
|
|
2756
|
+
safe_positions: dict[str, int] = {}
|
|
2757
|
+
for ref, position in ref_positions.items():
|
|
2758
|
+
for safe_ref in _safe_evidence_ref_terms((ref,)):
|
|
2759
|
+
safe_positions[safe_ref] = min(
|
|
2760
|
+
safe_positions.get(safe_ref, position),
|
|
2761
|
+
position,
|
|
2762
|
+
)
|
|
2763
|
+
return dict(sorted(safe_positions.items()))
|
|
2764
|
+
|
|
2765
|
+
|
|
2766
|
+
def _required_evidence_refs(item: Mapping[str, object]) -> tuple[str, ...]:
|
|
2767
|
+
bundle = _mapping(item.get("evidence_bundle"))
|
|
2768
|
+
quality = _mapping(item.get("retrieval_quality"))
|
|
2769
|
+
return tuple(
|
|
2770
|
+
dict.fromkeys(
|
|
2771
|
+
(
|
|
2772
|
+
*_str_tuple(bundle.get("covered_evidence_terms")),
|
|
2773
|
+
*_str_tuple(quality.get("missing_evidence_terms")),
|
|
2774
|
+
)
|
|
2775
|
+
)
|
|
2776
|
+
)
|
|
2777
|
+
|
|
2778
|
+
|
|
2779
|
+
def _bundle_evidence_ref_positions(
|
|
2780
|
+
bundle: Mapping[str, object],
|
|
2781
|
+
) -> tuple[dict[str, int], dict[str, int]]:
|
|
2782
|
+
positions: dict[str, int] = {}
|
|
2783
|
+
focused_positions: dict[str, int] = {}
|
|
2784
|
+
for item in _bundle_items(bundle):
|
|
2785
|
+
retrieval_order = (
|
|
2786
|
+
_positive_int(item.get("retrieval_order"))
|
|
2787
|
+
or _positive_int(item.get("rank"))
|
|
2788
|
+
or 9999
|
|
2789
|
+
)
|
|
2790
|
+
focused = _metric_value(item, "focused_evidence_score") > 0
|
|
2791
|
+
for ref in _str_tuple(item.get("covered_evidence_terms")):
|
|
2792
|
+
positions[ref] = min(positions.get(ref, retrieval_order), retrieval_order)
|
|
2793
|
+
if focused:
|
|
2794
|
+
focused_positions[ref] = min(
|
|
2795
|
+
focused_positions.get(ref, retrieval_order),
|
|
2796
|
+
retrieval_order,
|
|
2797
|
+
)
|
|
2798
|
+
return positions, focused_positions
|