dandelion-memory 1.0.0rc15__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.
- benchmarks/__init__.py +3 -0
- benchmarks/adapters/__init__.py +29 -0
- benchmarks/adapters/ablations.py +406 -0
- benchmarks/adapters/base.py +72 -0
- benchmarks/adapters/controlled/__init__.py +13 -0
- benchmarks/adapters/controlled/core_archival.py +115 -0
- benchmarks/adapters/controlled/extract_resolve.py +130 -0
- benchmarks/adapters/controlled/hybrid_rag.py +120 -0
- benchmarks/adapters/controlled/no_late_binding.py +113 -0
- benchmarks/adapters/dandelion.py +94 -0
- benchmarks/adapters/native/__init__.py +31 -0
- benchmarks/adapters/native/base.py +45 -0
- benchmarks/adapters/native/dandelion_native.py +164 -0
- benchmarks/adapters/native/dandelion_native_b0.py +165 -0
- benchmarks/adapters/native/dandelion_native_b1.py +170 -0
- benchmarks/adapters/native/dandelion_native_b2.py +169 -0
- benchmarks/adapters/native/dandelion_native_b3.py +171 -0
- benchmarks/adapters/native/dandelion_native_c4.py +261 -0
- benchmarks/adapters/native/dandelion_native_c4_1.py +281 -0
- benchmarks/adapters/native/dandelion_native_c4_2.py +435 -0
- benchmarks/adapters/native/event_evidence_b2.py +616 -0
- benchmarks/adapters/native/evidence_b2.py +609 -0
- benchmarks/adapters/native/letta_native.py +253 -0
- benchmarks/adapters/native/mem0_native.py +219 -0
- benchmarks/adapters/native/store_vector_b0.py +792 -0
- benchmarks/adapters/native/store_vector_b2.py +808 -0
- benchmarks/agent_adapter_stdio_acceptance.py +86 -0
- benchmarks/bootstrap_cross_stack.py +218 -0
- benchmarks/canonical_profile_instrumentation.py +167 -0
- benchmarks/canonical_public_baseline.py +288 -0
- benchmarks/cli.py +525 -0
- benchmarks/collector_public30_offline.py +1653 -0
- benchmarks/datasets/__init__.py +45 -0
- benchmarks/datasets/conversational_generator.py +238 -0
- benchmarks/datasets/generator.py +283 -0
- benchmarks/datasets/holdout_topology_generator.py +290 -0
- benchmarks/datasets/holdout_topology_generator_v2.py +294 -0
- benchmarks/datasets/multi_world.py +1643 -0
- benchmarks/datasets/scale_generator.py +289 -0
- benchmarks/datasets/schema.py +57 -0
- benchmarks/deep_collision_stress.py +199 -0
- benchmarks/evaluators/__init__.py +12 -0
- benchmarks/evaluators/manifest.py +142 -0
- benchmarks/evaluators/metrics.py +277 -0
- benchmarks/evaluators/runner.py +258 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v1.py +127 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v2.py +127 -0
- benchmarks/f1_step0/build_dev_measurement_manifest_v3.py +146 -0
- benchmarks/f1_step0/build_ledger.py +143 -0
- benchmarks/f1_step0/build_ledger_v2.py +296 -0
- benchmarks/f1_step0/compare_dev52_readiness_v1.py +106 -0
- benchmarks/f1_step0/locator_public_smoke.py +172 -0
- benchmarks/f1_step0/prepare_dev52_owner_v1.py +133 -0
- benchmarks/f1_step0/prepare_dev52_owner_v2.py +133 -0
- benchmarks/f1_step0/public_identity_probe.py +191 -0
- benchmarks/f1_step0/public_response_mapper.py +101 -0
- benchmarks/f1_step0/real_source_public_preflight.py +244 -0
- benchmarks/f1_step0/run_exact_fusion_dev_experiment_v1.py +83 -0
- benchmarks/f1_step0/scorer.py +110 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v1.py +627 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v2.py +659 -0
- benchmarks/f1_step0/source_aware_dev_measurement_v3.py +776 -0
- benchmarks/f1_step0/test_public_response_mapper.py +110 -0
- benchmarks/f1_step0/test_real_source_public_preflight.py +25 -0
- benchmarks/f1_step0/test_scorer.py +158 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement.py +189 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement_v2.py +263 -0
- benchmarks/f1_step0/test_source_aware_dev_measurement_v3.py +334 -0
- benchmarks/f1_step0/typed_readback_public_smoke.py +181 -0
- benchmarks/forensic_c4_1_dev.py +258 -0
- benchmarks/forensic_c4_dev.py +255 -0
- benchmarks/forensic_deep25_c4_1.py +478 -0
- benchmarks/legacy_migration_acceptance.py +29 -0
- benchmarks/longmemeval_actor.py +497 -0
- benchmarks/longmemeval_agent_judge.py +593 -0
- benchmarks/longmemeval_budget.py +139 -0
- benchmarks/longmemeval_full.py +410 -0
- benchmarks/longmemeval_judge.py +327 -0
- benchmarks/longmemeval_pilot.py +316 -0
- benchmarks/longmemeval_s.py +318 -0
- benchmarks/memory_bench.py +248 -0
- benchmarks/memory_formation/__init__.py +1 -0
- benchmarks/memory_formation/audit.py +801 -0
- benchmarks/memory_formation/real_audit.py +688 -0
- benchmarks/memory_session_acceptance.py +279 -0
- benchmarks/native_codex_host.py +513 -0
- benchmarks/owner_dense_acceptance.py +126 -0
- benchmarks/pilot_seeker_vault.py +266 -0
- benchmarks/prepare_public30_ripgrep_range_owner.py +115 -0
- benchmarks/profile_canonical.py +373 -0
- benchmarks/profile_canonical_lanes.py +405 -0
- benchmarks/profile_search_chunks.py +351 -0
- benchmarks/public_ranges_faq_proof.py +121 -0
- benchmarks/public_repos/build_history_scope_v3.py +330 -0
- benchmarks/public_repos/build_oracle.py +108 -0
- benchmarks/public_repos/build_oracle_v2.py +169 -0
- benchmarks/public_repos/build_oracle_v3.py +176 -0
- benchmarks/public_repos/map_public_v2.py +296 -0
- benchmarks/public_repos/project_prompts_v2.py +31 -0
- benchmarks/public_repos/project_prompts_v3.py +29 -0
- benchmarks/public_repos/ready_admin_v2.py +214 -0
- benchmarks/public_repos/score_public_v2.py +258 -0
- benchmarks/public_repos/test_map_public_v2.py +171 -0
- benchmarks/public_repos/test_public_repo_v2.py +44 -0
- benchmarks/public_repos/test_public_repo_v3.py +46 -0
- benchmarks/public_repos/test_ready_admin_v2.py +117 -0
- benchmarks/public_repos/test_score_public_v2.py +163 -0
- benchmarks/public_repos/test_wire_v2.py +292 -0
- benchmarks/public_repos/wire_v2.py +603 -0
- benchmarks/real_blocker_fix_acceptance.py +155 -0
- benchmarks/real_scan_rescan_acceptance.py +41 -0
- benchmarks/recall_v2_20k_smoke.py +112 -0
- benchmarks/recall_v2_e1_retrieve.py +70 -0
- benchmarks/recall_v2_e1_score.py +271 -0
- benchmarks/recall_v2_e2_prepare.py +69 -0
- benchmarks/recall_v2_e2_public_score.py +91 -0
- benchmarks/recall_v2_e2_score.py +108 -0
- benchmarks/recall_v2_navigation_mcp_replay.py +308 -0
- benchmarks/recall_v2_reader_capture.py +118 -0
- benchmarks/recall_v2_reader_replay.py +136 -0
- benchmarks/run_blind_h10_holdout.py +284 -0
- benchmarks/run_blind_h9_holdout.py +275 -0
- benchmarks/run_c4_2_nightly_scale.py +446 -0
- benchmarks/run_context_scale_simulation.py +189 -0
- benchmarks/run_conversational_bench.py +170 -0
- benchmarks/run_h11_evaluation.py +316 -0
- benchmarks/run_h11_v2_evaluation.py +431 -0
- benchmarks/run_native_fixed12.py +469 -0
- benchmarks/run_native_preflight.py +280 -0
- benchmarks/run_scale_stress.py +225 -0
- benchmarks/solanazation_brownfield_01/build_oracle.py +970 -0
- benchmarks/solanazation_brownfield_01/check_level_a.py +78 -0
- benchmarks/solanazation_brownfield_01/debug_scope.py +13 -0
- benchmarks/solanazation_brownfield_01/evaluate_bootstrap_02.py +570 -0
- benchmarks/solanazation_brownfield_01/evaluate_first_pass.py +306 -0
- benchmarks/solanazation_brownfield_01/generate_dryrun_report.py +222 -0
- benchmarks/solanazation_brownfield_01/generate_manifests.py +146 -0
- benchmarks/solanazation_brownfield_01/inspect_misses.py +29 -0
- benchmarks/solanazation_brownfield_01/run_miss_forensic.py +206 -0
- benchmarks/solanazation_brownfield_01/test_facts.py +15 -0
- benchmarks/statistics/__init__.py +15 -0
- benchmarks/statistics/significance.py +326 -0
- benchmarks/test_native_mcp_preflight.py +229 -0
- benchmarks/test_prepare_public30_range_owner.py +35 -0
- benchmarks/test_public30_source_reference.py +698 -0
- benchmarks/test_recall_v2_e1_reader_input.py +89 -0
- benchmarks/test_recall_v2_navigation_mcp_replay.py +155 -0
- benchmarks/test_recall_v2_reader_replay.py +41 -0
- dandelion/__init__.py +3 -0
- dandelion/__main__.py +11 -0
- dandelion/agent_adapter.py +2369 -0
- dandelion/bootstrap/__init__.py +872 -0
- dandelion/bootstrap/alias_policy.py +50 -0
- dandelion/bootstrap/authority.py +225 -0
- dandelion/bootstrap/canonical_history.py +412 -0
- dandelion/bootstrap/classifier.py +403 -0
- dandelion/bootstrap/component_graph.py +280 -0
- dandelion/bootstrap/discovery.py +279 -0
- dandelion/bootstrap/domain_induction.py +180 -0
- dandelion/bootstrap/domain_topology.py +673 -0
- dandelion/bootstrap/evidence_envelope.py +132 -0
- dandelion/bootstrap/extractors/base.py +171 -0
- dandelion/bootstrap/extractors/exact.py +1234 -0
- dandelion/bootstrap/extractors/generic.py +100 -0
- dandelion/bootstrap/extractors/git_temporal.py +111 -0
- dandelion/bootstrap/extractors/registry.py +345 -0
- dandelion/bootstrap/extractors/relations.py +89 -0
- dandelion/bootstrap/extractors/semantic.py +424 -0
- dandelion/bootstrap/extractors/status.py +218 -0
- dandelion/bootstrap/git_sweeper.py +135 -0
- dandelion/bootstrap/manifest.py +246 -0
- dandelion/bootstrap/quarantine.py +264 -0
- dandelion/bootstrap/report.py +259 -0
- dandelion/bootstrap/root_resolver.py +221 -0
- dandelion/bootstrap/tech_profiler.py +125 -0
- dandelion/bootstrap/topology.py +75 -0
- dandelion/bootstrap/topology_index.py +110 -0
- dandelion/bootstrap/transaction.py +315 -0
- dandelion/canonical_bootstrap.py +257 -0
- dandelion/canonical_memory.py +4130 -0
- dandelion/captured_input.py +295 -0
- dandelion/cli.py +767 -0
- dandelion/config.py +40 -0
- dandelion/derived_index.py +745 -0
- dandelion/domains.py +706 -0
- dandelion/embedder.py +229 -0
- dandelion/event_evidence.py +571 -0
- dandelion/evidence.py +812 -0
- dandelion/evidence_response.py +453 -0
- dandelion/evidence_workspace.py +2360 -0
- dandelion/exact_context.py +129 -0
- dandelion/hydrator.py +124 -0
- dandelion/inspector.py +442 -0
- dandelion/inspector_assets/dandelion-mark.svg +33 -0
- dandelion/inspector_assets/dandelion_graph.js +361 -0
- dandelion/inspector_assets/inspector.css +223 -0
- dandelion/inspector_assets/inspector.html +135 -0
- dandelion/inspector_assets/inspector.js +1059 -0
- dandelion/legacy_import.py +431 -0
- dandelion/live_source_grants.py +133 -0
- dandelion/local_owner.py +114 -0
- dandelion/memory_client.py +252 -0
- dandelion/memory_contract.py +107 -0
- dandelion/memory_owner.py +560 -0
- dandelion/reader_providers.py +118 -0
- dandelion/recall_v2.py +767 -0
- dandelion/reconciler.py +219 -0
- dandelion/request_budget.py +125 -0
- dandelion/retained_basis.py +223 -0
- dandelion/retrieval.py +485 -0
- dandelion/router.py +405 -0
- dandelion/search_terms.py +53 -0
- dandelion/security.py +124 -0
- dandelion/server.py +810 -0
- dandelion/source_content_fts.py +219 -0
- dandelion/source_delivery.py +89 -0
- dandelion/source_history.py +241 -0
- dandelion/source_identity.py +88 -0
- dandelion/source_navigator.py +5 -0
- dandelion/source_reader.py +444 -0
- dandelion/source_references.py +379 -0
- dandelion/source_sections.py +265 -0
- dandelion/store_kv.py +684 -0
- dandelion/store_vector.py +1289 -0
- dandelion/studio.py +325 -0
- dandelion/wal.py +227 -0
- dandelion_memory-1.0.0rc15.dist-info/METADATA +48 -0
- dandelion_memory-1.0.0rc15.dist-info/RECORD +232 -0
- dandelion_memory-1.0.0rc15.dist-info/WHEEL +5 -0
- dandelion_memory-1.0.0rc15.dist-info/entry_points.txt +5 -0
- dandelion_memory-1.0.0rc15.dist-info/licenses/LICENSE +21 -0
- dandelion_memory-1.0.0rc15.dist-info/top_level.txt +2 -0
dandelion/evidence.py
ADDED
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
"""Epistemic Evidence Plane for Dandelion memory architecture.
|
|
2
|
+
|
|
3
|
+
The Epistemic Plane separates semantic similarity from grounding support:
|
|
4
|
+
- Semantic Plane: dense vectors, asymmetric passage/query embeddings ("What happened and why?")
|
|
5
|
+
- Symbolic Plane: KVStore, exact state, revisions, code identifiers ("What exactly is true?")
|
|
6
|
+
- Evidence Plane: support level, component scope, memory kind, entity/topic grounding ("What does this memory actually support?")
|
|
7
|
+
|
|
8
|
+
Core Thesis:
|
|
9
|
+
"Similarity finds candidates. Evidence decides whether they are knowledge. Dandelion separates relevance from support."
|
|
10
|
+
|
|
11
|
+
Operational constraint:
|
|
12
|
+
- 0 LLM calls on core memory path
|
|
13
|
+
- Deterministic, local, sub-millisecond execution
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import enum
|
|
19
|
+
import re
|
|
20
|
+
from dataclasses import dataclass, field, asdict
|
|
21
|
+
from typing import Optional, Any
|
|
22
|
+
|
|
23
|
+
from dandelion.domains import (
|
|
24
|
+
extract_component_root,
|
|
25
|
+
extract_domain_kind,
|
|
26
|
+
DomainRegistry,
|
|
27
|
+
ScopeResolutionStatus,
|
|
28
|
+
get_global_domain_registry,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# Technical Code Identifier Pattern
|
|
32
|
+
TECHNICAL_CODE_ID: re.Pattern = re.compile(
|
|
33
|
+
r"\b0x[a-fA-F0-9]{4,}\b|" # Hex addresses / hashes
|
|
34
|
+
r"\b[a-zA-Z0-9_]+/[a-zA-Z0-9_./\-]+\.[a-zA-Z0-9]+\b|" # File paths with extension (src/worker.py)
|
|
35
|
+
r"/(?:[a-zA-Z0-9_.\-]+/)+[a-zA-Z0-9_.\-]*\b|" # Absolute endpoints (/api/v1/...)
|
|
36
|
+
r"\b[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\b|" # Dotted symbols (api.port, config.yaml)
|
|
37
|
+
r"\b[A-Z0-9_]{2,}-[A-Z0-9_]{2,}\b|" # Hyphenated tags (POC-157, ADR-01)
|
|
38
|
+
r"\b[A-Z0-9]+_[A-Z0-9_]+\b|" # ALL_CAPS with underscore (ERR_TIMEOUT, HTTP_500)
|
|
39
|
+
r"\b[a-z]+[A-Z][a-zA-Z0-9]*\b|" # camelCase (getUserProfile)
|
|
40
|
+
r"\b[a-z0-9]+_[a-z0-9_]+\b|" # snake_case (droop_control)
|
|
41
|
+
r"\bADR\b|\bRFC\b" # Architectural decision / request for comment tags
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
QUERY_STOP_WORDS: set[str] = {
|
|
45
|
+
"why", "how", "what", "when", "where", "which", "who", "whom",
|
|
46
|
+
"this", "that", "with", "from", "into", "does", "have", "will",
|
|
47
|
+
"the", "for", "our", "and", "was", "were", "been", "about", "after",
|
|
48
|
+
"show", "find", "list", "check", "extract", "without", "during",
|
|
49
|
+
"not", "all", "can", "get", "set", "use", "has", "had", "are",
|
|
50
|
+
"you", "out", "per", "via", "but", "also", "during", "service",
|
|
51
|
+
"services", "system", "systems", "implementation", "details", "explain",
|
|
52
|
+
"describe", "overview", "note", "notes", "policy", "policies", "review",
|
|
53
|
+
"каков", "какой", "какая", "какие", "для", "после", "при", "как", "что",
|
|
54
|
+
"где", "когда", "почему", "это", "или", "все", "был", "была", "было",
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
COMMON_ACRONYM_EXCLUSIONS: set[str] = {
|
|
58
|
+
"CPU", "RAM", "RCA", "URL", "API", "SQL", "DNS", "SSH", "TCP", "UDP",
|
|
59
|
+
"AWS", "GCP", "SDK", "CLI", "IDE", "HTTP", "REST", "JSON", "YAML", "SIMD", "POST", "GET",
|
|
60
|
+
"DEK", "KEK", "AES", "GCM", "IV", "HMAC", "HKDF", "PBKDF2", "MWA", "SHA", "RSA", "ECC",
|
|
61
|
+
"TLS", "SSL", "RPC", "UI", "OS", "APK", "SAF", "PR", "CI", "CD",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
KNOWN_SOFTWARE_COMPONENTS: set[str] = {
|
|
65
|
+
"ecommerce", "identity", "streaming", "legaltech", "devtools", "fintech",
|
|
66
|
+
"telemetry", "search", "logistics", "healthcare", "energy", "gaming",
|
|
67
|
+
"iot", "biotech", "robotics", "edtech", "agritech", "aerospace",
|
|
68
|
+
"automotive", "quantum", "insurtech", "marinetech", "cleantech",
|
|
69
|
+
"miningtech", "govtech", "devops", "web3", "secops", "mlops", "mobile",
|
|
70
|
+
"dataeng", "messaging", "crm", "avionics", "genomics", "social",
|
|
71
|
+
"compiler", "hrtech", "traveltech", "audio", "autonomous", "soc",
|
|
72
|
+
"publishing", "maritime", "semiconductor", "pharmatech", "supplychain",
|
|
73
|
+
"space", "neurotech", "realestate",
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
# Cross-lingual equivalence pairs for bilingual support matching
|
|
77
|
+
CROSS_LINGUAL_PAIRS: list[tuple[str, str]] = [
|
|
78
|
+
("streaming", "streaming"),
|
|
79
|
+
("streaming", "асинхрон"),
|
|
80
|
+
("queue", "очеред"),
|
|
81
|
+
("grpc", "grpc"),
|
|
82
|
+
("approved", "утвердил"),
|
|
83
|
+
("decision", "решение"),
|
|
84
|
+
("decision", "переход"),
|
|
85
|
+
("asynchronous", "асинхрон"),
|
|
86
|
+
("communication", "streaming"),
|
|
87
|
+
("communication", "grpc"),
|
|
88
|
+
("processing", "обработк"),
|
|
89
|
+
("incident", "сбой"),
|
|
90
|
+
("incident", "авария"),
|
|
91
|
+
("incident", "падение"),
|
|
92
|
+
("incident", "отказ"),
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
COMMON_CAMEL_CASE_EXCLUSIONS: set[str] = {
|
|
97
|
+
"ediscovery", "ecommerce", "ebusiness", "egov"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@dataclass(frozen=True)
|
|
102
|
+
class ResolvedScope:
|
|
103
|
+
"""Structured scope resolution state for recall query (ARCH-SCOPE-01)."""
|
|
104
|
+
asserted_scope: Optional[str] # Canonical root asserted by query, e.g. "cryorocket"
|
|
105
|
+
retrieval_scope: Optional[str] # Execution boundary root, e.g. "synchrotron"
|
|
106
|
+
status: ScopeResolutionStatus # RESOLVED, EXPLICIT_UNRESOLVED, IMPLICIT_LOCAL
|
|
107
|
+
raw_asserted_text: str = "" # Raw string that triggered scope detection
|
|
108
|
+
effective_domain_root: str = "" # Valid domain root for downstream processing (empty if unresolved)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class ScopeResolver:
|
|
112
|
+
"""Open-world query scope resolver enforcing 'Unresolved != Local' (ARCH-SCOPE-01).
|
|
113
|
+
|
|
114
|
+
Separates:
|
|
115
|
+
1. RETRIEVAL SCOPE: caller execution boundary (e.g. domain_filter='synchrotron.ops')
|
|
116
|
+
2. ASSERTED SCOPE: explicit project asserted in query text (e.g. 'in Cryorocket Propulsion')
|
|
117
|
+
3. MEMORY SCOPE: canonical domain of stored memory
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
PREPS: list[str] = [
|
|
121
|
+
r"\bin\b", r"\bfor\b", r"\babout\b", r"\bof\b", r"\bregarding\b",
|
|
122
|
+
r"\bдля\b", r"\bв\b", r"\bпо\b", r"\bсервиса\b", r"\bо\b", r"\bоб\b",
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
NON_SCOPE_COMMON_PHRASES: set[str] = {
|
|
126
|
+
"the worker loop", "the queue", "staging", "production", "prod", "dev",
|
|
127
|
+
"the cluster", "this service", "this system", "the database", "our cluster",
|
|
128
|
+
"our system", "our team", "the team", "1998", "2024", "2025", "2026", "2027",
|
|
129
|
+
"a worker", "the pipeline", "synchronous processing", "asynchronous streaming",
|
|
130
|
+
"the staging environment", "the production environment", "execution",
|
|
131
|
+
"android", "android build", "android tests", "ios", "ios build", "ios tests",
|
|
132
|
+
"unit tests", "tests", "docker", "docker build",
|
|
133
|
+
"web", "frontend", "backend", "debug build", "release build", "linux", "windows", "macos",
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@classmethod
|
|
137
|
+
def _extract_scope_candidates(cls, query: str) -> list[str]:
|
|
138
|
+
cand_list: list[str] = []
|
|
139
|
+
positions: list[tuple[int, int]] = []
|
|
140
|
+
for prep in cls.PREPS:
|
|
141
|
+
for m in re.finditer(prep, query, re.IGNORECASE):
|
|
142
|
+
positions.append((m.start(), m.end()))
|
|
143
|
+
positions.sort(key=lambda x: x[0])
|
|
144
|
+
for _start, end in positions:
|
|
145
|
+
tail = query[end:].strip()
|
|
146
|
+
sub = re.split(
|
|
147
|
+
r"\s+(?:during|when|where|while|after|before|with|at|under|due to|caused by|resulting in|при|когда|где|после|до|с|со|из-за|вызванн\w*|what|how|why|which|is|was|were|has|have|did|does|do|что|как|почему|какой|какая|какие|был|была|было|были)\b|(?:\s+[.,:;?!]|[.,:;?!](?:\s+|$))",
|
|
148
|
+
tail,
|
|
149
|
+
flags=re.IGNORECASE,
|
|
150
|
+
)[0]
|
|
151
|
+
sub = sub.strip(".,;:?!- ")
|
|
152
|
+
if sub and sub not in cand_list:
|
|
153
|
+
cand_list.append(sub)
|
|
154
|
+
return cand_list
|
|
155
|
+
|
|
156
|
+
@classmethod
|
|
157
|
+
def _is_explicit_unresolved_scope(cls, cand: str) -> bool:
|
|
158
|
+
if not cand:
|
|
159
|
+
return False
|
|
160
|
+
# File paths, packages, or code extensions are never project scopes
|
|
161
|
+
if "/" in cand or "\\" in cand or cand.startswith("@") or any(cand.endswith(ext) for ext in (".py", ".ts", ".js", ".json", ".yaml", ".yml", ".md", ".rs", ".go", ".c", ".cpp", ".h", ".gradle", ".properties")):
|
|
162
|
+
return False
|
|
163
|
+
# Ticket, issue, file, or code element prefixes are not domain scopes
|
|
164
|
+
if re.match(r"^(?:ticket|issue|pr|commit|file|function|method|class|variable|tag|error|exception)\b", cand, re.IGNORECASE):
|
|
165
|
+
return False
|
|
166
|
+
|
|
167
|
+
clean = re.sub(
|
|
168
|
+
r"^(?:the\s+)?(?:project|service|cluster|stand|facility|проекте|проект|сервисе|сервис|стенде|стенд|системе|система|кластере|кластер)\s+",
|
|
169
|
+
"",
|
|
170
|
+
cand,
|
|
171
|
+
flags=re.IGNORECASE,
|
|
172
|
+
).strip()
|
|
173
|
+
words = clean.split()
|
|
174
|
+
if not words:
|
|
175
|
+
return False
|
|
176
|
+
if clean.lower() in cls.NON_SCOPE_COMMON_PHRASES or cand.lower() in cls.NON_SCOPE_COMMON_PHRASES:
|
|
177
|
+
return False
|
|
178
|
+
common_single_tokens = {
|
|
179
|
+
phrase for phrase in cls.NON_SCOPE_COMMON_PHRASES if " " not in phrase
|
|
180
|
+
}
|
|
181
|
+
if words[0].lower() in common_single_tokens:
|
|
182
|
+
return False
|
|
183
|
+
# CamelCase code symbols following a preposition ("in GameRoot") are
|
|
184
|
+
# identifiers, not unknown external projects.
|
|
185
|
+
if len(words) == 1 and re.match(r"^[A-Z]?[a-z]+[A-Z][A-Za-z0-9]*$", clean):
|
|
186
|
+
return False
|
|
187
|
+
# Check acronym exclusions across sub-tokens (e.g. AES-256-GCM -> AES, GCM)
|
|
188
|
+
for w in words:
|
|
189
|
+
for sub_w in re.split(r"[_\-.:/]+", w):
|
|
190
|
+
if sub_w and sub_w.upper() in COMMON_ACRONYM_EXCLUSIONS:
|
|
191
|
+
return False
|
|
192
|
+
|
|
193
|
+
has_capitalized = any(w[0].isupper() for w in words if w)
|
|
194
|
+
is_all_upper = clean.isupper() and len(clean) >= 3
|
|
195
|
+
has_project_marker = bool(
|
|
196
|
+
re.match(
|
|
197
|
+
r"^(?:the\s+)?(?:project|service|stand|facility|проект|сервис|стенд|система)\b",
|
|
198
|
+
cand,
|
|
199
|
+
re.IGNORECASE,
|
|
200
|
+
)
|
|
201
|
+
)
|
|
202
|
+
return (has_capitalized or is_all_upper) or (has_project_marker and len(words) >= 2)
|
|
203
|
+
|
|
204
|
+
@classmethod
|
|
205
|
+
def resolve(
|
|
206
|
+
cls,
|
|
207
|
+
query: str,
|
|
208
|
+
retrieval_scope: Optional[str] = None,
|
|
209
|
+
registry: Optional[DomainRegistry] = None,
|
|
210
|
+
) -> ResolvedScope:
|
|
211
|
+
from dandelion.domains import get_global_domain_registry, extract_component_root
|
|
212
|
+
|
|
213
|
+
reg = registry or get_global_domain_registry()
|
|
214
|
+
retrieval_root = extract_component_root(retrieval_scope) if retrieval_scope else None
|
|
215
|
+
|
|
216
|
+
# 1. Check uppercase acronyms / ticket prefixes against registered domains ONLY
|
|
217
|
+
upper_matches = re.findall(r"\b([A-Z]{3,})(?:-[A-Z0-9]+)?\b", query)
|
|
218
|
+
for tag in upper_matches:
|
|
219
|
+
if tag not in COMMON_ACRONYM_EXCLUSIONS:
|
|
220
|
+
m_root, _ = reg.match_domain(tag)
|
|
221
|
+
if m_root:
|
|
222
|
+
return ResolvedScope(
|
|
223
|
+
asserted_scope=m_root,
|
|
224
|
+
retrieval_scope=retrieval_root,
|
|
225
|
+
status=ScopeResolutionStatus.RESOLVED,
|
|
226
|
+
raw_asserted_text=tag,
|
|
227
|
+
effective_domain_root=m_root,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
# 2. Extract candidate phrases following prepositions (shortest/most specific first)
|
|
231
|
+
candidates = sorted(cls._extract_scope_candidates(query), key=len)
|
|
232
|
+
|
|
233
|
+
# 3. Check for exact/fuzzy registry matches across candidates
|
|
234
|
+
for cand in candidates:
|
|
235
|
+
# Embedded "of <Title>" inside candidate (e.g. "in the staging environment of Synchrotron")
|
|
236
|
+
of_match = re.search(
|
|
237
|
+
r"\bof\s+([A-Z\u0400-\u04FF][a-zA-Z0-9\u0400-\u04FF_& /,\-()]+)",
|
|
238
|
+
cand,
|
|
239
|
+
re.IGNORECASE,
|
|
240
|
+
)
|
|
241
|
+
if of_match:
|
|
242
|
+
sub_raw = of_match.group(1).strip(".,;:?!- ")
|
|
243
|
+
sub_root, _ = reg.match_domain(sub_raw)
|
|
244
|
+
if sub_root:
|
|
245
|
+
return ResolvedScope(
|
|
246
|
+
asserted_scope=sub_root,
|
|
247
|
+
retrieval_scope=retrieval_root,
|
|
248
|
+
status=ScopeResolutionStatus.RESOLVED,
|
|
249
|
+
raw_asserted_text=sub_raw,
|
|
250
|
+
effective_domain_root=sub_root,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
matched_root, conf = reg.match_domain(cand)
|
|
254
|
+
if matched_root:
|
|
255
|
+
return ResolvedScope(
|
|
256
|
+
asserted_scope=matched_root,
|
|
257
|
+
retrieval_scope=retrieval_root,
|
|
258
|
+
status=ScopeResolutionStatus.RESOLVED,
|
|
259
|
+
raw_asserted_text=cand,
|
|
260
|
+
effective_domain_root=matched_root,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
# Check if candidate matches a canonical software component root
|
|
264
|
+
if "/" not in cand and not cand.startswith("@") and not any(cand.endswith(ext) for ext in (".js", ".ts", ".py", ".json", ".gradle", ".properties")):
|
|
265
|
+
cand_tokens = [w.lower() for w in re.findall(r"[a-zA-Z0-9]+", cand)]
|
|
266
|
+
for t in cand_tokens:
|
|
267
|
+
if t in KNOWN_SOFTWARE_COMPONENTS and t not in {"streaming", "search", "mobile", "gaming", "social", "energy"}:
|
|
268
|
+
return ResolvedScope(
|
|
269
|
+
asserted_scope=t,
|
|
270
|
+
retrieval_scope=retrieval_root,
|
|
271
|
+
status=ScopeResolutionStatus.RESOLVED,
|
|
272
|
+
raw_asserted_text=cand,
|
|
273
|
+
effective_domain_root=t,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
# 4. If no registered match, check for explicit UNRESOLVED scope
|
|
277
|
+
# (Epistemic Invariant: "Unresolved != Local"!)
|
|
278
|
+
for cand in candidates:
|
|
279
|
+
if cls._is_explicit_unresolved_scope(cand):
|
|
280
|
+
return ResolvedScope(
|
|
281
|
+
asserted_scope=None,
|
|
282
|
+
retrieval_scope=retrieval_root,
|
|
283
|
+
status=ScopeResolutionStatus.EXPLICIT_UNRESOLVED,
|
|
284
|
+
raw_asserted_text=cand,
|
|
285
|
+
effective_domain_root="",
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
# 5. Default: No explicit external scope asserted -> implicit local scope
|
|
289
|
+
effective_root = retrieval_root or ""
|
|
290
|
+
if not effective_root:
|
|
291
|
+
registered_roots = list(reg.get_all_domains())
|
|
292
|
+
if len(registered_roots) == 1:
|
|
293
|
+
# A project-local store has one unambiguous execution context.
|
|
294
|
+
# This preserves natural component queries without promoting
|
|
295
|
+
# generic component names into global aliases. Multi-project
|
|
296
|
+
# stores remain open-world and deliberately do not guess.
|
|
297
|
+
effective_root = registered_roots[0]
|
|
298
|
+
return ResolvedScope(
|
|
299
|
+
asserted_scope=None,
|
|
300
|
+
retrieval_scope=retrieval_root,
|
|
301
|
+
status=ScopeResolutionStatus.IMPLICIT_LOCAL,
|
|
302
|
+
raw_asserted_text="",
|
|
303
|
+
effective_domain_root=effective_root,
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
class SupportLevel(str, enum.Enum):
|
|
308
|
+
"""Epistemic support level evaluating candidate memory against query evidence."""
|
|
309
|
+
STRONG = "STRONG" # Grounded structural / exact proof (fact ref, code ID match, component+topic match)
|
|
310
|
+
MEDIUM = "MEDIUM" # Grounded semantic match (component match + topic/action overlap, or high semantic similarity)
|
|
311
|
+
WEAK = "WEAK" # Bare semantic similarity without verified component/topic grounding
|
|
312
|
+
UNSUPPORTED = "UNSUPPORTED" # Contradicted component, ungrounded topic query, or missing mandatory identifier
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
@dataclass
|
|
316
|
+
class MemoryEvidence:
|
|
317
|
+
"""Evidence envelope stored in memory payload and resolved during recall."""
|
|
318
|
+
domain_root: str = ""
|
|
319
|
+
component_ids: list[str] = field(default_factory=list)
|
|
320
|
+
memory_kind: str = "general"
|
|
321
|
+
entities: list[str] = field(default_factory=list)
|
|
322
|
+
topics: list[str] = field(default_factory=list)
|
|
323
|
+
actions: list[str] = field(default_factory=list)
|
|
324
|
+
fact_refs: list[str] = field(default_factory=list)
|
|
325
|
+
template: str = ""
|
|
326
|
+
event_id: str = ""
|
|
327
|
+
event_sig: Optional[Any] = None
|
|
328
|
+
|
|
329
|
+
def to_dict(self) -> dict[str, Any]:
|
|
330
|
+
d = asdict(self)
|
|
331
|
+
if self.event_sig and hasattr(self.event_sig, "to_dict"):
|
|
332
|
+
d["event_sig"] = self.event_sig.to_dict()
|
|
333
|
+
else:
|
|
334
|
+
d.pop("event_sig", None)
|
|
335
|
+
return d
|
|
336
|
+
|
|
337
|
+
@classmethod
|
|
338
|
+
def from_dict(cls, data: dict[str, Any]) -> MemoryEvidence:
|
|
339
|
+
from dandelion.event_evidence import EventSignature
|
|
340
|
+
ev_sig = None
|
|
341
|
+
if data.get("event_sig"):
|
|
342
|
+
try:
|
|
343
|
+
ev_sig = EventSignature.from_dict(data["event_sig"])
|
|
344
|
+
except Exception:
|
|
345
|
+
ev_sig = None
|
|
346
|
+
return cls(
|
|
347
|
+
domain_root=data.get("domain_root", ""),
|
|
348
|
+
component_ids=data.get("component_ids", []),
|
|
349
|
+
memory_kind=data.get("memory_kind", "general"),
|
|
350
|
+
entities=data.get("entities", []),
|
|
351
|
+
topics=data.get("topics", []),
|
|
352
|
+
actions=data.get("actions", []),
|
|
353
|
+
fact_refs=data.get("fact_refs", []),
|
|
354
|
+
template=data.get("template", ""),
|
|
355
|
+
event_id=data.get("event_id", ""),
|
|
356
|
+
event_sig=ev_sig,
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
@dataclass
|
|
361
|
+
class QueryEvidence:
|
|
362
|
+
"""Structured evidence requirements parsed from a recall query."""
|
|
363
|
+
query: str
|
|
364
|
+
explicit_domains: list[str] = field(default_factory=list)
|
|
365
|
+
explicit_identifiers: list[str] = field(default_factory=list)
|
|
366
|
+
explicit_revs: list[tuple[str, int]] = field(default_factory=list)
|
|
367
|
+
requested_kind: Optional[str] = None
|
|
368
|
+
# True only for unambiguous lifecycle/evidence language. Broad words such
|
|
369
|
+
# as "enabled" still request status-aware ranking, but may also describe a
|
|
370
|
+
# configuration value and therefore must retain the general candidate lane.
|
|
371
|
+
explicit_kind_intent: bool = False
|
|
372
|
+
scoped_prefix: Optional[str] = None
|
|
373
|
+
scope_tokens: list[str] = field(default_factory=list)
|
|
374
|
+
substantive_topics: list[str] = field(default_factory=list)
|
|
375
|
+
is_cyrillic: bool = False
|
|
376
|
+
event_sig: Optional[Any] = None
|
|
377
|
+
resolved_scope: Optional[ResolvedScope] = None
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def extract_query_evidence(
|
|
381
|
+
query: str,
|
|
382
|
+
domain: Optional[str] = None,
|
|
383
|
+
explicit_revs: Optional[list[tuple[str, int]]] = None,
|
|
384
|
+
known_domains: Optional[set[str]] = None,
|
|
385
|
+
registry: Optional[DomainRegistry] = None,
|
|
386
|
+
) -> QueryEvidence:
|
|
387
|
+
"""Extract structured evidence requirements from a query."""
|
|
388
|
+
from dandelion.domains import get_global_domain_registry
|
|
389
|
+
|
|
390
|
+
reg = registry or get_global_domain_registry()
|
|
391
|
+
resolved_scope = ScopeResolver.resolve(query=query, retrieval_scope=domain, registry=reg)
|
|
392
|
+
|
|
393
|
+
q_lower = query.lower()
|
|
394
|
+
raw_tokens = set(re.findall(r"[a-zA-Z0-9\u0400-\u04FF]+", q_lower))
|
|
395
|
+
is_cyrillic = bool(re.search(r"[\u0400-\u04FF]", query))
|
|
396
|
+
|
|
397
|
+
# Incorporate dynamically known domain roots
|
|
398
|
+
components_pool = set(KNOWN_SOFTWARE_COMPONENTS)
|
|
399
|
+
known_roots: set[str] = set()
|
|
400
|
+
if known_domains:
|
|
401
|
+
for d in known_domains:
|
|
402
|
+
root = extract_component_root(d)
|
|
403
|
+
if root:
|
|
404
|
+
known_roots.add(root)
|
|
405
|
+
components_pool.add(root)
|
|
406
|
+
for root in reg.get_all_domains().keys():
|
|
407
|
+
known_roots.add(root)
|
|
408
|
+
components_pool.add(root)
|
|
409
|
+
|
|
410
|
+
# Scoped component root from ScopeResolver
|
|
411
|
+
scoped_prefix: Optional[str] = None
|
|
412
|
+
if resolved_scope.status == ScopeResolutionStatus.RESOLVED:
|
|
413
|
+
scoped_prefix = resolved_scope.asserted_scope
|
|
414
|
+
elif resolved_scope.status == ScopeResolutionStatus.IMPLICIT_LOCAL:
|
|
415
|
+
scoped_prefix = resolved_scope.effective_domain_root or (extract_component_root(domain) if domain else None)
|
|
416
|
+
elif resolved_scope.status == ScopeResolutionStatus.EXPLICIT_UNRESOLVED:
|
|
417
|
+
scoped_prefix = "__UNRESOLVED__"
|
|
418
|
+
|
|
419
|
+
# Fallback component extraction if no explicit project was asserted
|
|
420
|
+
if not scoped_prefix and resolved_scope.status == ScopeResolutionStatus.IMPLICIT_LOCAL:
|
|
421
|
+
ambiguous = {"streaming", "search", "mobile", "gaming", "social", "energy"}
|
|
422
|
+
search_pool = known_roots if known_roots else components_pool
|
|
423
|
+
for comp in sorted(search_pool, key=len, reverse=True):
|
|
424
|
+
if comp in raw_tokens and comp not in ambiguous:
|
|
425
|
+
scoped_prefix = comp
|
|
426
|
+
break
|
|
427
|
+
|
|
428
|
+
# Scope tokens associated with component
|
|
429
|
+
scope_tokens: set[str] = set()
|
|
430
|
+
if scoped_prefix and scoped_prefix != "__UNRESOLVED__":
|
|
431
|
+
scope_tokens.add(scoped_prefix)
|
|
432
|
+
if resolved_scope.status == ScopeResolutionStatus.RESOLVED:
|
|
433
|
+
dom_info = reg.get_domain(scoped_prefix)
|
|
434
|
+
if dom_info and dom_info.keywords:
|
|
435
|
+
scope_tokens.update(dom_info.keywords)
|
|
436
|
+
if resolved_scope.raw_asserted_text:
|
|
437
|
+
raw_words = re.findall(r"[a-zA-Z0-9\u0400-\u04FF]+", resolved_scope.raw_asserted_text.lower())
|
|
438
|
+
scope_tokens.update(raw_words)
|
|
439
|
+
if domain:
|
|
440
|
+
scope_tokens.update(re.findall(r"[a-zA-Z0-9\u0400-\u04FF]+", domain.lower()))
|
|
441
|
+
if known_domains:
|
|
442
|
+
for kd in known_domains:
|
|
443
|
+
scope_tokens.update(re.findall(r"[a-zA-Z0-9\u0400-\u04FF]+", kd.lower()))
|
|
444
|
+
|
|
445
|
+
# Code identifiers (excluding title words, acronyms, and non-code camelCase like eDiscovery)
|
|
446
|
+
code_ids = []
|
|
447
|
+
for ident in TECHNICAL_CODE_ID.findall(query):
|
|
448
|
+
cleaned = ident.strip(".:,-/")
|
|
449
|
+
parts = {p.lower() for p in re.split(r"[._\-]+", cleaned) if p}
|
|
450
|
+
if (
|
|
451
|
+
cleaned.lower() not in QUERY_STOP_WORDS
|
|
452
|
+
and cleaned not in COMMON_ACRONYM_EXCLUSIONS
|
|
453
|
+
and cleaned.lower() not in scope_tokens
|
|
454
|
+
and not (parts and parts.issubset(scope_tokens))
|
|
455
|
+
and cleaned.lower() not in COMMON_CAMEL_CASE_EXCLUSIONS
|
|
456
|
+
):
|
|
457
|
+
code_ids.append(cleaned)
|
|
458
|
+
|
|
459
|
+
# Memory kind intent
|
|
460
|
+
requested_kind: Optional[str] = None
|
|
461
|
+
explicit_kind_intent = False
|
|
462
|
+
if any(k in q_lower for k in ("incident", "outage", "failure", "crash", "postmortem", "post-mortem", "downtime", "alert", "500", "сбой", "инцидент", "авария")):
|
|
463
|
+
requested_kind = "incident"
|
|
464
|
+
elif any(k in q_lower for k in (
|
|
465
|
+
"status", "implemented", "implementation", "tested", "verified",
|
|
466
|
+
"deployed", "enabled", "disabled", "work in progress", "wip",
|
|
467
|
+
"accepted", "registered", "submitted", "confirmed", "turnkey release",
|
|
468
|
+
)) or re.match(r"^\s*(?:is|are|has|have)\b.{0,80}\bconfigured\b", q_lower):
|
|
469
|
+
requested_kind = "status"
|
|
470
|
+
explicit_kind_intent = any(k in q_lower for k in (
|
|
471
|
+
"status", "implemented", "implementation", "tested", "verified",
|
|
472
|
+
"deployed", "work in progress", "wip", "accepted", "registered",
|
|
473
|
+
"submitted", "confirmed", "turnkey release",
|
|
474
|
+
))
|
|
475
|
+
elif any(k in q_lower for k in (
|
|
476
|
+
"relationship", "relation between", "depends on", "dependency between",
|
|
477
|
+
"connects", "connected to", "integration between",
|
|
478
|
+
)):
|
|
479
|
+
requested_kind = "relation"
|
|
480
|
+
elif any(k in q_lower for k in ("architecture", "architectural", "adr", "rfc", "design", "архитектур")):
|
|
481
|
+
requested_kind = "architecture"
|
|
482
|
+
elif any(k in q_lower for k in ("config", "settings", "port", "host", "endpoint", "url", "key", "конфиг")):
|
|
483
|
+
requested_kind = "config"
|
|
484
|
+
elif any(k in q_lower for k in ("bug", "bugfix", "fix", "patch", "issue", "ошибк", "исправлен")):
|
|
485
|
+
requested_kind = "bugfix"
|
|
486
|
+
|
|
487
|
+
# Substantive question topics (tokens not in stop words, not in scope tokens, not kind keywords)
|
|
488
|
+
kind_noise = {
|
|
489
|
+
"incident", "outage", "failure", "crash", "postmortem", "downtime", "alert",
|
|
490
|
+
"architecture", "architectural", "design",
|
|
491
|
+
"config", "configuration", "settings", "options", "setup",
|
|
492
|
+
"bugfix", "reference", "general", "status", "implemented", "implementation",
|
|
493
|
+
"tested", "verified", "deployed", "enabled", "disabled", "relationship",
|
|
494
|
+
"relation", "depends", "dependency", "connects", "connected", "integration",
|
|
495
|
+
}
|
|
496
|
+
substantive_topics = set()
|
|
497
|
+
for tok in raw_tokens:
|
|
498
|
+
if (
|
|
499
|
+
len(tok) > 2
|
|
500
|
+
and tok not in QUERY_STOP_WORDS
|
|
501
|
+
and tok not in scope_tokens
|
|
502
|
+
and tok not in kind_noise
|
|
503
|
+
and not tok.isdigit()
|
|
504
|
+
):
|
|
505
|
+
substantive_topics.add(tok)
|
|
506
|
+
|
|
507
|
+
explicit_domains = [domain] if domain else []
|
|
508
|
+
from dandelion.event_evidence import PredicateNormalizer
|
|
509
|
+
ev_sig = PredicateNormalizer.extract_signature(
|
|
510
|
+
text=query,
|
|
511
|
+
domain_root=scoped_prefix or (explicit_domains[0].split(".")[0] if explicit_domains else ""),
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
return QueryEvidence(
|
|
515
|
+
query=query,
|
|
516
|
+
explicit_domains=explicit_domains,
|
|
517
|
+
explicit_identifiers=sorted(code_ids),
|
|
518
|
+
explicit_revs=explicit_revs or [],
|
|
519
|
+
requested_kind=requested_kind,
|
|
520
|
+
explicit_kind_intent=explicit_kind_intent,
|
|
521
|
+
scoped_prefix=scoped_prefix,
|
|
522
|
+
scope_tokens=sorted(scope_tokens),
|
|
523
|
+
substantive_topics=sorted(substantive_topics),
|
|
524
|
+
is_cyrillic=is_cyrillic,
|
|
525
|
+
event_sig=ev_sig,
|
|
526
|
+
resolved_scope=resolved_scope,
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
def extract_memory_evidence(
|
|
531
|
+
domain: str,
|
|
532
|
+
template: str,
|
|
533
|
+
referenced_facts: Optional[list[str]] = None,
|
|
534
|
+
event_id: str = "",
|
|
535
|
+
memory_kind: Optional[str] = None,
|
|
536
|
+
) -> MemoryEvidence:
|
|
537
|
+
"""Extract evidence envelope from memory domain and template."""
|
|
538
|
+
domain_root = extract_component_root(domain)
|
|
539
|
+
domain_kind = extract_domain_kind(domain)
|
|
540
|
+
|
|
541
|
+
# Component IDs from domain and template
|
|
542
|
+
comp_ids: set[str] = set()
|
|
543
|
+
if domain_root:
|
|
544
|
+
comp_ids.add(domain_root)
|
|
545
|
+
|
|
546
|
+
# Extract [PREFIX-123] or service name from template
|
|
547
|
+
prefix_match = re.findall(r"\b([A-Z]{3,})-\d+\b", template)
|
|
548
|
+
for p in prefix_match:
|
|
549
|
+
if p not in COMMON_ACRONYM_EXCLUSIONS:
|
|
550
|
+
comp_ids.add(p.lower())
|
|
551
|
+
|
|
552
|
+
t_lower = template.lower()
|
|
553
|
+
domain_segments = set(domain.lower().split("."))
|
|
554
|
+
comp_ids.update(p for p in domain_segments if p)
|
|
555
|
+
for comp in KNOWN_SOFTWARE_COMPONENTS:
|
|
556
|
+
if comp == domain_root or comp in domain_segments:
|
|
557
|
+
comp_ids.add(comp)
|
|
558
|
+
|
|
559
|
+
# Memory kind
|
|
560
|
+
mem_kind = memory_kind or domain_kind
|
|
561
|
+
if any(k in t_lower for k in ("incident", "outage", "failure", "crash", "postmortem", "alert", "500")):
|
|
562
|
+
if mem_kind == "general":
|
|
563
|
+
mem_kind = "incident"
|
|
564
|
+
elif any(k in t_lower for k in ("adr", "rfc", "architecture", "decision")):
|
|
565
|
+
if mem_kind == "general":
|
|
566
|
+
mem_kind = "architecture"
|
|
567
|
+
|
|
568
|
+
# Entities
|
|
569
|
+
entities = [
|
|
570
|
+
ident.strip(".:,-/")
|
|
571
|
+
for ident in TECHNICAL_CODE_ID.findall(template)
|
|
572
|
+
if ident.lower() not in QUERY_STOP_WORDS and ident not in COMMON_ACRONYM_EXCLUSIONS
|
|
573
|
+
]
|
|
574
|
+
|
|
575
|
+
# Fact refs
|
|
576
|
+
fact_refs = list(referenced_facts) if referenced_facts else []
|
|
577
|
+
in_tmpl_refs = re.findall(r"\{\{ref:([\w.]+)(?:@rev:\d+)?\}\}", template)
|
|
578
|
+
for r in in_tmpl_refs:
|
|
579
|
+
if r not in fact_refs:
|
|
580
|
+
fact_refs.append(r)
|
|
581
|
+
|
|
582
|
+
# Actions and Topics
|
|
583
|
+
raw_tokens = [w.lower().strip(".:,-/?!\"'(){}[]") for w in re.split(r"[\s\-._/]+", template)]
|
|
584
|
+
topics = [
|
|
585
|
+
tok for tok in raw_tokens
|
|
586
|
+
if (
|
|
587
|
+
len(tok) > 2
|
|
588
|
+
and tok not in QUERY_STOP_WORDS
|
|
589
|
+
and tok not in comp_ids
|
|
590
|
+
and not tok.isdigit()
|
|
591
|
+
)
|
|
592
|
+
]
|
|
593
|
+
|
|
594
|
+
from dandelion.event_evidence import PredicateNormalizer
|
|
595
|
+
m_sig = PredicateNormalizer.extract_signature(
|
|
596
|
+
text=template,
|
|
597
|
+
domain_root=domain_root,
|
|
598
|
+
event_id=event_id,
|
|
599
|
+
)
|
|
600
|
+
|
|
601
|
+
return MemoryEvidence(
|
|
602
|
+
domain_root=domain_root,
|
|
603
|
+
component_ids=sorted(comp_ids),
|
|
604
|
+
memory_kind=mem_kind,
|
|
605
|
+
entities=sorted(set(entities)),
|
|
606
|
+
topics=sorted(set(topics)),
|
|
607
|
+
actions=[],
|
|
608
|
+
fact_refs=sorted(set(fact_refs)),
|
|
609
|
+
template=template,
|
|
610
|
+
event_id=event_id,
|
|
611
|
+
event_sig=m_sig,
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
def resolve_evidence(
|
|
616
|
+
query_ev: QueryEvidence,
|
|
617
|
+
mem_ev: MemoryEvidence,
|
|
618
|
+
vector_score: float,
|
|
619
|
+
is_fact_boosted: bool = False,
|
|
620
|
+
enable_event_gate: bool = True,
|
|
621
|
+
) -> tuple[SupportLevel, float, str]:
|
|
622
|
+
"""Resolve whether candidate memory provides epistemic support for the query.
|
|
623
|
+
|
|
624
|
+
Returns:
|
|
625
|
+
(SupportLevel, evidence_score, reason)
|
|
626
|
+
"""
|
|
627
|
+
# 0. Scope Plane: ARCH-SCOPE-01 Open-World Scope Grounding
|
|
628
|
+
scope = getattr(query_ev, "resolved_scope", None)
|
|
629
|
+
if scope is not None:
|
|
630
|
+
if scope.status == ScopeResolutionStatus.EXPLICIT_UNRESOLVED:
|
|
631
|
+
return (
|
|
632
|
+
SupportLevel.UNSUPPORTED,
|
|
633
|
+
0.0,
|
|
634
|
+
f"Scope rejection: explicit asserted scope '{scope.raw_asserted_text}' is unresolved in registry (ungrounded)",
|
|
635
|
+
)
|
|
636
|
+
if scope.status == ScopeResolutionStatus.RESOLVED and scope.asserted_scope:
|
|
637
|
+
if mem_ev.domain_root and scope.asserted_scope != mem_ev.domain_root:
|
|
638
|
+
return (
|
|
639
|
+
SupportLevel.UNSUPPORTED,
|
|
640
|
+
0.0,
|
|
641
|
+
f"Scope conflict: asserted scope '{scope.asserted_scope}' != memory domain '{mem_ev.domain_root}'",
|
|
642
|
+
)
|
|
643
|
+
|
|
644
|
+
from dandelion.event_evidence import (
|
|
645
|
+
PredicateNormalizer,
|
|
646
|
+
EventRelation,
|
|
647
|
+
resolve_event_relation,
|
|
648
|
+
)
|
|
649
|
+
|
|
650
|
+
q_sig = getattr(query_ev, "event_sig", None)
|
|
651
|
+
if q_sig is None:
|
|
652
|
+
q_sig = PredicateNormalizer.extract_signature(
|
|
653
|
+
text=query_ev.query,
|
|
654
|
+
domain_root=query_ev.scoped_prefix or (query_ev.explicit_domains[0].split(".")[0] if query_ev.explicit_domains else ""),
|
|
655
|
+
)
|
|
656
|
+
|
|
657
|
+
m_sig = getattr(mem_ev, "event_sig", None)
|
|
658
|
+
if m_sig is None:
|
|
659
|
+
m_sig = PredicateNormalizer.extract_signature(
|
|
660
|
+
text=mem_ev.template or "",
|
|
661
|
+
domain_root=mem_ev.domain_root,
|
|
662
|
+
event_id=mem_ev.event_id or "",
|
|
663
|
+
)
|
|
664
|
+
|
|
665
|
+
typed_non_event_evidence = (
|
|
666
|
+
query_ev.requested_kind in {"status", "relation"}
|
|
667
|
+
and mem_ev.memory_kind == query_ev.requested_kind
|
|
668
|
+
)
|
|
669
|
+
has_event_semantics = not typed_non_event_evidence and (
|
|
670
|
+
q_sig.event_kind != "general"
|
|
671
|
+
or m_sig.event_kind != "general"
|
|
672
|
+
or bool(q_sig.trigger)
|
|
673
|
+
or bool(q_sig.failure_mode)
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
# 1. Symbolic Plane: Fact reverse lookup match
|
|
677
|
+
if is_fact_boosted:
|
|
678
|
+
if enable_event_gate and has_event_semantics:
|
|
679
|
+
rel = resolve_event_relation(q_sig, m_sig)
|
|
680
|
+
if rel == EventRelation.CONFLICTING_EVENT:
|
|
681
|
+
return SupportLevel.UNSUPPORTED, 0.0, f"Event evidence rejection: {rel.value} (ungrounded)"
|
|
682
|
+
return SupportLevel.STRONG, 1.0, "Symbolic fact match"
|
|
683
|
+
|
|
684
|
+
# 2. Symbolic Plane: Explicit code identifier gate
|
|
685
|
+
if query_ev.explicit_identifiers:
|
|
686
|
+
mem_ident_set = set(ident.lower() for ident in mem_ev.entities)
|
|
687
|
+
mem_topics_set = set(t.lower() for t in mem_ev.topics)
|
|
688
|
+
all_mem_tokens = mem_ident_set | mem_topics_set | set(mem_ev.component_ids)
|
|
689
|
+
|
|
690
|
+
has_ident_match = any(
|
|
691
|
+
qid.lower() in all_mem_tokens or any(qid.lower() in tok for tok in all_mem_tokens)
|
|
692
|
+
for qid in query_ev.explicit_identifiers
|
|
693
|
+
)
|
|
694
|
+
if has_ident_match:
|
|
695
|
+
if enable_event_gate and has_event_semantics:
|
|
696
|
+
rel = resolve_event_relation(q_sig, m_sig)
|
|
697
|
+
if rel == EventRelation.CONFLICTING_EVENT:
|
|
698
|
+
return SupportLevel.UNSUPPORTED, 0.0, f"Event evidence rejection: {rel.value} (ungrounded)"
|
|
699
|
+
return SupportLevel.STRONG, 0.95, "Code identifier match"
|
|
700
|
+
else:
|
|
701
|
+
return SupportLevel.UNSUPPORTED, 0.0, "Missing required code identifier (ungrounded)"
|
|
702
|
+
|
|
703
|
+
# 3. Event Plane: ARCH-EVENT-01 Structured Event Resolution
|
|
704
|
+
if enable_event_gate and has_event_semantics:
|
|
705
|
+
rel = resolve_event_relation(q_sig, m_sig)
|
|
706
|
+
if rel == EventRelation.CONFLICTING_EVENT:
|
|
707
|
+
return SupportLevel.UNSUPPORTED, 0.0, f"Event evidence rejection: {rel.value} (ungrounded)"
|
|
708
|
+
elif rel == EventRelation.SAME_EVENT:
|
|
709
|
+
return SupportLevel.STRONG, 0.95, "Verified event identity match"
|
|
710
|
+
elif rel == EventRelation.RELATED_EVENT:
|
|
711
|
+
if (q_sig.failure_mode and q_sig.failure_mode == m_sig.failure_mode and vector_score >= 0.60):
|
|
712
|
+
pass
|
|
713
|
+
else:
|
|
714
|
+
return SupportLevel.UNSUPPORTED, 0.0, f"Event evidence rejection: {rel.value} (ungrounded)"
|
|
715
|
+
elif rel == EventRelation.INSUFFICIENT_EVIDENCE:
|
|
716
|
+
if query_ev.requested_kind == "incident" or q_sig.event_kind == "incident":
|
|
717
|
+
mem_tokens = set(mem_ev.topics) | set(mem_ev.component_ids) | set(mem_ev.entities)
|
|
718
|
+
has_text_overlap = any(qt in mem_tokens for qt in query_ev.substantive_topics)
|
|
719
|
+
if not has_text_overlap:
|
|
720
|
+
return SupportLevel.UNSUPPORTED, 0.0, f"Event evidence rejection: {rel.value} (ungrounded)"
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
mem_tokens = set(mem_ev.topics) | set(mem_ev.component_ids) | set(mem_ev.entities)
|
|
724
|
+
|
|
725
|
+
# 3. Evidence Plane: Component-Scope Anchoring (SELECT-A)
|
|
726
|
+
scoped_prefix = query_ev.scoped_prefix
|
|
727
|
+
if scoped_prefix:
|
|
728
|
+
mem_comp_set = set(mem_ev.component_ids)
|
|
729
|
+
if mem_ev.domain_root:
|
|
730
|
+
mem_comp_set.add(mem_ev.domain_root)
|
|
731
|
+
|
|
732
|
+
if scoped_prefix not in mem_comp_set:
|
|
733
|
+
# Component mismatch: query explicitly scoped to a different component!
|
|
734
|
+
return SupportLevel.UNSUPPORTED, 0.0, f"Component mismatch ({mem_ev.domain_root} != {scoped_prefix})"
|
|
735
|
+
|
|
736
|
+
# Kind check: If query requested an incident, memory MUST be an incident
|
|
737
|
+
if query_ev.requested_kind == "incident":
|
|
738
|
+
if mem_ev.memory_kind != "incident":
|
|
739
|
+
return SupportLevel.UNSUPPORTED, 0.0, "Requested incident but memory is not an incident"
|
|
740
|
+
|
|
741
|
+
# Check substantive question topics
|
|
742
|
+
q_topics = query_ev.substantive_topics
|
|
743
|
+
topic_hits = 0
|
|
744
|
+
for qt in q_topics:
|
|
745
|
+
if qt in mem_tokens:
|
|
746
|
+
topic_hits += 1
|
|
747
|
+
else:
|
|
748
|
+
for mt in mem_tokens:
|
|
749
|
+
if len(qt) >= 4 and len(mt) >= 4 and (qt[:4] == mt[:4] or qt in mt or mt in qt):
|
|
750
|
+
topic_hits += 1
|
|
751
|
+
break
|
|
752
|
+
# Cross-lingual equivalence check
|
|
753
|
+
matched_cl = False
|
|
754
|
+
for eng, rus in CROSS_LINGUAL_PAIRS:
|
|
755
|
+
if (qt == eng and rus in mt) or (rus in qt and mt == eng):
|
|
756
|
+
topic_hits += 1
|
|
757
|
+
matched_cl = True
|
|
758
|
+
break
|
|
759
|
+
if matched_cl:
|
|
760
|
+
break
|
|
761
|
+
|
|
762
|
+
if q_topics and topic_hits == 0:
|
|
763
|
+
# Component matched, but substantive question topics are completely ungrounded!
|
|
764
|
+
return SupportLevel.UNSUPPORTED, 0.0, "Substantive question topics ungrounded in component memory"
|
|
765
|
+
|
|
766
|
+
# SELECT-B: Grounded Component + Topic Match
|
|
767
|
+
if vector_score >= 0.55:
|
|
768
|
+
return SupportLevel.STRONG, 0.90 + min(0.08, topic_hits * 0.02), f"Grounded component and topic match ({topic_hits} hits)"
|
|
769
|
+
elif vector_score >= 0.45:
|
|
770
|
+
return SupportLevel.MEDIUM, 0.70 + min(0.08, topic_hits * 0.02), f"Plausible component and topic match ({topic_hits} hits)"
|
|
771
|
+
elif query_ev.explicit_domains and (topic_hits >= 1 or not q_topics):
|
|
772
|
+
return SupportLevel.MEDIUM, 0.60 + min(0.08, topic_hits * 0.02), f"Domain-scoped topic match ({topic_hits} hits)"
|
|
773
|
+
else:
|
|
774
|
+
return SupportLevel.WEAK, 0.40, "Low vector similarity"
|
|
775
|
+
|
|
776
|
+
# 4. Pure semantic query without explicit component scope
|
|
777
|
+
if query_ev.requested_kind == "incident" and mem_ev.memory_kind != "incident":
|
|
778
|
+
return SupportLevel.UNSUPPORTED, 0.0, "Query requested incident but memory is not an incident"
|
|
779
|
+
|
|
780
|
+
# Cross-lingual / Cyrillic
|
|
781
|
+
if query_ev.is_cyrillic:
|
|
782
|
+
cyr_q = {w.lower() for w in query_ev.substantive_topics if re.search(r"[\u0400-\u04FF]", w)}
|
|
783
|
+
cyr_t = {w.lower() for w in mem_tokens if re.search(r"[\u0400-\u04FF]", w)}
|
|
784
|
+
stem_q = {w[:4] for w in cyr_q if len(w) >= 4}
|
|
785
|
+
stem_t = {w[:4] for w in cyr_t if len(w) >= 4}
|
|
786
|
+
stem_hits = len(stem_q & stem_t)
|
|
787
|
+
cyr_overlap = len(cyr_q & cyr_t)
|
|
788
|
+
if vector_score >= 0.60 and (cyr_overlap > 0 or stem_hits > 0):
|
|
789
|
+
return SupportLevel.MEDIUM, 0.75, "Cyrillic semantic match with topic grounding"
|
|
790
|
+
else:
|
|
791
|
+
return SupportLevel.UNSUPPORTED, 0.0, "Cyrillic match lacks lexical grounding"
|
|
792
|
+
|
|
793
|
+
topic_hits = sum(1 for qt in query_ev.substantive_topics if any(qt in mt or mt in qt for mt in mem_tokens))
|
|
794
|
+
if query_ev.substantive_topics and topic_hits == 0:
|
|
795
|
+
return SupportLevel.UNSUPPORTED, 0.0, "Substantive question topics ungrounded in memory"
|
|
796
|
+
|
|
797
|
+
if (
|
|
798
|
+
query_ev.requested_kind in {"status", "relation"}
|
|
799
|
+
and mem_ev.memory_kind == query_ev.requested_kind
|
|
800
|
+
and topic_hits > 0
|
|
801
|
+
and vector_score >= 0.40
|
|
802
|
+
):
|
|
803
|
+
return SupportLevel.MEDIUM, 0.68, "Typed memory kind and topic match"
|
|
804
|
+
|
|
805
|
+
if vector_score >= 0.65:
|
|
806
|
+
return SupportLevel.MEDIUM, 0.80, "High cosine match"
|
|
807
|
+
elif vector_score >= 0.60:
|
|
808
|
+
return SupportLevel.MEDIUM, 0.70, "Medium cosine match"
|
|
809
|
+
elif query_ev.explicit_domains and (topic_hits >= 1 or not query_ev.substantive_topics):
|
|
810
|
+
return SupportLevel.MEDIUM, 0.65, f"Domain-scoped semantic match ({topic_hits} hits)"
|
|
811
|
+
else:
|
|
812
|
+
return SupportLevel.WEAK, 0.40, "Low similarity"
|