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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Dandelion baseline B0 native adapter for DandelionBench Track B."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
import dandelion.store_kv
|
|
5
|
+
from dandelion.store_kv import KVStore
|
|
6
|
+
from benchmarks.adapters.native.store_vector_b0 import VectorStore as B0VectorStore
|
|
7
|
+
from dandelion.hydrator import hydrate_template, pin_snapshots
|
|
8
|
+
from benchmarks.adapters.native.base import NativeMemoryAdapter
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DandelionNativeB0Adapter(NativeMemoryAdapter):
|
|
12
|
+
"""Frozen Baseline B0 Dandelion memory engine before SEMANTIC-SELECT-01."""
|
|
13
|
+
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
self.kv: Optional[KVStore] = None
|
|
16
|
+
self.vec: Optional[B0VectorStore] = None
|
|
17
|
+
self.query_count = 0
|
|
18
|
+
self.total_tokens = 0
|
|
19
|
+
self.reset()
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def name(self) -> str:
|
|
23
|
+
return "dandelion_native_b0"
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def package_version(self) -> str:
|
|
27
|
+
return "dandelion-0.2.0-b0 (frozen baseline)"
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def configuration_metadata(self) -> dict[str, Any]:
|
|
31
|
+
return {
|
|
32
|
+
"system": "dandelion_b0",
|
|
33
|
+
"architecture": "hub_and_spoke_b0_baseline",
|
|
34
|
+
"embedding_model": "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
|
35
|
+
"llm_used": "none (deterministic symbolic hydration)",
|
|
36
|
+
"vector_store": "qdrant_in_memory_b0",
|
|
37
|
+
"hydration_policy": "read_time_late_binding",
|
|
38
|
+
"security_policy": "deny_by_default_secret_masking",
|
|
39
|
+
"reverse_index": "enabled_exact_match",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def telemetry(self) -> dict[str, Any]:
|
|
44
|
+
avg_tok = (self.total_tokens / max(1, self.query_count)) if self.query_count else 0
|
|
45
|
+
return {
|
|
46
|
+
"query_count": self.query_count,
|
|
47
|
+
"llm_calls_total": 0,
|
|
48
|
+
"llm_calls_per_query": 0.0,
|
|
49
|
+
"api_calls_total": 0,
|
|
50
|
+
"api_calls_per_query": 0.0,
|
|
51
|
+
"cost_total_usd": 0.0,
|
|
52
|
+
"cost_per_1k_queries_usd": 0.0,
|
|
53
|
+
"mean_memory_context_tokens": round(avg_tok, 1),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
def reset(self) -> None:
|
|
57
|
+
self.kv = KVStore(path=None)
|
|
58
|
+
dandelion.store_kv._store = self.kv
|
|
59
|
+
self.vec = B0VectorStore(in_memory=True)
|
|
60
|
+
self.query_count = 0
|
|
61
|
+
self.total_tokens = 0
|
|
62
|
+
|
|
63
|
+
def ingest_fact(
|
|
64
|
+
self,
|
|
65
|
+
key: str,
|
|
66
|
+
value: str,
|
|
67
|
+
timestamp: float,
|
|
68
|
+
domain: str = "general",
|
|
69
|
+
source: str = "config_read",
|
|
70
|
+
) -> None:
|
|
71
|
+
self.kv.set_fact(key=key, value=value, source=source, timestamp=timestamp)
|
|
72
|
+
|
|
73
|
+
def ingest_memory(
|
|
74
|
+
self,
|
|
75
|
+
event_id: str,
|
|
76
|
+
template: str,
|
|
77
|
+
domain: str,
|
|
78
|
+
timestamp: float,
|
|
79
|
+
supersedes: Optional[str] = None,
|
|
80
|
+
source: str = "tool_observed",
|
|
81
|
+
) -> str:
|
|
82
|
+
pinned = pin_snapshots(template, self.kv.get_current_revision, domain)
|
|
83
|
+
return self.vec.save_chunk(
|
|
84
|
+
domain=domain,
|
|
85
|
+
template=pinned,
|
|
86
|
+
supersedes=supersedes,
|
|
87
|
+
source=source,
|
|
88
|
+
created_at=timestamp,
|
|
89
|
+
event_id=event_id,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def recall(
|
|
93
|
+
self,
|
|
94
|
+
query: str,
|
|
95
|
+
domain: Optional[str] = None,
|
|
96
|
+
limit: int = 3,
|
|
97
|
+
) -> list[dict[str, Any]]:
|
|
98
|
+
domains = [domain] if domain else None
|
|
99
|
+
raw_results = self.vec.search_chunks(query=query, domains=domains, limit=limit)
|
|
100
|
+
hydrated: list[dict[str, Any]] = []
|
|
101
|
+
|
|
102
|
+
for r in raw_results:
|
|
103
|
+
text = hydrate_template(
|
|
104
|
+
text=r["template"],
|
|
105
|
+
kv_resolver=self.kv.resolve_ref,
|
|
106
|
+
chunk_domain=r.get("domain", "general"),
|
|
107
|
+
allow_secrets=False,
|
|
108
|
+
)
|
|
109
|
+
hydrated.append({
|
|
110
|
+
"id": r["id"],
|
|
111
|
+
"event_id": r.get("event_id", r["id"]),
|
|
112
|
+
"text": text,
|
|
113
|
+
"domain": r.get("domain", "general"),
|
|
114
|
+
"score": r.get("score", 0.0),
|
|
115
|
+
"vector_score": r.get("vector_score", 0.0),
|
|
116
|
+
"has_fact": r.get("has_fact", False),
|
|
117
|
+
"is_historical": "{{ref:" in r["template"] and "@rev:" in r["template"],
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
self.query_count += 1
|
|
121
|
+
tok_sum = sum(len(h["text"].split()) for h in hydrated)
|
|
122
|
+
self.total_tokens += tok_sum
|
|
123
|
+
|
|
124
|
+
return hydrated
|
|
125
|
+
|
|
126
|
+
def answer(
|
|
127
|
+
self,
|
|
128
|
+
query: str,
|
|
129
|
+
domain: Optional[str] = None,
|
|
130
|
+
) -> dict[str, Any]:
|
|
131
|
+
"""End-to-end answering surface using secure context envelope."""
|
|
132
|
+
candidates = self.recall(query=query, domain=domain, limit=3)
|
|
133
|
+
if not candidates:
|
|
134
|
+
return {
|
|
135
|
+
"answer": "I have no memory regarding this topic.",
|
|
136
|
+
"retrieved_context": "",
|
|
137
|
+
"context_tokens": 0,
|
|
138
|
+
"llm_calls": 0,
|
|
139
|
+
"api_calls": 0,
|
|
140
|
+
"cost_usd": 0.0,
|
|
141
|
+
"source_events": [],
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
context_str = "\n".join(f"[{c['event_id']}] {c['text']}" for c in candidates)
|
|
145
|
+
context_tokens = len(context_str.split())
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
"answer": context_str,
|
|
149
|
+
"retrieved_context": context_str,
|
|
150
|
+
"context_tokens": context_tokens,
|
|
151
|
+
"llm_calls": 0,
|
|
152
|
+
"api_calls": 0,
|
|
153
|
+
"cost_usd": 0.0,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
def get_fact(
|
|
157
|
+
self,
|
|
158
|
+
key: str,
|
|
159
|
+
domain: Optional[str] = None,
|
|
160
|
+
at: Optional[float] = None,
|
|
161
|
+
) -> Optional[str]:
|
|
162
|
+
if at is not None:
|
|
163
|
+
return self.kv.get_fact(key, at_timestamp=at)
|
|
164
|
+
return self.kv.resolve_ref(key, domain=domain)
|
|
165
|
+
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""Dandelion baseline B1 native adapter for DandelionBench Track B (H9 Evaluation).
|
|
2
|
+
|
|
3
|
+
Freezes Candidate C1 (winner of H8 with Semantic Evidence Gate SELECT-A/SELECT-B),
|
|
4
|
+
prior to the ARCH-EVENT-01 Structured Event Evidence algebra.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any, Optional
|
|
8
|
+
import dandelion.store_kv
|
|
9
|
+
from dandelion.store_kv import KVStore
|
|
10
|
+
from dandelion.store_vector import VectorStore
|
|
11
|
+
from dandelion.hydrator import hydrate_template, pin_snapshots
|
|
12
|
+
from benchmarks.adapters.native.base import NativeMemoryAdapter
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DandelionNativeB1Adapter(NativeMemoryAdapter):
|
|
16
|
+
"""Frozen Baseline B1 Dandelion memory engine (Candidate C1 from H8)."""
|
|
17
|
+
|
|
18
|
+
def __init__(self) -> None:
|
|
19
|
+
self.kv: Optional[KVStore] = None
|
|
20
|
+
self.vec: Optional[VectorStore] = None
|
|
21
|
+
self.query_count = 0
|
|
22
|
+
self.total_tokens = 0
|
|
23
|
+
self.reset()
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def name(self) -> str:
|
|
27
|
+
return "dandelion_native_b1"
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def package_version(self) -> str:
|
|
31
|
+
return "dandelion-0.2.0-b1 (frozen baseline: C1)"
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def configuration_metadata(self) -> dict[str, Any]:
|
|
35
|
+
return {
|
|
36
|
+
"system": "dandelion_b1",
|
|
37
|
+
"architecture": "hub_and_spoke_b1_candidate_c1",
|
|
38
|
+
"embedding_model": "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
|
39
|
+
"llm_used": "none (deterministic symbolic hydration)",
|
|
40
|
+
"vector_store": "qdrant_in_memory_b1",
|
|
41
|
+
"hydration_policy": "read_time_late_binding",
|
|
42
|
+
"security_policy": "deny_by_default_secret_masking",
|
|
43
|
+
"reverse_index": "enabled_exact_match",
|
|
44
|
+
"evidence_gate": "semantic_select_c1",
|
|
45
|
+
"event_gate": "disabled",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def telemetry(self) -> dict[str, Any]:
|
|
50
|
+
avg_tok = (self.total_tokens / max(1, self.query_count)) if self.query_count else 0
|
|
51
|
+
return {
|
|
52
|
+
"query_count": self.query_count,
|
|
53
|
+
"llm_calls_total": 0,
|
|
54
|
+
"llm_calls_per_query": 0.0,
|
|
55
|
+
"api_calls_total": 0,
|
|
56
|
+
"api_calls_per_query": 0.0,
|
|
57
|
+
"cost_total_usd": 0.0,
|
|
58
|
+
"cost_per_1k_queries_usd": 0.0,
|
|
59
|
+
"mean_memory_context_tokens": round(avg_tok, 1),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
def reset(self) -> None:
|
|
63
|
+
self.kv = KVStore(path=None)
|
|
64
|
+
dandelion.store_kv._store = self.kv
|
|
65
|
+
self.vec = VectorStore(in_memory=True, enable_event_gate=False)
|
|
66
|
+
self.query_count = 0
|
|
67
|
+
self.total_tokens = 0
|
|
68
|
+
|
|
69
|
+
def ingest_fact(
|
|
70
|
+
self,
|
|
71
|
+
key: str,
|
|
72
|
+
value: str,
|
|
73
|
+
timestamp: float,
|
|
74
|
+
domain: str = "general",
|
|
75
|
+
source: str = "user_asserted",
|
|
76
|
+
) -> None:
|
|
77
|
+
self.kv.set_fact(key=key, value=value, source=source, timestamp=timestamp)
|
|
78
|
+
|
|
79
|
+
def ingest_memory(
|
|
80
|
+
self,
|
|
81
|
+
event_id: str,
|
|
82
|
+
template: str,
|
|
83
|
+
domain: str,
|
|
84
|
+
timestamp: float,
|
|
85
|
+
supersedes: Optional[str] = None,
|
|
86
|
+
source: str = "tool_observed",
|
|
87
|
+
) -> str:
|
|
88
|
+
pinned = pin_snapshots(template, self.kv.get_current_revision, domain)
|
|
89
|
+
return self.vec.save_chunk(
|
|
90
|
+
domain=domain,
|
|
91
|
+
template=pinned,
|
|
92
|
+
supersedes=supersedes,
|
|
93
|
+
source=source,
|
|
94
|
+
created_at=timestamp,
|
|
95
|
+
event_id=event_id,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def recall(
|
|
99
|
+
self,
|
|
100
|
+
query: str,
|
|
101
|
+
domain: Optional[str] = None,
|
|
102
|
+
limit: int = 3,
|
|
103
|
+
) -> list[dict[str, Any]]:
|
|
104
|
+
domains = [domain] if domain else None
|
|
105
|
+
raw_results = self.vec.search_chunks(query=query, domains=domains, limit=limit)
|
|
106
|
+
hydrated: list[dict[str, Any]] = []
|
|
107
|
+
|
|
108
|
+
for r in raw_results:
|
|
109
|
+
text = hydrate_template(
|
|
110
|
+
text=r["template"],
|
|
111
|
+
kv_resolver=self.kv.resolve_ref,
|
|
112
|
+
chunk_domain=r.get("domain", "general"),
|
|
113
|
+
allow_secrets=False,
|
|
114
|
+
)
|
|
115
|
+
hydrated.append({
|
|
116
|
+
"id": r["id"],
|
|
117
|
+
"event_id": r.get("event_id", r["id"]),
|
|
118
|
+
"text": text,
|
|
119
|
+
"domain": r.get("domain", "general"),
|
|
120
|
+
"score": r.get("score", 0.0),
|
|
121
|
+
"vector_score": r.get("vector_score", 0.0),
|
|
122
|
+
"has_fact": r.get("has_fact", False),
|
|
123
|
+
"is_historical": "{{ref:" in r["template"] and "@rev:" in r["template"],
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
self.query_count += 1
|
|
127
|
+
tok_sum = sum(len(h["text"].split()) for h in hydrated)
|
|
128
|
+
self.total_tokens += tok_sum
|
|
129
|
+
|
|
130
|
+
return hydrated
|
|
131
|
+
|
|
132
|
+
def answer(
|
|
133
|
+
self,
|
|
134
|
+
query: str,
|
|
135
|
+
domain: Optional[str] = None,
|
|
136
|
+
) -> dict[str, Any]:
|
|
137
|
+
"""End-to-end answering surface using secure context envelope."""
|
|
138
|
+
candidates = self.recall(query=query, domain=domain, limit=3)
|
|
139
|
+
if not candidates:
|
|
140
|
+
return {
|
|
141
|
+
"answer": "I have no memory regarding this topic.",
|
|
142
|
+
"retrieved_context": "",
|
|
143
|
+
"context_tokens": 0,
|
|
144
|
+
"llm_calls": 0,
|
|
145
|
+
"api_calls": 0,
|
|
146
|
+
"cost_usd": 0.0,
|
|
147
|
+
"source_events": [],
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
context_str = "\n".join(f"[{c['event_id']}] {c['text']}" for c in candidates)
|
|
151
|
+
context_tokens = len(context_str.split())
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
"answer": context_str,
|
|
155
|
+
"retrieved_context": context_str,
|
|
156
|
+
"context_tokens": context_tokens,
|
|
157
|
+
"llm_calls": 0,
|
|
158
|
+
"api_calls": 0,
|
|
159
|
+
"cost_usd": 0.0,
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
def get_fact(
|
|
163
|
+
self,
|
|
164
|
+
key: str,
|
|
165
|
+
domain: Optional[str] = None,
|
|
166
|
+
at: Optional[float] = None,
|
|
167
|
+
) -> Optional[str]:
|
|
168
|
+
if at is not None:
|
|
169
|
+
return self.kv.get_fact(key, at_timestamp=at)
|
|
170
|
+
return self.kv.resolve_ref(key, domain=domain)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Dandelion baseline B2 native adapter for DandelionBench Track B (H10 Evaluation).
|
|
2
|
+
|
|
3
|
+
Freezes Candidate C2 (ARCH-EVENT-01 Structured Event Evidence engine),
|
|
4
|
+
prior to the ARCH-SCOPE-01 Open-World Scope Grounding architecture.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any, Optional
|
|
8
|
+
import dandelion.store_kv
|
|
9
|
+
from dandelion.store_kv import KVStore
|
|
10
|
+
from benchmarks.adapters.native.store_vector_b2 import VectorStore as VectorStoreB2
|
|
11
|
+
from dandelion.hydrator import hydrate_template, pin_snapshots
|
|
12
|
+
from benchmarks.adapters.native.base import NativeMemoryAdapter
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DandelionNativeB2Adapter(NativeMemoryAdapter):
|
|
16
|
+
"""Frozen Baseline B2 Dandelion memory engine (Candidate C2 from H9)."""
|
|
17
|
+
|
|
18
|
+
def __init__(self) -> None:
|
|
19
|
+
self.kv: Optional[KVStore] = None
|
|
20
|
+
self.vec: Optional[VectorStoreB2] = None
|
|
21
|
+
self.query_count = 0
|
|
22
|
+
self.total_tokens = 0
|
|
23
|
+
self.reset()
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def name(self) -> str:
|
|
27
|
+
return "dandelion_native_b2"
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def package_version(self) -> str:
|
|
31
|
+
return "dandelion-0.2.0-b2 (frozen baseline: C2)"
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def configuration_metadata(self) -> dict[str, Any]:
|
|
35
|
+
return {
|
|
36
|
+
"system": "dandelion_b2",
|
|
37
|
+
"architecture": "hub_and_spoke_b2_candidate_c2",
|
|
38
|
+
"embedding_model": "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
|
39
|
+
"llm_used": "none (deterministic symbolic hydration)",
|
|
40
|
+
"vector_store": "qdrant_in_memory_b2",
|
|
41
|
+
"hydration_policy": "read_time_late_binding",
|
|
42
|
+
"security_policy": "deny_by_default_secret_masking",
|
|
43
|
+
"reverse_index": "enabled_exact_match",
|
|
44
|
+
"event_evidence_gate": "enabled_arch_event_01",
|
|
45
|
+
"scope_grounding": "static_ontology_baseline",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def telemetry(self) -> dict[str, Any]:
|
|
50
|
+
avg_tok = (self.total_tokens / max(1, self.query_count)) if self.query_count else 0
|
|
51
|
+
return {
|
|
52
|
+
"query_count": self.query_count,
|
|
53
|
+
"llm_calls_total": 0,
|
|
54
|
+
"llm_calls_per_query": 0.0,
|
|
55
|
+
"api_calls_total": 0,
|
|
56
|
+
"api_calls_per_query": 0.0,
|
|
57
|
+
"cost_total_usd": 0.0,
|
|
58
|
+
"cost_per_1k_queries_usd": 0.0,
|
|
59
|
+
"mean_memory_context_tokens": round(avg_tok, 1),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
def reset(self) -> None:
|
|
63
|
+
self.kv = KVStore(path=None)
|
|
64
|
+
dandelion.store_kv._store = self.kv
|
|
65
|
+
self.vec = VectorStoreB2(in_memory=True, enable_event_gate=True)
|
|
66
|
+
self.query_count = 0
|
|
67
|
+
self.total_tokens = 0
|
|
68
|
+
|
|
69
|
+
def ingest_fact(
|
|
70
|
+
self,
|
|
71
|
+
key: str,
|
|
72
|
+
value: str,
|
|
73
|
+
timestamp: float,
|
|
74
|
+
domain: str = "general",
|
|
75
|
+
source: str = "config_read",
|
|
76
|
+
) -> None:
|
|
77
|
+
self.kv.set_fact(key=key, value=value, source=source, timestamp=timestamp)
|
|
78
|
+
|
|
79
|
+
def ingest_memory(
|
|
80
|
+
self,
|
|
81
|
+
event_id: str,
|
|
82
|
+
template: str,
|
|
83
|
+
domain: str,
|
|
84
|
+
timestamp: float,
|
|
85
|
+
supersedes: Optional[str] = None,
|
|
86
|
+
source: str = "tool_observed",
|
|
87
|
+
) -> str:
|
|
88
|
+
pinned = pin_snapshots(template, self.kv.get_current_revision, domain)
|
|
89
|
+
return self.vec.save_chunk(
|
|
90
|
+
domain=domain,
|
|
91
|
+
template=pinned,
|
|
92
|
+
supersedes=supersedes,
|
|
93
|
+
source=source,
|
|
94
|
+
created_at=timestamp,
|
|
95
|
+
event_id=event_id,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def recall(
|
|
99
|
+
self,
|
|
100
|
+
query: str,
|
|
101
|
+
domain: Optional[str] = None,
|
|
102
|
+
limit: int = 3,
|
|
103
|
+
) -> list[dict[str, Any]]:
|
|
104
|
+
domains = [domain] if domain else None
|
|
105
|
+
raw_results = self.vec.search_chunks(query=query, domains=domains, limit=limit)
|
|
106
|
+
hydrated: list[dict[str, Any]] = []
|
|
107
|
+
|
|
108
|
+
for r in raw_results:
|
|
109
|
+
text = hydrate_template(
|
|
110
|
+
text=r["template"],
|
|
111
|
+
kv_resolver=self.kv.resolve_ref,
|
|
112
|
+
chunk_domain=r.get("domain", "general"),
|
|
113
|
+
allow_secrets=False,
|
|
114
|
+
)
|
|
115
|
+
hydrated.append({
|
|
116
|
+
"id": r["id"],
|
|
117
|
+
"event_id": r.get("event_id", r["id"]),
|
|
118
|
+
"text": text,
|
|
119
|
+
"domain": r.get("domain", "general"),
|
|
120
|
+
"score": r.get("score", 0.0),
|
|
121
|
+
"vector_score": r.get("vector_score", 0.0),
|
|
122
|
+
"has_fact": r.get("has_fact", False),
|
|
123
|
+
"is_historical": "{{ref:" in r["template"] and "@rev:" in r["template"],
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
self.query_count += 1
|
|
127
|
+
tok_sum = sum(len(h["text"].split()) for h in hydrated)
|
|
128
|
+
self.total_tokens += tok_sum
|
|
129
|
+
|
|
130
|
+
return hydrated
|
|
131
|
+
|
|
132
|
+
def answer(
|
|
133
|
+
self,
|
|
134
|
+
query: str,
|
|
135
|
+
domain: Optional[str] = None,
|
|
136
|
+
) -> dict[str, Any]:
|
|
137
|
+
"""End-to-end answering surface using secure context envelope."""
|
|
138
|
+
candidates = self.recall(query=query, domain=domain, limit=3)
|
|
139
|
+
if not candidates:
|
|
140
|
+
return {
|
|
141
|
+
"answer": "I have no memory regarding this topic.",
|
|
142
|
+
"retrieved_context": "",
|
|
143
|
+
"context_tokens": 0,
|
|
144
|
+
"llm_calls": 0,
|
|
145
|
+
"api_calls": 0,
|
|
146
|
+
"cost_usd": 0.0,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
context_str = "\n".join(f"[{c['event_id']}] {c['text']}" for c in candidates)
|
|
150
|
+
context_tokens = len(context_str.split())
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
"answer": context_str,
|
|
154
|
+
"retrieved_context": context_str,
|
|
155
|
+
"context_tokens": context_tokens,
|
|
156
|
+
"llm_calls": 0,
|
|
157
|
+
"api_calls": 0,
|
|
158
|
+
"cost_usd": 0.0,
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
def get_fact(
|
|
162
|
+
self,
|
|
163
|
+
key: str,
|
|
164
|
+
domain: Optional[str] = None,
|
|
165
|
+
at: Optional[float] = None,
|
|
166
|
+
) -> Optional[str]:
|
|
167
|
+
if at is not None:
|
|
168
|
+
return self.kv.get_fact(key, at_timestamp=at)
|
|
169
|
+
return self.kv.resolve_ref(key, domain=domain)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Dandelion baseline B3 native adapter for DandelionBench Track B.
|
|
2
|
+
|
|
3
|
+
Freezes Candidate C3 (ARCH-SCOPE-01: Open-World Scope Grounding and Event Evidence Engine),
|
|
4
|
+
validated in Hypothesis H10 on Scope-Select-Holdout-v1.
|
|
5
|
+
Enforces the Epistemic Invariant: 'Unresolved != Local'.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Any, Optional
|
|
9
|
+
import dandelion.store_kv
|
|
10
|
+
from dandelion.store_kv import KVStore
|
|
11
|
+
from dandelion.store_vector import VectorStore
|
|
12
|
+
from dandelion.hydrator import hydrate_template, pin_snapshots
|
|
13
|
+
from benchmarks.adapters.native.base import NativeMemoryAdapter
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DandelionNativeB3Adapter(NativeMemoryAdapter):
|
|
17
|
+
"""Frozen Baseline B3 Dandelion memory engine (Candidate C3 from H10)."""
|
|
18
|
+
|
|
19
|
+
def __init__(self) -> None:
|
|
20
|
+
self.kv: Optional[KVStore] = None
|
|
21
|
+
self.vec: Optional[VectorStore] = None
|
|
22
|
+
self.query_count = 0
|
|
23
|
+
self.total_tokens = 0
|
|
24
|
+
self.reset()
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def name(self) -> str:
|
|
28
|
+
return "dandelion_native_b3"
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def package_version(self) -> str:
|
|
32
|
+
return "dandelion-0.2.0-b3 (frozen baseline: C3)"
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def configuration_metadata(self) -> dict[str, Any]:
|
|
36
|
+
return {
|
|
37
|
+
"system": "dandelion_b3",
|
|
38
|
+
"architecture": "hub_and_spoke_b3_candidate_c3",
|
|
39
|
+
"embedding_model": "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
|
40
|
+
"llm_used": "none (deterministic symbolic hydration)",
|
|
41
|
+
"vector_store": "qdrant_in_memory_b3",
|
|
42
|
+
"hydration_policy": "read_time_late_binding",
|
|
43
|
+
"security_policy": "deny_by_default_secret_masking",
|
|
44
|
+
"reverse_index": "enabled_exact_match",
|
|
45
|
+
"event_evidence_gate": "enabled_arch_event_01",
|
|
46
|
+
"scope_grounding": "dynamic_domain_registry_arch_scope_01",
|
|
47
|
+
"epistemic_invariant": "unresolved_not_equal_local",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def telemetry(self) -> dict[str, Any]:
|
|
52
|
+
avg_tok = (self.total_tokens / max(1, self.query_count)) if self.query_count else 0
|
|
53
|
+
return {
|
|
54
|
+
"query_count": self.query_count,
|
|
55
|
+
"llm_calls_total": 0,
|
|
56
|
+
"llm_calls_per_query": 0.0,
|
|
57
|
+
"api_calls_total": 0,
|
|
58
|
+
"api_calls_per_query": 0.0,
|
|
59
|
+
"cost_total_usd": 0.0,
|
|
60
|
+
"cost_per_1k_queries_usd": 0.0,
|
|
61
|
+
"mean_memory_context_tokens": round(avg_tok, 1),
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
def reset(self) -> None:
|
|
65
|
+
self.kv = KVStore(path=None)
|
|
66
|
+
dandelion.store_kv._store = self.kv
|
|
67
|
+
self.vec = VectorStore(in_memory=True)
|
|
68
|
+
self.query_count = 0
|
|
69
|
+
self.total_tokens = 0
|
|
70
|
+
|
|
71
|
+
def ingest_fact(
|
|
72
|
+
self,
|
|
73
|
+
key: str,
|
|
74
|
+
value: str,
|
|
75
|
+
timestamp: float,
|
|
76
|
+
domain: str = "general",
|
|
77
|
+
source: str = "config_read",
|
|
78
|
+
) -> None:
|
|
79
|
+
self.kv.set_fact(key=key, value=value, source=source, timestamp=timestamp)
|
|
80
|
+
|
|
81
|
+
def ingest_memory(
|
|
82
|
+
self,
|
|
83
|
+
event_id: str,
|
|
84
|
+
template: str,
|
|
85
|
+
domain: str,
|
|
86
|
+
timestamp: float,
|
|
87
|
+
supersedes: Optional[str] = None,
|
|
88
|
+
source: str = "tool_observed",
|
|
89
|
+
) -> str:
|
|
90
|
+
pinned = pin_snapshots(template, self.kv.get_current_revision, domain)
|
|
91
|
+
return self.vec.save_chunk(
|
|
92
|
+
domain=domain,
|
|
93
|
+
template=pinned,
|
|
94
|
+
supersedes=supersedes,
|
|
95
|
+
source=source,
|
|
96
|
+
created_at=timestamp,
|
|
97
|
+
event_id=event_id,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def recall(
|
|
101
|
+
self,
|
|
102
|
+
query: str,
|
|
103
|
+
domain: Optional[str] = None,
|
|
104
|
+
limit: int = 3,
|
|
105
|
+
) -> list[dict[str, Any]]:
|
|
106
|
+
domains = [domain] if domain else None
|
|
107
|
+
raw_results = self.vec.search_chunks(query=query, domains=domains, limit=limit)
|
|
108
|
+
hydrated: list[dict[str, Any]] = []
|
|
109
|
+
|
|
110
|
+
for r in raw_results:
|
|
111
|
+
text = hydrate_template(
|
|
112
|
+
text=r["template"],
|
|
113
|
+
kv_resolver=self.kv.resolve_ref,
|
|
114
|
+
chunk_domain=r.get("domain", "general"),
|
|
115
|
+
allow_secrets=False,
|
|
116
|
+
)
|
|
117
|
+
hydrated.append({
|
|
118
|
+
"id": r["id"],
|
|
119
|
+
"event_id": r.get("event_id", r["id"]),
|
|
120
|
+
"text": text,
|
|
121
|
+
"domain": r.get("domain", "general"),
|
|
122
|
+
"score": r.get("score", 0.0),
|
|
123
|
+
"vector_score": r.get("vector_score", 0.0),
|
|
124
|
+
"has_fact": r.get("has_fact", False),
|
|
125
|
+
"is_historical": "{{ref:" in r["template"] and "@rev:" in r["template"],
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
self.query_count += 1
|
|
129
|
+
tok_sum = sum(len(h["text"].split()) for h in hydrated)
|
|
130
|
+
self.total_tokens += tok_sum
|
|
131
|
+
|
|
132
|
+
return hydrated
|
|
133
|
+
|
|
134
|
+
def answer(
|
|
135
|
+
self,
|
|
136
|
+
query: str,
|
|
137
|
+
domain: Optional[str] = None,
|
|
138
|
+
) -> dict[str, Any]:
|
|
139
|
+
"""End-to-end answering surface using secure context envelope."""
|
|
140
|
+
candidates = self.recall(query=query, domain=domain, limit=3)
|
|
141
|
+
if not candidates:
|
|
142
|
+
return {
|
|
143
|
+
"answer": "I have no memory regarding this topic.",
|
|
144
|
+
"retrieved_context": "",
|
|
145
|
+
"context_tokens": 0,
|
|
146
|
+
"llm_calls": 0,
|
|
147
|
+
"api_calls": 0,
|
|
148
|
+
"cost_usd": 0.0,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
context_str = "\n".join(f"[{c['event_id']}] {c['text']}" for c in candidates)
|
|
152
|
+
context_tokens = len(context_str.split())
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
"answer": context_str,
|
|
156
|
+
"retrieved_context": context_str,
|
|
157
|
+
"context_tokens": context_tokens,
|
|
158
|
+
"llm_calls": 0,
|
|
159
|
+
"api_calls": 0,
|
|
160
|
+
"cost_usd": 0.0,
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
def get_fact(
|
|
164
|
+
self,
|
|
165
|
+
key: str,
|
|
166
|
+
domain: Optional[str] = None,
|
|
167
|
+
at: Optional[float] = None,
|
|
168
|
+
) -> Optional[str]:
|
|
169
|
+
if at is not None:
|
|
170
|
+
return self.kv.get_fact(key, at_timestamp=at)
|
|
171
|
+
return self.kv.resolve_ref(key, domain=domain)
|