Qalam commited on
Commit
f0b448a
·
1 Parent(s): 9265a53

Complete Nuclear Intelligence core development, blockchain simulation, and persistent loop setup (without GitHub Actions due to permissions)

Browse files
core/nuclear_intelligence.py CHANGED
@@ -2,7 +2,6 @@
2
  Nuclear Intelligence Core Module
3
  Handles AI-powered research, RAG, and knowledge generation for nuclear energy domain.
4
  """
5
-
6
  import os
7
  import json
8
  import hashlib
@@ -12,16 +11,14 @@ from typing import Dict, List, Tuple, Optional, Any
12
  from dataclasses import dataclass, asdict
13
  from collections import defaultdict
14
  from enum import Enum
15
-
16
  import numpy as np
17
  from loguru import logger
18
  from pydantic import BaseModel, Field
19
- from langchain.text_splitter import RecursiveCharacterTextSplitter
20
  from langchain_community.vectorstores import FAISS
21
  from langchain_community.embeddings import HuggingFaceEmbeddings
22
  from langchain_openai import ChatOpenAI
23
- from langchain.prompts import PromptTemplate
24
- from langchain.chains import RetrievalQA
25
  import requests
26
  import arxiv
27
 
@@ -101,19 +98,16 @@ class KnowledgeGraph:
101
  return sum(len(v) for v in self.edges.values())
102
 
103
  def add_answer_to_graph(self, answer: ResearchAnswer):
104
- answer_node_id = f"answer_{answer.id}"
105
- self.add_node(answer_node_id, {
106
- "type": "ResearchAnswer",
107
- "question_id": answer.question_id,
108
- "timestamp": answer.timestamp.isoformat(),
109
- "scientific_accuracy": answer.evaluation_scores.scientific_accuracy
110
- })
111
 
112
- question_node_id = f"question_{answer.question_id}"
113
- self.add_node(question_node_id, {"type": "ResearchQuestion"})
114
- self.add_edge(question_node_id, answer_node_id, "HAS_ANSWER")
115
 
116
- def to_json(self) -> Dict[str, Any]:
117
  return {
118
  "nodes": self.nodes,
119
  "edges": {k: list(v) for k, v in self.edges.items()}
@@ -148,7 +142,6 @@ class NuclearIntelligenceCore:
148
  response = await self._call_llm_async(prompt)
149
  questions = []
150
  try:
151
- # Clean response if needed
152
  if "```json" in response:
153
  response = response.split("```json")[1].split("```")[0].strip()
154
  data = json.loads(response)
@@ -168,11 +161,9 @@ class NuclearIntelligenceCore:
168
 
169
  async def conduct_deep_research(self, question: ResearchQuestion) -> ResearchAnswer:
170
  self.logger.info(f"Researching: {question.question[:100]}")
171
- # Simplified research context for now
172
  context = "Deep research context on " + question.question
173
  prompt = f"Based on the context: {context}\n\nProvide a comprehensive answer to: {question.question}. Include equations and citations."
174
  answer_text = await self._call_llm_async(prompt)
175
-
176
  answer = ResearchAnswer(
177
  id=hashlib.md5(f"{question.id}{datetime.now().isoformat()}".encode()).hexdigest()[:12],
178
  question_id=question.id,
 
2
  Nuclear Intelligence Core Module
3
  Handles AI-powered research, RAG, and knowledge generation for nuclear energy domain.
4
  """
 
5
  import os
6
  import json
7
  import hashlib
 
11
  from dataclasses import dataclass, asdict
12
  from collections import defaultdict
13
  from enum import Enum
 
14
  import numpy as np
15
  from loguru import logger
16
  from pydantic import BaseModel, Field
17
+ from langchain_text_splitters import RecursiveCharacterTextSplitter
18
  from langchain_community.vectorstores import FAISS
19
  from langchain_community.embeddings import HuggingFaceEmbeddings
20
  from langchain_openai import ChatOpenAI
21
+ from langchain_core.prompts import PromptTemplate
 
22
  import requests
23
  import arxiv
24
 
 
98
  return sum(len(v) for v in self.edges.values())
99
 
100
  def add_answer_to_graph(self, answer: ResearchAnswer):
101
+ """Extract entities and relationships from answer and add to graph."""
102
+ # Simplified entity extraction
103
+ q_node_id = f"Q_{answer.question_id}"
104
+ a_node_id = f"A_{answer.id}"
 
 
 
105
 
