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/embedder.py
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"""Singleton embedding engine for Dandelion.
|
|
2
|
+
|
|
3
|
+
Wraps FastEmbed's TextEmbedding with:
|
|
4
|
+
- Thread-safe singleton initialization (double-checked locking)
|
|
5
|
+
- Asymmetric search: passage_embed for storage, query_embed for retrieval
|
|
6
|
+
- Persistent model cache directory (avoids Windows %TEMP% purging)
|
|
7
|
+
- Proper generator unwrapping (embed() returns a generator, not a list)
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
import hashlib
|
|
12
|
+
import importlib.metadata
|
|
13
|
+
import json
|
|
14
|
+
import logging
|
|
15
|
+
import inspect
|
|
16
|
+
import threading
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, ClassVar, Mapping, Optional
|
|
19
|
+
|
|
20
|
+
from dandelion.config import EMBEDDING_FINGERPRINT, MODEL_NAME, MODEL_CACHE_DIR
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _pooling_for_class(class_name: str) -> tuple[str, str]:
|
|
26
|
+
"""Return the pooling and normalization contract for a FastEmbed wrapper."""
|
|
27
|
+
name = class_name.lower()
|
|
28
|
+
if "poolednormalized" in name:
|
|
29
|
+
return "mean_attention_mask", "l2"
|
|
30
|
+
if "pooledembedding" in name:
|
|
31
|
+
return "mean_attention_mask", "none"
|
|
32
|
+
if "onnxtextembedding" in name:
|
|
33
|
+
return "model_output_cls", "l2"
|
|
34
|
+
return "unknown", "unknown"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _fastembed_version() -> str:
|
|
38
|
+
try:
|
|
39
|
+
return importlib.metadata.version("fastembed")
|
|
40
|
+
except importlib.metadata.PackageNotFoundError:
|
|
41
|
+
return "not_installed"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def describe_embedding_runtime(model_name: str = MODEL_NAME) -> dict[str, Any]:
|
|
45
|
+
"""Describe the configured FastEmbed model without loading or downloading it.
|
|
46
|
+
|
|
47
|
+
The selected FastEmbed wrapper is part of the contract: for the default model
|
|
48
|
+
on FastEmbed 0.8.x it records mean pooling, while older releases used CLS.
|
|
49
|
+
"""
|
|
50
|
+
result: dict[str, Any] = {
|
|
51
|
+
"fastembed_version": _fastembed_version(),
|
|
52
|
+
"model_name": model_name,
|
|
53
|
+
"implementation": "unknown",
|
|
54
|
+
"pooling": "unknown",
|
|
55
|
+
"normalization": "unknown",
|
|
56
|
+
"dimension": None,
|
|
57
|
+
"model_source": None,
|
|
58
|
+
"model_file": None,
|
|
59
|
+
}
|
|
60
|
+
try:
|
|
61
|
+
from fastembed import TextEmbedding
|
|
62
|
+
except ImportError:
|
|
63
|
+
return result
|
|
64
|
+
|
|
65
|
+
for embedding_type in TextEmbedding.EMBEDDINGS_REGISTRY:
|
|
66
|
+
descriptions = embedding_type._list_supported_models()
|
|
67
|
+
description = next(
|
|
68
|
+
(item for item in descriptions if item.model.lower() == model_name.lower()),
|
|
69
|
+
None,
|
|
70
|
+
)
|
|
71
|
+
if description is None:
|
|
72
|
+
continue
|
|
73
|
+
pooling, normalization = _pooling_for_class(embedding_type.__name__)
|
|
74
|
+
source = getattr(description, "sources", None)
|
|
75
|
+
result.update(
|
|
76
|
+
implementation=embedding_type.__name__,
|
|
77
|
+
pooling=pooling,
|
|
78
|
+
normalization=normalization,
|
|
79
|
+
dimension=description.dim,
|
|
80
|
+
model_source=getattr(source, "hf", None),
|
|
81
|
+
model_file=description.model_file,
|
|
82
|
+
)
|
|
83
|
+
break
|
|
84
|
+
return result
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def embedding_fingerprint_digest(fingerprint: Mapping[str, Any]) -> str:
|
|
88
|
+
"""Return a stable digest for a runtime fingerprint mapping."""
|
|
89
|
+
payload = json.dumps(dict(fingerprint), sort_keys=True, separators=(",", ":"))
|
|
90
|
+
return hashlib.sha256(payload.encode("utf-8")).hexdigest()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _runtime_signature(runtime: Any) -> str:
|
|
94
|
+
tokenizer = getattr(runtime, "tokenizer", None)
|
|
95
|
+
settings = {"runtime": id(runtime), "tokenizer": id(tokenizer),
|
|
96
|
+
"model_name": getattr(runtime, "model_name", None),
|
|
97
|
+
"truncation": getattr(tokenizer, "truncation", None),
|
|
98
|
+
"padding": getattr(tokenizer, "padding", None),
|
|
99
|
+
"special_tokens": getattr(runtime, "special_token_to_id", None)}
|
|
100
|
+
vocabulary_size = getattr(tokenizer, "get_vocab_size", None)
|
|
101
|
+
settings["vocabulary_size"] = vocabulary_size() if callable(vocabulary_size) else None
|
|
102
|
+
for name in ("normalizer", "pre_tokenizer", "post_processor", "decoder"):
|
|
103
|
+
component = getattr(tokenizer, name, None)
|
|
104
|
+
state = component.__getstate__() if component is not None else None
|
|
105
|
+
settings[name] = hashlib.sha256(state).hexdigest() if isinstance(state, bytes) else repr(state)
|
|
106
|
+
return json.dumps(settings, sort_keys=True)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class Embedder:
|
|
110
|
+
"""Thread-safe singleton embedding engine using FastEmbed."""
|
|
111
|
+
|
|
112
|
+
_instance: ClassVar[Optional["Embedder"]] = None
|
|
113
|
+
_lock: ClassVar[threading.Lock] = threading.Lock()
|
|
114
|
+
|
|
115
|
+
def __init__(self) -> None:
|
|
116
|
+
# Loading an embedder must not initialize the legacy KV/Qdrant store.
|
|
117
|
+
# CI and owner-mode callers keep the immutable model cache separate
|
|
118
|
+
# from workspace state.
|
|
119
|
+
MODEL_CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
|
120
|
+
logger.info("Loading embedding model %s...", MODEL_NAME)
|
|
121
|
+
|
|
122
|
+
from fastembed import TextEmbedding
|
|
123
|
+
|
|
124
|
+
self._model = TextEmbedding(
|
|
125
|
+
model_name=MODEL_NAME,
|
|
126
|
+
cache_dir=str(MODEL_CACHE_DIR),
|
|
127
|
+
threads=2,
|
|
128
|
+
lazy_load=False,
|
|
129
|
+
)
|
|
130
|
+
actual = self.fingerprint
|
|
131
|
+
if EMBEDDING_FINGERPRINT and EMBEDDING_FINGERPRINT != actual["digest"]:
|
|
132
|
+
raise RuntimeError(
|
|
133
|
+
"Embedding runtime fingerprint mismatch: "
|
|
134
|
+
f"expected {EMBEDDING_FINGERPRINT}, got {actual['digest']}"
|
|
135
|
+
)
|
|
136
|
+
logger.info("Embedding model loaded.")
|
|
137
|
+
|
|
138
|
+
@classmethod
|
|
139
|
+
def get(cls) -> "Embedder":
|
|
140
|
+
"""Get or create the singleton Embedder instance."""
|
|
141
|
+
if cls._instance is None:
|
|
142
|
+
with cls._lock:
|
|
143
|
+
if cls._instance is None:
|
|
144
|
+
cls._instance = cls()
|
|
145
|
+
return cls._instance
|
|
146
|
+
|
|
147
|
+
@classmethod
|
|
148
|
+
def reset(cls) -> None:
|
|
149
|
+
"""Reset the singleton (for testing)."""
|
|
150
|
+
with cls._lock:
|
|
151
|
+
cls._instance = None
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def fingerprint(self) -> dict[str, Any]:
|
|
155
|
+
"""Bind immutable loaded weights and fail closed on changed tokenizer settings."""
|
|
156
|
+
runtime = getattr(self._model, "model", self._model)
|
|
157
|
+
cached = getattr(self, "_fingerprint_cache", None)
|
|
158
|
+
if cached is not None:
|
|
159
|
+
if _runtime_signature(runtime) != self._fingerprint_signature:
|
|
160
|
+
result = {key: value for key, value in cached.items() if key != "digest"}
|
|
161
|
+
result["verified"] = False
|
|
162
|
+
result["digest"] = embedding_fingerprint_digest(result)
|
|
163
|
+
return result
|
|
164
|
+
return dict(cached)
|
|
165
|
+
result = describe_embedding_runtime(MODEL_NAME)
|
|
166
|
+
implementation = type(runtime).__name__
|
|
167
|
+
pooling, normalization = _pooling_for_class(implementation)
|
|
168
|
+
result.update(
|
|
169
|
+
implementation=implementation,
|
|
170
|
+
pooling=pooling,
|
|
171
|
+
normalization=normalization,
|
|
172
|
+
dimension=getattr(self._model, "embedding_size", result["dimension"]),
|
|
173
|
+
)
|
|
174
|
+
result["verified"] = False
|
|
175
|
+
try:
|
|
176
|
+
description = runtime.model_description
|
|
177
|
+
directory = Path(runtime._model_dir)
|
|
178
|
+
names = [description.model_file, *(getattr(description, "additional_files", None) or [])]
|
|
179
|
+
assets = {}
|
|
180
|
+
for name in names:
|
|
181
|
+
digest = hashlib.sha256()
|
|
182
|
+
with (directory / name).open("rb") as source:
|
|
183
|
+
for chunk in iter(lambda: source.read(1024 * 1024), b""):
|
|
184
|
+
digest.update(chunk)
|
|
185
|
+
assets[name] = digest.hexdigest()
|
|
186
|
+
tokenizer = runtime.tokenizer.to_str()
|
|
187
|
+
methods = {name: hashlib.sha256(inspect.getsource(getattr(type(runtime), name)).encode()).hexdigest()
|
|
188
|
+
for name in ("query_embed", "passage_embed")}
|
|
189
|
+
result.update(assets=assets, tokenizer_sha256=hashlib.sha256(tokenizer.encode()).hexdigest(),
|
|
190
|
+
embedding_methods=methods,
|
|
191
|
+
special_tokens=getattr(runtime, "special_token_to_id", {}),
|
|
192
|
+
verified=bool(assets and result["dimension"] and pooling != "unknown"
|
|
193
|
+
and normalization != "unknown"))
|
|
194
|
+
except (AttributeError, OSError, TypeError, ValueError):
|
|
195
|
+
pass
|
|
196
|
+
result["digest"] = embedding_fingerprint_digest(result)
|
|
197
|
+
self._fingerprint_cache = dict(result)
|
|
198
|
+
self._fingerprint_signature = _runtime_signature(runtime)
|
|
199
|
+
return result
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def fingerprint_digest(self) -> str:
|
|
203
|
+
"""Return only the stable digest used by release/benchmark checks."""
|
|
204
|
+
return self.fingerprint["digest"]
|
|
205
|
+
|
|
206
|
+
def embed_passage(self, text: str) -> list[float]:
|
|
207
|
+
"""Embed text for storage using passage_embed.
|
|
208
|
+
|
|
209
|
+
Uses the model's passage embedding mode (no query instruction prefix).
|
|
210
|
+
Always pass [text] (list), never bare string.
|
|
211
|
+
"""
|
|
212
|
+
vectors = list(self._model.passage_embed([text]))
|
|
213
|
+
return vectors[0].tolist()
|
|
214
|
+
|
|
215
|
+
@property
|
|
216
|
+
def dimension(self) -> int:
|
|
217
|
+
"""Return the embedding dimension of the loaded model."""
|
|
218
|
+
# Embed a dummy string to discover the output dimension dynamically
|
|
219
|
+
vec = self.embed_passage("dim_probe")
|
|
220
|
+
return len(vec)
|
|
221
|
+
|
|
222
|
+
def embed_query(self, text: str) -> list[float]:
|
|
223
|
+
"""Embed text for search using query_embed.
|
|
224
|
+
|
|
225
|
+
Uses the model's query embedding mode (may prepend an instruction
|
|
226
|
+
prefix for asymmetric retrieval, depending on the model).
|
|
227
|
+
"""
|
|
228
|
+
vectors = list(self._model.query_embed(text))
|
|
229
|
+
return vectors[0].tolist()
|