developeranveshraman commited on
Commit
c3af799
Β·
verified Β·
1 Parent(s): 2413b3a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +558 -3
README.md CHANGED
@@ -1,3 +1,558 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ # AnveshAI Edge V2
6
+
7
+ **A fully offline, hybrid AI tutor for JEE Advanced β€” Physics, Chemistry, and Mathematics.**
8
+
9
+ AnveshAI Edge is a terminal-based AI assistant designed to run entirely on-device (CPU only). It combines dedicated deterministic engines for Physics, Chemistry, and symbolic Mathematics with a local knowledge base and a compact 1.5B-parameter language model into a unified hierarchical pipeline. A **chain-of-thought reasoning engine** decomposes every problem before the LLM is invoked, significantly reducing hallucinations for supported deterministic problems and improving answer quality.
10
+
11
+ ---
12
+
13
+ ## Links
14
+
15
+ - GitHub: *[Click Here!](https://github.com/AnveshAI/AnveshAI-Edge-V2)*
16
+ - Zenodo: *Coming Soon!*
17
+
18
+ ---
19
+
20
+ ## Why AnveshAI Edge?
21
+
22
+ - Works fully offline β€” no internet required after the one-time model download
23
+ - Gives step-by-step JEE Advanced-style solutions
24
+ - Uses far less compute than cloud AI tools β€” hybrid deterministic solving avoids sending every query through a large model, reducing compute cost significantly for supported problem types
25
+ - Designed for students on low-resource hardware
26
+
27
+ ---
28
+
29
+ ## Benchmark Snapshot (V2)
30
+
31
+ | Metric | Result |
32
+ |--------|--------|
33
+ | Overall pass rate | 81.1% |
34
+ | Routing accuracy | 100% |
35
+ | Average latency | 0.3 ms |
36
+ | Main remaining bottleneck | Primarily solver coverage gaps |
37
+
38
+ ---
39
+
40
+ ## Table of Contents
41
+
42
+ 1. [Links](#links)
43
+ 2. [Architecture Overview](#architecture-overview)
44
+ 3. [Components](#components)
45
+ 4. [JEE Advanced Domain Coverage](#jee-advanced-domain-coverage)
46
+ 5. [Question Bank](#question-bank)
47
+ 6. [Advanced Math Engine](#advanced-math-engine)
48
+ 7. [Reasoning Engine](#reasoning-engine)
49
+ 8. [Getting Started](#getting-started)
50
+ 9. [Usage Examples](#usage-examples)
51
+ 10. [Commands](#commands)
52
+ 11. [Design Principles](#design-principles)
53
+ 12. [Current Limitations](#current-limitations)
54
+ 13. [File Structure](#file-structure)
55
+ 14. [Technical Details](#technical-details)
56
+
57
+ ---
58
+
59
+ ## Architecture Overview
60
+
61
+ AnveshAI Edge uses a **hierarchical fallback pipeline** with reasoning at every non-trivial stage:
62
+
63
+ ```
64
+ User Input
65
+ β”‚
66
+ β”œβ”€β”€ [/command] ──► System Handler (instant)
67
+ β”‚
68
+ β”œβ”€β”€ [arithmetic] ──► Math Engine (AST safe-eval, instant)
69
+ β”‚
70
+ β”œβ”€β”€ [physics] ──► Reasoning Engine: analyze()
71
+ β”‚ β”‚ (problem type, strategy selection)
72
+ β”‚ β–Ό
73
+ β”‚ Physics Engine (formula solver)
74
+ β”‚ β”‚ EXACT answer computed
75
+ β”‚ β–Ό
76
+ β”‚ Reasoning Engine: build_math_prompt()
77
+ β”‚ β”‚ (CoT plan embedded in LLM prompt)
78
+ β”‚ β–Ό
79
+ β”‚ LLM (Qwen2.5-1.5B) β†’ Step-by-step explanation
80
+ β”‚
81
+ β”œβ”€β”€ [chemistry] ──► Reasoning Engine: analyze()
82
+ β”‚ β–Ό
83
+ β”‚ Chemistry Engine (stoichiometry, equilibrium, kinetics…)
84
+ β”‚ β–Ό
85
+ β”‚ LLM with CoT context β†’ User
86
+ β”‚
87
+ β”œβ”€β”€ [advanced math] ──► Reasoning Engine: analyze()
88
+ β”‚ β–Ό
89
+ β”‚ Advanced Math Engine (SymPy β€” exact symbolic answer)
90
+ β”‚ β–Ό
91
+ β”‚ LLM with CoT context β†’ User
92
+ β”‚
93
+ β”œβ”€β”€ [knowledge] ──► Knowledge Engine (local KB)
94
+ β”‚ β”œβ”€β”€ match found β†’ User
95
+ β”‚ └── no match β†’ LLM with CoT context β†’ User
96
+ β”‚
97
+ β”œβ”€β”€ [logic] ──► Inference Engine (propositional logic)
98
+ β”‚ └── LLM with CoT context β†’ User
99
+ β”‚
100
+ └── [conversation] ──► Conversation Engine (pattern rules)
101
+ β”œβ”€β”€ matched β†’ User
102
+ └── no match β†’ LLM with CoT context β†’ User
103
+ ```
104
+
105
+ ### Key Design Principle
106
+
107
+ > **Correctness-first:** For all deterministic problems (math, physics, chemistry), the domain engine computes the exact answer *before* the LLM is called. The LLM's only task is to explain the working β€” it cannot invent a wrong answer.
108
+
109
+ ---
110
+
111
+ ## Components
112
+
113
+ | Module | File | Role |
114
+ |--------|------|------|
115
+ | **Intent Router** | `router.py` | Rule-based intent classifier. Outputs: `system`, `physics`, `chemistry`, `advanced_math`, `math`, `knowledge`, `logic`, `conversation`. Checked in priority order. |
116
+ | **Math Engine** | `math_engine.py` | Safe AST-based evaluator for plain arithmetic (`2 + 3 * (4^2)`). No `eval()` β€” uses a whitelist of allowed AST node types. |
117
+ | **Advanced Math Engine** | `advanced_math_engine.py` | SymPy symbolic computation engine. 31+ operation types. Returns `(success, result_str, latex_str)`. |
118
+ | **Physics Engine** | `physics_engine.py` | Deterministic formula solver for JEE Advanced Physics: mechanics, SHM, electrostatics, magnetism, modern physics, optics, thermodynamics. |
119
+ | **Chemistry Engine** | `chemistry_engine.py` | Deterministic solver for JEE Advanced Chemistry: stoichiometry, equilibrium (Kc/Kp), kinetics, colligative properties, solid state, acid-base. |
120
+ | **Reasoning Engine** | `reasoning_engine.py` | Structured reasoning planner using chain-of-thought decomposition. Identifies 64 problem types across 15+ domains, selects strategy, generates ordered sub-steps, assigns confidence, flags warnings. Builds structured LLM prompts. |
121
+ | **Inference Engine** | `inference_engine.py` | Propositional logic and deductive reasoning handler. |
122
+ | **Knowledge Engine** | `knowledge_engine.py` | Local knowledge-base lookup from `knowledge.txt`. Returns `(response, found: bool)`. |
123
+ | **Conversation Engine** | `conversation_engine.py` | Pattern-matching response rules from `conversation.txt`. Returns `(response, matched: bool)`. |
124
+ | **LLM Engine** | `llm_engine.py` | Lazy-loading `Qwen2.5-1.5B-Instruct` (GGUF, Q4_K_M, ~1 GB) via `llama-cpp-python`. CPU-only, no GPU required. JEE Advanced system prompt tuned for exam-level rigor. |
125
+ | **Memory** | `memory.py` | SQLite-backed conversation history. Powers the `/history` command. |
126
+ | **Main** | `main.py` | Terminal REPL loop. Orchestrates all engines. Displays colour-coded output. |
127
+
128
+ ---
129
+
130
+ ## JEE Advanced Domain Coverage
131
+
132
+ AnveshAI Edge currently supports core JEE Advanced topics, with ongoing solver expansion.
133
+
134
+ ### Physics Topics Handled
135
+
136
+ | Domain | Problem Types | Example Queries |
137
+ |--------|--------------|----------------|
138
+ | Mechanics | `physics_problem`, `shm_problem` | Kinetic energy, time period of spring-mass system |
139
+ | SHM & Oscillations | `shm_problem` | Spring constant, pendulum period, angular frequency |
140
+ | Rotational Mechanics | `rotational_mechanics` | Moment of inertia, angular momentum, rolling motion |
141
+ | Modern Physics | `modern_physics` | Photoelectric effect, de Broglie wavelength, Bohr model |
142
+ | Electrostatics | `electrostatics` | Electric field, Coulomb's law, potential |
143
+ | Electromagnetism | `electromagnetism` | Self-inductance, solenoid, Faraday's law |
144
+ | Thermodynamics | `ideal_gas_thermo` | Ideal gas, internal energy, isothermal/adiabatic |
145
+
146
+ ### Chemistry Topics Handled
147
+
148
+ | Domain | Problem Types | Example Queries |
149
+ |--------|--------------|----------------|
150
+ | Chemical Equilibrium | `chemical_equilibrium` | Kc, Kp, delta n, ICE tables |
151
+ | Chemical Kinetics | `chemical_kinetics` | Rate law, half-life, Arrhenius equation |
152
+ | Solid State | `solid_state` | BCC/FCC/SC lattice, packing fraction, atomic radius |
153
+ | Colligative Properties | `colligative_properties` | Boiling point elevation, osmotic pressure, van't Hoff |
154
+ | Acid-Base / pH | `chemistry_problem` | pH calculations, buffer solutions, Nernst equation |
155
+ | General Chemistry | `chemistry_problem` | Stoichiometry, molarity, enthalpy |
156
+
157
+ ### Mathematics Topics Handled
158
+
159
+ | Domain | Problem Types | Example Queries |
160
+ |--------|--------------|----------------|
161
+ | Calculus | `integration`, `differentiation`, `limit_evaluation`, `maxima_minima`, `monotonicity` | Integration by parts, implicit diff, L'HΓ΄pital |
162
+ | Coordinate Geometry | `conic_parabola`, `conic_ellipse`, `conic_hyperbola`, `circle_geometry`, `straight_line` | Tangent to parabola, foci of ellipse, asymptotes |
163
+ | 3D Geometry & Vectors | `3d_geometry`, `vector_algebra` | Shortest distance between skew lines, scalar triple product |
164
+ | Trigonometry | `trigonometric_equation`, `inverse_trig`, `trig_identities`, `triangle_trig` | General solution of sin 2x = cos x |
165
+ | Algebra | `sequences_series`, `binomial_theorem`, `equation_solving` | AP/GP sums, middle term in binomial expansion |
166
+ | Probability & Stats | `bayes_probability`, `probability_problem`, `statistical_analysis` | Bayes theorem, probability distributions |
167
+ | ODE & Transforms | `ode_solving`, `laplace_transform`, `fourier_transform` | Solve y'' + y = 0, Laplace of sin(t) |
168
+ | Linear Algebra | `matrix_operation`, `eigenvalue` | Determinant, eigenvalues, matrix inverse |
169
+
170
+ ---
171
+
172
+ ## Question Bank
173
+
174
+ AnveshAI Edge includes **3,000 tagged benchmark questions** (`datasheet.csv`) spanning all three subjects.
175
+
176
+ | Subject | Questions | Topics Covered |
177
+ |---------|-----------|---------------|
178
+ | **Physics** | 1,000 | SHM, Mechanics, Rotational Mechanics, Gravitation, Electrostatics, Electromagnetism, Current Electricity, Thermodynamics, Optics, Wave Optics, Waves, Modern Physics, Semiconductors, AC Circuits, Fluid Mechanics, Electromagnetic Waves |
179
+ | **Chemistry** | 1,000 | Chemical Equilibrium, Chemical Kinetics, Solid State, Colligative Properties, Acid-Base/pH, Electrochemistry, Thermochemistry, Organic Chemistry, Coordination Chemistry, Periodic Table, Chemical Bonding, Solutions, Surface Chemistry, Industrial Chemistry, Biochemistry, Polymers, Analytical Chemistry, Environmental Chemistry, Metallurgy |
180
+ | **Mathematics** | 1,000 | Integration, Differentiation, Limits, Maxima-Minima, Sequences & Series, Binomial Theorem, Complex Numbers, Quadratics/Polynomials, Probability & Distributions, Matrices & Determinants, Differential Equations, Laplace/Fourier Transforms, Number Theory, Statistics, Combinatorics, Coordinate Geometry (Straight Lines, Circles, Parabola, Ellipse, Hyperbola), 3D Geometry, Vectors, Trigonometry |
181
+
182
+ ### Dataset Format (`datasheet.csv`)
183
+
184
+ ```
185
+ id, question, subject, topic, expected_intent, expected_problem_type
186
+ ```
187
+
188
+ Each row contains a unique question ID, the full question text, subject, topic tag, the expected intent label (used by the router), and the expected problem type (used by the reasoning engine). This dataset is used by `benchmark.py` to evaluate end-to-end routing and classification accuracy.
189
+
190
+ ### Running the Benchmark
191
+
192
+ ```bash
193
+ python benchmark.py
194
+ ```
195
+
196
+ Outputs `report.csv` with per-question results and a summary block including overall accuracy, per-subject breakdown, and weak-topic identification.
197
+
198
+ ---
199
+
200
+ ## Advanced Math Engine
201
+
202
+ The engine supports **31+ symbolic mathematics operations** across 11 categories:
203
+
204
+ ### Calculus
205
+ | Operation | Example Input |
206
+ |-----------|--------------|
207
+ | Indefinite integration | `integrate x^2 sin(x)` |
208
+ | Definite integration | `definite integral of x^2 from 0 to 3` |
209
+ | Differentiation (any order) | `second derivative of sin(x) * e^x` |
210
+ | Limits (including ±∞) | `limit of sin(x)/x as x approaches 0` |
211
+
212
+ ### Algebra & Equations
213
+ | Operation | Example Input |
214
+ |-----------|--------------|
215
+ | Equation solving | `solve x^2 - 5x + 6 = 0` |
216
+ | Factorisation | `factor x^3 - 8` |
217
+ | Expansion | `expand (x + y)^4` |
218
+ | Simplification | `simplify (x^2 - 1)/(x - 1)` |
219
+ | Partial fractions | `partial fraction 1/(x^2 - 1)` |
220
+ | Trig simplification | `simplify trig sin^2(x) + cos^2(x)` |
221
+
222
+ ### Differential Equations
223
+ | Operation | Example Input |
224
+ |-----------|--------------|
225
+ | ODE solving (dsolve) | `solve differential equation y'' + y = 0` |
226
+ | First-order ODEs | `solve ode dy/dx = y` |
227
+
228
+ ### Series & Transforms
229
+ | Operation | Example Input |
230
+ |-----------|--------------|
231
+ | Taylor / Maclaurin series | `taylor series of e^x around 0 order 6` |
232
+ | Laplace transform | `laplace transform of sin(t)` |
233
+ | Inverse Laplace transform | `inverse laplace of 1/(s^2 + 1)` |
234
+ | Fourier transform | `fourier transform of exp(-x^2)` |
235
+
236
+ ### Linear Algebra
237
+ | Operation | Example Input |
238
+ |-----------|--------------|
239
+ | Determinant | `determinant of [[1,2],[3,4]]` |
240
+ | Matrix inverse | `inverse matrix [[2,1],[5,3]]` |
241
+ | Eigenvalues & eigenvectors | `eigenvalue [[4,1],[2,3]]` |
242
+ | Matrix rank | `rank of matrix [[1,2,3],[4,5,6]]` |
243
+ | Matrix trace | `trace of matrix [[1,2],[3,4]]` |
244
+
245
+ ### Number Theory
246
+ | Operation | Example Input |
247
+ |-----------|--------------|
248
+ | GCD | `gcd of 48 and 18` |
249
+ | LCM | `lcm of 12 and 15` |
250
+ | Prime factorisation | `prime factorization of 360` |
251
+ | Modular arithmetic | `17 mod 5` |
252
+ | Modular inverse | `modular inverse of 3 mod 7` |
253
+
254
+ ### Statistics
255
+ | Operation | Example Input |
256
+ |-----------|--------------|
257
+ | Descriptive stats | `mean of 2, 4, 6, 8, 10` |
258
+ | Standard deviation | `standard deviation of 1, 2, 3, 4, 5` |
259
+
260
+ ### Combinatorics
261
+ | Operation | Example Input |
262
+ |-----------|--------------|
263
+ | Factorial | `factorial of 10` |
264
+ | Binomial coefficient | `binomial coefficient 10 choose 3` |
265
+ | Permutations | `permutation 6 P 2` |
266
+
267
+ ### Summations & Products
268
+ | Operation | Example Input |
269
+ |-----------|--------------|
270
+ | Finite sum | `sum of k^2 for k from 1 to 10` |
271
+ | Infinite series | `summation of 1/n^2 for n from 1 to infinity` |
272
+
273
+ ### Complex Numbers
274
+ | Operation | Example Input |
275
+ |-----------|--------------|
276
+ | All properties | `modulus of 3 + 4*I` |
277
+
278
+ ---
279
+
280
+ ## Reasoning Engine
281
+
282
+ The **ReasoningEngine** adds structured chain-of-thought reasoning at every stage.
283
+
284
+ ### Reasoning Pipeline (4 Stages)
285
+
286
+ **Stage 1 β€” Problem Analysis**
287
+ - Detects domain (15+ domains: calculus, linear algebra, coordinate_geometry, 3d_geometry, trigonometry, statistics, physics, chemistry, computer_science, …)
288
+ - Classifies problem type (64 problem types via priority-ordered regex)
289
+ - Identifies sub-questions implicit in the problem
290
+
291
+ **Stage 2 β€” Strategy Selection**
292
+ - Chooses the optimal solution method (u-substitution, L'HΓ΄pital, ICE table, Kp-Kc relation, parallel axis theorem, …)
293
+ - Decomposes the problem into an ordered list of numbered reasoning steps
294
+
295
+ **Stage 3 β€” Verification & Confidence**
296
+ - Assigns confidence: `HIGH` (symbolic/deterministic answer available), `MEDIUM`, or `LOW`
297
+ - Detects warnings: missing bounds, undetected variables, potential singularities
298
+
299
+ **Stage 4 β€” Prompt Engineering**
300
+ - Builds a structured LLM prompt that embeds the full reasoning plan
301
+ - For math/physics/chemistry: forces the LLM to follow exact numbered steps toward the verified answer
302
+ - For knowledge: guides the LLM through the identified sub-questions in order
303
+
304
+ ### ReasoningPlan Data Structure
305
+
306
+ ```python
307
+ @dataclass
308
+ class ReasoningPlan:
309
+ problem_type: str # e.g. "conic_parabola", "chemical_kinetics"
310
+ domain: str # e.g. "coordinate_geometry", "chemistry"
311
+ sub_problems: list[str] # ordered reasoning steps
312
+ strategy: str # solution method description
313
+ expected_form: str # what the answer should look like
314
+ assumptions: list[str] # stated assumptions
315
+ confidence: str # HIGH / MEDIUM / LOW
316
+ warnings: list[str] # potential issues flagged
317
+ ```
318
+
319
+ ### Problem Types Covered (64 types across 15+ domains)
320
+
321
+ | Category | Problem Types |
322
+ |----------|--------------|
323
+ | Calculus | `integration`, `differentiation`, `limit_evaluation`, `ode_solving`, `maxima_minima`, `monotonicity`, `mean_value_theorem` |
324
+ | Coordinate Geometry | `conic_parabola`, `conic_ellipse`, `conic_hyperbola`, `conic_section`, `circle_geometry`, `straight_line`, `pair_of_lines` |
325
+ | 3D Geometry & Vectors | `3d_geometry`, `vector_algebra` |
326
+ | Trigonometry | `trigonometric_equation`, `inverse_trig`, `trig_identities`, `triangle_trig` |
327
+ | Algebra | `sequences_series`, `binomial_theorem`, `equation_solving`, `factorization`, `algebraic_expansion`, `simplification`, `summation` |
328
+ | Probability & Stats | `bayes_probability`, `probability_problem`, `probability_distribution`, `statistical_analysis` |
329
+ | Transforms & Series | `laplace_transform`, `fourier_transform`, `series_expansion` |
330
+ | Linear Algebra | `matrix_operation`, `eigenvalue` |
331
+ | Number Theory | `number_theory`, `combinatorics` |
332
+ | Physics | `shm_problem`, `rotational_mechanics`, `modern_physics`, `electrostatics`, `electromagnetism`, `ideal_gas_thermo`, `physics_problem` |
333
+ | Chemistry | `chemical_equilibrium`, `chemical_kinetics`, `solid_state`, `colligative_properties`, `chemistry_problem` |
334
+ | Logic & Reasoning | `propositional_logic`, `logical_reasoning`, `analogical_reasoning`, `causal_analysis`, `comparative_analysis` |
335
+ | Knowledge | `knowledge_retrieval`, `conceptual_explanation`, `procedural_knowledge` |
336
+
337
+ ### Why Chain-of-Thought Matters for a Small LLM
338
+
339
+ The Qwen2.5-1.5B model has 1.5 billion parameters. Without structured guidance it can still:
340
+ - Skip algebraic steps
341
+ - Confuse method with result on multi-step problems
342
+ - Apply correct techniques incorrectly
343
+
344
+ By embedding a detailed reasoning plan in every prompt β€” and for deterministic problems, by **providing the correct answer upfront** β€” the model's role becomes that of a *step-by-step explainer* rather than an *unsupervised solver*. This dramatically improves output quality without requiring a larger model.
345
+
346
+ ---
347
+
348
+ ## Getting Started
349
+
350
+ ### System Requirements
351
+
352
+ | Requirement | Minimum |
353
+ |-------------|---------|
354
+ | RAM | 4 GB (8 GB recommended) |
355
+ | OS | Linux, macOS, Windows (WSL recommended on Windows) |
356
+ | Python | 3.9+ |
357
+ | Disk space | ~2 GB (model + dependencies) |
358
+
359
+ > **First run:** The Qwen2.5-1.5B model (~1 GB) is downloaded automatically from HuggingFace and cached locally. Expect 5–15 minutes depending on your connection speed. Subsequent runs load from cache instantly.
360
+
361
+ ### Installation
362
+
363
+ ```bash
364
+ pip install sympy llama-cpp-python colorama
365
+ ```
366
+
367
+ > **Note for `llama-cpp-python`:** This package compiles C++ code during installation. You may need:
368
+ > - A C++ compiler (`gcc` / `g++` on Linux, Xcode CLI tools on macOS)
369
+ > - At least 2 GB of free RAM during the build
370
+ > - If the build fails, try: `pip install llama-cpp-python --no-cache-dir`
371
+
372
+ > **Replit users:** Use the AnveshAI Edge workflow β€” dependencies are pre-configured. RAM may be limited on free-tier instances; the model may load slowly or require a paid plan with higher memory.
373
+
374
+ ### Troubleshooting
375
+
376
+ | Issue | Fix |
377
+ |-------|-----|
378
+ | `llama-cpp-python` build fails | Install `build-essential` (Linux) or Xcode CLI tools (macOS) |
379
+ | Out of memory on model load | Close other apps; ensure at least 3 GB free RAM |
380
+ | Model download stalls | Check your internet connection; delete the partial cache and retry |
381
+ | Slow inference | Normal on CPU β€” first-token latency is ~2–5 s on typical hardware |
382
+
383
+ ### Running
384
+
385
+ ```bash
386
+ cd anveshai
387
+ python main.py
388
+ # try: "integrate x^2 sin(x)"
389
+ ```
390
+
391
+ Or use the **AnveshAI Edge** workflow in the Replit environment.
392
+
393
+ ---
394
+
395
+ ## Usage Examples
396
+
397
+ ```
398
+ You β€Ί A spring of constant 200 N/m has a mass of 0.5 kg attached. Find the time period.
399
+
400
+ Physics Engine β†’ T = 2Ο€βˆš(m/k) = 2Ο€βˆš(0.5/200) = 0.314 s
401
+ [Reasoning] domain=physics | type=shm_problem | strategy=SHM formula | confidence=HIGH
402
+
403
+ AnveshAI [Physics+CoT+LLM] β€Ί T β‰ˆ 0.314 s
404
+ Step 1: Identify the spring-mass system parameters: k = 200 N/m, m = 0.5 kg
405
+ Step 2: Apply the SHM time period formula: T = 2Ο€βˆš(m/k)
406
+ Step 3: Substitute: T = 2Ο€βˆš(0.5/200) = 2Ο€ Γ— 0.05 = 0.314 s
407
+ ```
408
+
409
+ ```
410
+ You β€Ί Kc for N2 + 3H2 β‡Œ 2NH3 is 0.5 at 400K. Find Kp.
411
+
412
+ Chemistry Engine β†’ Kp = Kc(RT)^Ξ”n, Ξ”n = 2βˆ’4 = βˆ’2
413
+ [Reasoning] domain=chemistry | type=chemical_equilibrium | confidence=HIGH
414
+
415
+ AnveshAI [Chem+CoT+LLM] β€Ί Kp = Kc Γ— (RT)^(βˆ’2) β‰ˆ 3.27 Γ— 10⁻⁡
416
+ Step 1: Write the balanced equation and count Ξ”n = moles product gas βˆ’ moles reactant gas
417
+ Step 2: Ξ”n = 2 βˆ’ (1 + 3) = βˆ’2
418
+ Step 3: Apply Kp = Kc(RT)^Ξ”n = 0.5 Γ— (0.0821 Γ— 400)^(βˆ’2)
419
+ ```
420
+
421
+ ```
422
+ You β€Ί Find the equation of tangent to parabola yΒ²=8x at point (2,4).
423
+
424
+ SymPy β†’ Tangent computed
425
+ [Reasoning] domain=coordinate_geometry | type=conic_parabola | confidence=HIGH
426
+
427
+ AnveshAI [AdvMath+CoT+LLM] β€Ί y = x + 2
428
+ Step 1: Identify standard form yΒ²=4ax, so a = 2
429
+ Step 2: Slope of tangent at (x₁, y₁): m = 2a/y₁ = 4/4 = 1
430
+ Step 3: Tangent equation: yy₁ = 2a(x + x₁) β†’ 4y = 4(x + 2) β†’ y = x + 2
431
+ ```
432
+
433
+ ```
434
+ You β€Ί integrate x^2 sin(x)
435
+
436
+ SymPy β†’ ∫ (x**2*sin(x)) dx = -x**2*cos(x) + 2*x*sin(x) + 2*cos(x) + C
437
+ [Reasoning] domain=calculus | strategy=Apply integration by parts (IBP) | confidence=HIGH
438
+
439
+ AnveshAI [AdvMath+CoT+LLM] β€Ί -x**2*cos(x) + 2*x*sin(x) + 2*cos(x) + C
440
+ Step 1: Use Integration by Parts twice: u = xΒ², dv = sin(x)dx
441
+ …
442
+ ```
443
+
444
+ ---
445
+
446
+ ## Commands
447
+
448
+ | Command | Action |
449
+ |---------|--------|
450
+ | `/help` | Show all commands and usage examples |
451
+ | `/history` | Display the last 10 conversation turns |
452
+ | `/exit` | Quit the assistant |
453
+
454
+ ---
455
+
456
+ ## Design Principles
457
+
458
+ 1. **Correctness-first for deterministic problems** β€” The domain engine (SymPy / Physics / Chemistry) always runs before the LLM. The LLM explains, it does not compute.
459
+
460
+ 2. **Offline-first** β€” All computation runs locally. No API keys, no internet connection required after the one-time model download (~1 GB).
461
+
462
+ 3. **JEE Advanced focus** β€” System prompts, strategy libraries, and reasoning steps are tuned for JEE Advanced level. Domain scoring prioritises correct sub-domain classification (SHM vs rotational, equilibrium vs kinetics, conics vs 3D).
463
+
464
+ 4. **Transparency** β€” The system prints its internal reasoning trace to the console (engine used, reasoning plan summary, confidence, warnings).
465
+
466
+ 5. **Graceful degradation** β€” Every engine has a fallback: SymPy failures fall back to CoT-guided LLM, KB misses fall back to reasoning-guided LLM.
467
+
468
+ 6. **Safety** β€” Arithmetic uses AST-based safe-eval (no `eval()`). Matrix parsing uses a validated bracket pattern before `eval()`. The LLM prompt explicitly forbids inventing a different answer.
469
+
470
+ 7. **Modularity** β€” Every engine is independent and communicates through simple return types. Adding a new math operation requires only a new handler function and a keyword entry.
471
+
472
+ ---
473
+
474
+ ## Current Limitations
475
+
476
+ - Some advanced Physics and Chemistry formula handlers are still being added; solver gaps account for all current benchmark failures
477
+ - Open-ended conceptual explanations depend on the 1.5B LLM and may vary in depth or phrasing
478
+ - CPU inference speed depends on hardware β€” responses may take several seconds on lower-end machines
479
+ - The model requires at least ~3 GB of free RAM to load comfortably
480
+
481
+ ---
482
+
483
+ ## File Structure
484
+
485
+ ```
486
+ anveshai/
487
+ β”œβ”€β”€ main.py # REPL loop, orchestration, response composer
488
+ β”œβ”€β”€ router.py # Rule-based intent classifier (8 intents)
489
+ β”œβ”€β”€ math_engine.py # Safe AST arithmetic evaluator
490
+ β”œβ”€β”€ advanced_math_engine.py # SymPy symbolic engine (31+ operations)
491
+ β”œβ”€β”€ physics_engine.py # JEE Advanced Physics formula solver
492
+ β”œβ”€β”€ chemistry_engine.py # JEE Advanced Chemistry solver
493
+ β”œβ”€β”€ reasoning_engine.py # Structured reasoning planner (64 problem types)
494
+ β”œβ”€β”€ llm_engine.py # Qwen2.5-1.5B-Instruct GGUF loader, JEE tuned prompts
495
+ β”œβ”€β”€ inference_engine.py # Propositional logic / deductive reasoning
496
+ β”œβ”€β”€ knowledge_engine.py # Local KB lookup (knowledge.txt)
497
+ β”œβ”€β”€ conversation_engine.py # Pattern-response engine (conversation.txt)
498
+ β”œβ”€β”€ memory.py # SQLite conversation history
499
+ β”œβ”€β”€ knowledge.txt # Local knowledge base paragraphs
500
+ β”œβ”€β”€ conversation.txt # PATTERN|||RESPONSE rule pairs
501
+ └── anveshai_memory.db # Auto-created SQLite DB (gitignored)
502
+ ```
503
+
504
+ ---
505
+
506
+ ## Technical Details
507
+
508
+ ### Model
509
+ - **Name:** Qwen2.5-1.5B-Instruct
510
+ - **Format:** GGUF (Q4_K_M quantisation, ~1 GB)
511
+ - **Runtime:** llama-cpp-python (CPU-only via llama.cpp)
512
+ - **Context window:** 16,384 tokens
513
+ - **Parameters:** 1.5B (3Γ— the original 0.5B for noticeably better reasoning)
514
+ - **Threads:** 4 CPU threads
515
+ - **System prompt:** JEE Advanced tutor β€” exam-focused, notation-correct, concise
516
+
517
+ ### Symbolic Engine
518
+ - **Library:** SymPy 1.x
519
+ - **Parsing:** `sympy.parsing.sympy_parser` with implicit multiplication and XOR-to-power transforms
520
+ - **Supported variables:** x, y, z, t, n, k, a, b, c, m, n, p, q, r, s
521
+ - **Special constants:** Ο€, e, i (imaginary), ∞
522
+
523
+ ### Chain-of-Thought Reasoning
524
+ - **Domain detection:** 15+ domain categories with keyword matching
525
+ - **Problem type classification:** 64 problem types via priority-ordered regex
526
+ - **Strategy library:** Pre-defined strategies for 64 problem types
527
+ - **Decomposition:** Problem-specific step generators for 50+ operation types
528
+ - **Confidence levels:** HIGH (deterministic result available) / MEDIUM / LOW
529
+ - **JEE-specific types:** SHM, rotational mechanics, modern physics, electrostatics, electromagnetism, chemical equilibrium, chemical kinetics, solid state, colligative properties, conic sections, 3D geometry, Bayes probability, binomial theorem, sequences/series, trig equations, inverse trig, maxima/minima
530
+
531
+ ### Response Labels
532
+
533
+ | Label | Meaning |
534
+ |-------|---------|
535
+ | `Math` | Instant arithmetic result |
536
+ | `AdvMath+CoT+LLM` | SymPy exact answer + CoT plan + LLM explanation |
537
+ | `AdvMath+CoT` | CoT-guided LLM fallback (SymPy failed) |
538
+ | `Physics+CoT+LLM` | Physics engine result + CoT plan + LLM explanation |
539
+ | `Chem+CoT+LLM` | Chemistry engine result + CoT plan + LLM explanation |
540
+ | `Knowledge` | Local KB answer |
541
+ | `LLM+CoT-KB` | KB miss β†’ reasoning-guided LLM |
542
+ | `Chat` | Conversation pattern match |
543
+ | `LLM+CoT` | Reasoning-guided LLM for open conversation |
544
+
545
+ ### Intent Routing
546
+
547
+ Benchmark routing accuracy on full 3,000-question dataset: **100%**
548
+
549
+ | Intent | Sample Triggers |
550
+ |--------|----------------|
551
+ | `physics` | spring constant, moment of inertia, photoelectric effect, de Broglie, electrostatics |
552
+ | `chemistry` | Kc, Kp, rate constant, half-life, BCC lattice, boiling point elevation |
553
+ | `advanced_math` | parabola, binomial theorem, general solution, shortest distance, Bayes theorem |
554
+ | `math` | plain numeric arithmetic expressions |
555
+ | `knowledge` | "what is", "explain", "define" β€” general knowledge |
556
+ | `logic` | "if…then…", "given that", logical deduction |
557
+ | `conversation` | greetings, small talk |
558
+ | `system` | `/help`, `/exit`, `/history` |