KnowledgeSnapshot.fromMap constructor
Reopens saved passages without tokenization or embedding inference. Graph and typed metadata meanings are reconstructed by upstream OKF.
Implementation
factory KnowledgeSnapshot.fromMap(Map<String, Object?> map) {
if (map['version'] != 1) {
throw const FormatException('Unsupported knowledge snapshot version.');
}
final original = KnowledgeSnapshot.fromSources(
Map<String, String>.from(map['sources']! as Map),
bundleId: map['bundleId']! as String,
assets: List<String>.from(map['assets']! as List),
);
final chunks = (map['chunks']! as List)
.map((value) => Chunk.fromMap(Map<String, Object?>.from(value as Map)))
.toList();
final contexts = Map<String, String>.from(map['contextTexts']! as Map);
final ids = chunks.map((chunk) => chunk.id).toSet();
if (ids.length != chunks.length ||
contexts.length != ids.length ||
chunks.any(
(chunk) =>
!original.conceptPaths.contains(chunk.sourcePath) ||
!(contexts[chunk.id]?.endsWith(chunk.content) ?? false),
)) {
throw const FormatException('Inconsistent saved knowledge passages.');
}
return KnowledgeSnapshot._(
original.bundleId,
List.unmodifiable(chunks),
original.graph,
original._metadata,
Map.unmodifiable(contexts),
original.sources,
original.assets,
);
}