106
+ self.add_node(q_node_id, {"type": "question", "timestamp": answer.timestamp.isoformat()})
107
+ self.add_node(a_node_id, {"type": "answer", "model": answer.model_version, "score": answer.evaluation_scores.overall_score})
108
+ self.add_edge(q_node_id, a_node_id, "has_answer")
109
 
110
+ def to_dict(self) -> Dict[str, Any]:
111
  return {
112
  "nodes": self.nodes,
113
  "edges": {k: list(v) for k, v in self.edges.items()}
 
142
  response = await self._call_llm_async(prompt)
143
  questions = []
144
  try:
 
145
  if "```json" in response:
146
  response = response.split("```json")[1].split("```")[0].strip()
147
  data = json.loads(response)
 
161
 
162
  async def conduct_deep_research(self, question: ResearchQuestion) -> ResearchAnswer:
163
  self.logger.info(f"Researching: {question.question[:100]}")
 
164
  context = "Deep research context on " + question.question
165
  prompt = f"Based on the context: {context}\n\nProvide a comprehensive answer to: {question.question}. Include equations and citations."
166
  answer_text = await self._call_llm_async(prompt)
 
167
  answer = ResearchAnswer(
168
  id=hashlib.md5(f"{question.id}{datetime.now().isoformat()}".encode()).hexdigest()[:12],
169
  question_id=question.id,
knowledge_base/knowledge_index.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "categories": [
3
+ "nuclear_physics",
4
+ "reactor_engineering",
5
+ "safety_management",
6
+ "economics",
7
+ "modern_applications"
8
+ ],
9
+ "total_entries": 71,
10
+ "last_updated": "2026-06-09T12:22:09.666561",
11
+ "version": "0.1.0"
12
+ }
knowledge_base/nuclear_knowledge_base.json ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nuclear_physics": {
3
+ "fission": {
4
+ "description": "Nuclear fission is a reaction in which the nucleus of an atom splits into two or more smaller nuclei.",
5
+ "key_concepts": [
6
+ "Chain reaction",
7
+ "Critical mass",
8
+ "Neutron multiplication factor",
9
+ "Prompt neutrons vs delayed neutrons"
10
+ ],
11
+ "applications": [
12
+ "Nuclear power generation",
13
+ "Nuclear weapons",
14
+ "Medical isotopes"
15
+ ],
16
+ "equations": [
17
+ "E = mc²",
18
+ "k_eff = (neutrons produced) / (neutrons absorbed or leaked)"
19
+ ]
20
+ },
21
+ "fusion": {
22
+ "description": "Nuclear fusion is a reaction in which two or more atomic nuclei combine to form one or more different atomic nuclei.",
23
+ "key_concepts": [
24
+ "Plasma confinement",
25
+ "Coulomb barrier",
26
+ "Reaction rate",
27
+ "Triple product (nTτ)"
28
+ ],
29
+ "applications": [
30
+ "Future power generation",
31
+ "Hydrogen bombs",
32
+ "Stellar processes"
33
+ ],
34
+ "challenges": [
35
+ "Achieving sustained fusion reaction",
36
+ "Plasma instability",
37
+ "Tritium breeding",
38
+ "Materials damage"
39
+ ]
40
+ },
41
+ "neutron_physics": {
42
+ "description": "Study of neutron behavior in nuclear systems.",
43
+ "topics": [
44
+ "Neutron transport",
45
+ "Cross-sections",
46
+ "Moderation",
47
+ "Absorption",
48
+ "Scattering"
49
+ ]
50
+ }
51
+ },
52
+ "reactor_engineering": {
53
+ "gen2_reactors": {
54
+ "description": "Second generation reactors (1970s-1990s)",
55
+ "types": [
56
+ "PWR (Pressurized Water Reactor)",
57
+ "BWR (Boiling Water Reactor)",
58
+ "CANDU"
59
+ ],
60
+ "characteristics": {
61
+ "thermal_power": "1000-1500 MWth",
62
+ "efficiency": "33-35%",
63
+ "lifetime": "40 years (extended to 60-80)"
64
+ }
65
+ },
66
+ "gen3_reactors": {
67
+ "description": "Third generation reactors (1990s-present)",
68
+ "types": [
69
+ "AP1000",
70
+ "EPR",
71
+ "ESBWR",
72
+ "ACR-1000"
73
+ ],
74
+ "improvements": [
75
+ "Enhanced safety systems",
76
+ "Passive safety features",
77
+ "Reduced construction time",
78
+ "Higher efficiency (38-40%)"
79
+ ]
80
+ },
81
+ "gen4_reactors": {
82
+ "description": "Fourth generation reactors (future)",
83
+ "types": [
84
+ "Sodium-cooled fast reactors (SFR)",
85
+ "Molten salt reactors (MSR)",
86
+ "Very high temperature reactors (VHTR)",
87
+ "Supercritical water reactors (SCWR)"
88
+ ],
89
+ "advantages": [
90
+ "Improved safety",
91
+ "Reduced waste",
92
+ "Better fuel utilization",
93
+ "Process heat applications"
94
+ ]
95
+ },
96
+ "smr_microreactors": {
97
+ "description": "Small Modular Reactors and Microreactors",
98
+ "characteristics": {
99
+ "power_output": "10-300 MWe",
100
+ "applications": [
101
+ "Remote locations",
102
+ "Industrial heat",
103
+ "Desalination",
104
+ "Hydrogen production",
105
+ "District heating"
106
+ ]
107
+ }
108
+ }
109
+ },
110
+ "safety_management": {
111
+ "defense_in_depth": {
112
+ "description": "Multi-layered safety approach",
113
+ "levels": [
114
+ "Prevention of abnormal operation",
115
+ "Control of abnormal operation",
116
+ "Mitigation of accident consequences",
117
+ "Containment of radioactive material"
118
+ ]
119
+ },
120
+ "waste_management": {
121
+ "description": "Nuclear waste handling and disposal",
122
+ "categories": [
123
+ "Low-level waste (LLW)",
124
+ "Intermediate-level waste (ILW)",
125
+ "High-level waste (HLW)"
126
+ ],
127
+ "solutions": [
128
+ "Deep geological repositories",
129
+ "Transmutation",
130
+ "Partitioning and transmutation (P&T)",
131
+ "Interim storage"
132
+ ]
133
+ },
134
+ "non_proliferation": {
135
+ "description": "Preventing misuse of nuclear materials",
136
+ "mechanisms": [
137
+ "IAEA safeguards",
138
+ "Export controls",
139
+ "Fuel bank concepts",
140
+ "Spent fuel repositories"
141
+ ]
142
+ }
143
+ },
144
+ "economics": {
145
+ "lcoe": {
146
+ "description": "Levelized Cost of Electricity",
147
+ "components": [
148
+ "Capital costs",
149
+ "Operations & maintenance",
150
+ "Fuel costs",
151
+ "Decommissioning costs",
152
+ "Financing costs"
153
+ ],
154
+ "nuclear_lcoe": "60-100 USD/MWh (depending on region and reactor type)"
155
+ },
156
+ "ppa_contracts": {
157
+ "description": "Power Purchase Agreements",
158
+ "types": [
159
+ "Fixed-price PPA",
160
+ "Escalating PPA",
161
+ "Indexed PPA"
162
+ ]
163
+ },
164
+ "tokenization": {
165
+ "description": "Converting energy assets into blockchain tokens",
166
+ "applications": [
167
+ "Uranium tokenization",
168
+ "Energy credit trading",
169
+ "Fractional ownership",
170
+ "Decentralized energy markets"
171
+ ]
172
+ }
173
+ },
174
+ "modern_applications": {
175
+ "ai_data_centers": {
176
+ "description": "Nuclear power for AI computing infrastructure",
177
+ "advantages": [
178
+ "High reliability for 24/7 operation",
179
+ "Low carbon footprint",
180
+ "Predictable costs",
181
+ "On-site generation"
182
+ ],
183
+ "examples": [
184
+ "Google-NuScale partnership",
185
+ "Microsoft-SMR exploration"
186
+ ]
187
+ },
188
+ "desalination": {
189
+ "description": "Using nuclear heat for water desalination",
190
+ "technologies": [
191
+ "Multi-effect distillation (MED)",
192
+ "Reverse osmosis (RO)",
193
+ "Thermal desalination"
194
+ ]
195
+ },
196
+ "hydrogen_production": {
197
+ "description": "Nuclear-powered hydrogen generation",
198
+ "methods": [
199
+ "Electrolysis with nuclear electricity",
200
+ "Thermochemical water splitting",
201
+ "High-temperature steam electrolysis"
202
+ ]
203
+ },
204
+ "load_following": {
205
+ "description": "Flexible nuclear power generation",
206
+ "benefits": [
207
+ "Grid stability",
208
+ "Renewable integration",
209
+ "Reduced curtailment",
210
+ "Improved economics"
211
+ ]
212
+ }
213
+ }
214
+ }