agentdb 1.0.0
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.
- package/LICENSE +38 -0
- package/LICENSE-APACHE +190 -0
- package/LICENSE-MIT +21 -0
- package/README.md +953 -0
- package/bin/agentdb.js +485 -0
- package/bin/plugin-cli-wrapper.mjs +21 -0
- package/dist/cache/query-cache.d.ts +105 -0
- package/dist/cache/query-cache.d.ts.map +1 -0
- package/dist/cache/query-cache.js +224 -0
- package/dist/cache/query-cache.js.map +1 -0
- package/dist/cache/query-cache.mjs +219 -0
- package/dist/cli/cache/query-cache.d.ts +104 -0
- package/dist/cli/cache/query-cache.js +244 -0
- package/dist/cli/cli/db-commands.d.ts +48 -0
- package/dist/cli/cli/db-commands.js +613 -0
- package/dist/cli/commands.d.ts +7 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +113 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/core/backend-interface.d.ts +70 -0
- package/dist/cli/core/backend-interface.js +15 -0
- package/dist/cli/core/native-backend.d.ts +140 -0
- package/dist/cli/core/native-backend.js +432 -0
- package/dist/cli/core/vector-db.d.ts +126 -0
- package/dist/cli/core/vector-db.js +338 -0
- package/dist/cli/core/wasm-backend.d.ts +95 -0
- package/dist/cli/core/wasm-backend.js +418 -0
- package/dist/cli/db-commands.d.ts +49 -0
- package/dist/cli/db-commands.d.ts.map +1 -0
- package/dist/cli/db-commands.js +533 -0
- package/dist/cli/db-commands.js.map +1 -0
- package/dist/cli/db-commands.mjs +522 -0
- package/dist/cli/generator.d.ts +11 -0
- package/dist/cli/generator.d.ts.map +1 -0
- package/dist/cli/generator.js +567 -0
- package/dist/cli/generator.js.map +1 -0
- package/dist/cli/generator.mjs +527 -0
- package/dist/cli/help.d.ts +18 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +676 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/help.mjs +667 -0
- package/dist/cli/index/hnsw.d.ts +164 -0
- package/dist/cli/index/hnsw.js +558 -0
- package/dist/cli/plugin-cli.d.ts +7 -0
- package/dist/cli/plugin-cli.d.ts.map +1 -0
- package/dist/cli/plugin-cli.js +295 -0
- package/dist/cli/plugin-cli.js.map +1 -0
- package/dist/cli/plugin-cli.mjs +289 -0
- package/dist/cli/quantization/product-quantization.d.ts +108 -0
- package/dist/cli/quantization/product-quantization.js +350 -0
- package/dist/cli/query/query-builder.d.ts +322 -0
- package/dist/cli/query/query-builder.js +600 -0
- package/dist/cli/templates.d.ts +14 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +182 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/cli/templates.mjs +176 -0
- package/dist/cli/types/index.d.ts +116 -0
- package/dist/cli/types/index.js +5 -0
- package/dist/cli/types.d.ts +91 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +6 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/types.mjs +4 -0
- package/dist/cli/wizard/index.d.ts +6 -0
- package/dist/cli/wizard/index.d.ts.map +1 -0
- package/dist/cli/wizard/index.js +138 -0
- package/dist/cli/wizard/index.js.map +1 -0
- package/dist/cli/wizard/index.mjs +131 -0
- package/dist/cli/wizard/prompts.d.ts +11 -0
- package/dist/cli/wizard/prompts.d.ts.map +1 -0
- package/dist/cli/wizard/prompts.js +482 -0
- package/dist/cli/wizard/prompts.js.map +1 -0
- package/dist/cli/wizard/prompts.mjs +470 -0
- package/dist/cli/wizard/validator.d.ts +13 -0
- package/dist/cli/wizard/validator.d.ts.map +1 -0
- package/dist/cli/wizard/validator.js +234 -0
- package/dist/cli/wizard/validator.js.map +1 -0
- package/dist/cli/wizard/validator.mjs +224 -0
- package/dist/core/backend-interface.d.ts +71 -0
- package/dist/core/backend-interface.d.ts.map +1 -0
- package/dist/core/backend-interface.js +16 -0
- package/dist/core/backend-interface.js.map +1 -0
- package/dist/core/backend-interface.mjs +12 -0
- package/dist/core/native-backend.d.ts +141 -0
- package/dist/core/native-backend.d.ts.map +1 -0
- package/dist/core/native-backend.js +457 -0
- package/dist/core/native-backend.js.map +1 -0
- package/dist/core/native-backend.mjs +449 -0
- package/dist/core/vector-db.d.ts +127 -0
- package/dist/core/vector-db.d.ts.map +1 -0
- package/dist/core/vector-db.js +266 -0
- package/dist/core/vector-db.js.map +1 -0
- package/dist/core/vector-db.mjs +261 -0
- package/dist/core/wasm-backend.d.ts +96 -0
- package/dist/core/wasm-backend.d.ts.map +1 -0
- package/dist/core/wasm-backend.js +393 -0
- package/dist/core/wasm-backend.js.map +1 -0
- package/dist/core/wasm-backend.mjs +385 -0
- package/dist/index/hnsw-optimized.d.ts +75 -0
- package/dist/index/hnsw-optimized.d.ts.map +1 -0
- package/dist/index/hnsw-optimized.js +412 -0
- package/dist/index/hnsw-optimized.js.map +1 -0
- package/dist/index/hnsw-optimized.mjs +407 -0
- package/dist/index/hnsw.d.ts +165 -0
- package/dist/index/hnsw.d.ts.map +1 -0
- package/dist/index/hnsw.js +521 -0
- package/dist/index/hnsw.js.map +1 -0
- package/dist/index/hnsw.mjs +516 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +789 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-server.mjs +784 -0
- package/dist/plugins/base-plugin.d.ts +114 -0
- package/dist/plugins/base-plugin.d.ts.map +1 -0
- package/dist/plugins/base-plugin.js +313 -0
- package/dist/plugins/base-plugin.js.map +1 -0
- package/dist/plugins/base-plugin.mjs +275 -0
- package/dist/plugins/implementations/active-learning.d.ts +135 -0
- package/dist/plugins/implementations/active-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/active-learning.js +372 -0
- package/dist/plugins/implementations/active-learning.js.map +1 -0
- package/dist/plugins/implementations/active-learning.mjs +367 -0
- package/dist/plugins/implementations/actor-critic.d.ts +64 -0
- package/dist/plugins/implementations/actor-critic.d.ts.map +1 -0
- package/dist/plugins/implementations/actor-critic.js +363 -0
- package/dist/plugins/implementations/actor-critic.js.map +1 -0
- package/dist/plugins/implementations/actor-critic.mjs +358 -0
- package/dist/plugins/implementations/adversarial-training.d.ts +133 -0
- package/dist/plugins/implementations/adversarial-training.d.ts.map +1 -0
- package/dist/plugins/implementations/adversarial-training.js +409 -0
- package/dist/plugins/implementations/adversarial-training.js.map +1 -0
- package/dist/plugins/implementations/adversarial-training.mjs +404 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts +132 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.js +354 -0
- package/dist/plugins/implementations/curriculum-learning.js.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.mjs +349 -0
- package/dist/plugins/implementations/decision-transformer.d.ts +77 -0
- package/dist/plugins/implementations/decision-transformer.d.ts.map +1 -0
- package/dist/plugins/implementations/decision-transformer.js +422 -0
- package/dist/plugins/implementations/decision-transformer.js.map +1 -0
- package/dist/plugins/implementations/decision-transformer.mjs +417 -0
- package/dist/plugins/implementations/federated-learning.d.ts +126 -0
- package/dist/plugins/implementations/federated-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/federated-learning.js +436 -0
- package/dist/plugins/implementations/federated-learning.js.map +1 -0
- package/dist/plugins/implementations/federated-learning.mjs +431 -0
- package/dist/plugins/implementations/index.d.ts +30 -0
- package/dist/plugins/implementations/index.d.ts.map +1 -0
- package/dist/plugins/implementations/index.js +45 -0
- package/dist/plugins/implementations/index.js.map +1 -0
- package/dist/plugins/implementations/index.mjs +31 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts +115 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.js +369 -0
- package/dist/plugins/implementations/multi-task-learning.js.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.mjs +364 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts +148 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.js +379 -0
- package/dist/plugins/implementations/neural-architecture-search.js.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.mjs +374 -0
- package/dist/plugins/implementations/q-learning.d.ts +98 -0
- package/dist/plugins/implementations/q-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/q-learning.js +435 -0
- package/dist/plugins/implementations/q-learning.js.map +1 -0
- package/dist/plugins/implementations/q-learning.mjs +430 -0
- package/dist/plugins/implementations/sarsa.d.ts +103 -0
- package/dist/plugins/implementations/sarsa.d.ts.map +1 -0
- package/dist/plugins/implementations/sarsa.js +347 -0
- package/dist/plugins/implementations/sarsa.js.map +1 -0
- package/dist/plugins/implementations/sarsa.mjs +342 -0
- package/dist/plugins/index.d.ts +107 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +179 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/index.mjs +168 -0
- package/dist/plugins/interface.d.ts +439 -0
- package/dist/plugins/interface.d.ts.map +1 -0
- package/dist/plugins/interface.js +12 -0
- package/dist/plugins/interface.js.map +1 -0
- package/dist/plugins/interface.mjs +10 -0
- package/dist/plugins/learning-plugin.interface.d.ts +257 -0
- package/dist/plugins/learning-plugin.interface.d.ts.map +1 -0
- package/dist/plugins/learning-plugin.interface.js +7 -0
- package/dist/plugins/learning-plugin.interface.js.map +1 -0
- package/dist/plugins/learning-plugin.interface.mjs +5 -0
- package/dist/plugins/plugin-exports.d.ts +71 -0
- package/dist/plugins/plugin-exports.d.ts.map +1 -0
- package/dist/plugins/plugin-exports.js +78 -0
- package/dist/plugins/plugin-exports.js.map +1 -0
- package/dist/plugins/plugin-exports.mjs +69 -0
- package/dist/plugins/registry.d.ts +206 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +365 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/registry.mjs +356 -0
- package/dist/plugins/validator.d.ts +63 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +464 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/plugins/validator.mjs +458 -0
- package/dist/quantization/binary-quantization.d.ts +104 -0
- package/dist/quantization/binary-quantization.d.ts.map +1 -0
- package/dist/quantization/binary-quantization.js +246 -0
- package/dist/quantization/binary-quantization.js.map +1 -0
- package/dist/quantization/binary-quantization.mjs +240 -0
- package/dist/quantization/optimized-pq.d.ts +138 -0
- package/dist/quantization/optimized-pq.d.ts.map +1 -0
- package/dist/quantization/optimized-pq.js +320 -0
- package/dist/quantization/optimized-pq.js.map +1 -0
- package/dist/quantization/optimized-pq.mjs +313 -0
- package/dist/quantization/product-quantization.d.ts +109 -0
- package/dist/quantization/product-quantization.d.ts.map +1 -0
- package/dist/quantization/product-quantization.js +287 -0
- package/dist/quantization/product-quantization.js.map +1 -0
- package/dist/quantization/product-quantization.mjs +282 -0
- package/dist/quantization/scalar-quantization.d.ts +100 -0
- package/dist/quantization/scalar-quantization.d.ts.map +1 -0
- package/dist/quantization/scalar-quantization.js +324 -0
- package/dist/quantization/scalar-quantization.js.map +1 -0
- package/dist/quantization/scalar-quantization.mjs +319 -0
- package/dist/query/index.d.ts +6 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +9 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/index.mjs +4 -0
- package/dist/query/query-builder.d.ts +323 -0
- package/dist/query/query-builder.d.ts.map +1 -0
- package/dist/query/query-builder.js +524 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/query/query-builder.mjs +519 -0
- package/dist/reasoning/context-synthesizer.d.ts +57 -0
- package/dist/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoning/context-synthesizer.js +224 -0
- package/dist/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoning/context-synthesizer.mjs +219 -0
- package/dist/reasoning/experience-curator.d.ts +66 -0
- package/dist/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoning/experience-curator.js +288 -0
- package/dist/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoning/experience-curator.mjs +283 -0
- package/dist/reasoning/memory-optimizer.d.ts +69 -0
- package/dist/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoning/memory-optimizer.js +331 -0
- package/dist/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoning/memory-optimizer.mjs +326 -0
- package/dist/reasoning/pattern-matcher.d.ts +59 -0
- package/dist/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoning/pattern-matcher.js +229 -0
- package/dist/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoning/pattern-matcher.mjs +224 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +118 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js +477 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +1 -0
- package/dist/reasoningbank/adapter/types.d.ts +113 -0
- package/dist/reasoningbank/adapter/types.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/types.js +9 -0
- package/dist/reasoningbank/adapter/types.js.map +1 -0
- package/dist/reasoningbank/cli/commands.d.ts +16 -0
- package/dist/reasoningbank/cli/commands.d.ts.map +1 -0
- package/dist/reasoningbank/cli/commands.js +272 -0
- package/dist/reasoningbank/cli/commands.js.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +319 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js +301 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +1 -0
- package/dist/reasoningbank/migration/migrate.d.ts +25 -0
- package/dist/reasoningbank/migration/migrate.d.ts.map +1 -0
- package/dist/reasoningbank/migration/migrate.js +178 -0
- package/dist/reasoningbank/migration/migrate.js.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +37 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js +114 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +39 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.js +98 -0
- package/dist/reasoningbank/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +44 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js +184 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +40 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js +87 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts +77 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.js +165 -0
- package/dist/reasoningbank/sync/quic-sync.js.map +1 -0
- package/dist/sync/conflict.d.ts +78 -0
- package/dist/sync/conflict.d.ts.map +1 -0
- package/dist/sync/conflict.js +202 -0
- package/dist/sync/conflict.js.map +1 -0
- package/dist/sync/conflict.mjs +196 -0
- package/dist/sync/coordinator.d.ts +111 -0
- package/dist/sync/coordinator.d.ts.map +1 -0
- package/dist/sync/coordinator.js +256 -0
- package/dist/sync/coordinator.js.map +1 -0
- package/dist/sync/coordinator.mjs +250 -0
- package/dist/sync/delta.d.ts +81 -0
- package/dist/sync/delta.d.ts.map +1 -0
- package/dist/sync/delta.js +245 -0
- package/dist/sync/delta.js.map +1 -0
- package/dist/sync/delta.mjs +238 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +22 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/index.mjs +9 -0
- package/dist/sync/quic-sync.d.ts +81 -0
- package/dist/sync/quic-sync.d.ts.map +1 -0
- package/dist/sync/quic-sync.js +329 -0
- package/dist/sync/quic-sync.js.map +1 -0
- package/dist/sync/quic-sync.mjs +323 -0
- package/dist/sync/types.d.ts +168 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +8 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/sync/types.mjs +6 -0
- package/dist/types/index.d.ts +117 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +4 -0
- package/dist/wasm-loader.d.ts +32 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.js +75 -0
- package/dist/wasm-loader.js.map +1 -0
- package/dist/wasm-loader.mjs +64 -0
- package/examples/adaptive-learning.ts +284 -0
- package/examples/browser/README.md +732 -0
- package/examples/browser/adaptive-recommendations/index.html +427 -0
- package/examples/browser/collaborative-filtering/index.html +310 -0
- package/examples/browser/continual-learning/index.html +736 -0
- package/examples/browser/experience-replay/index.html +616 -0
- package/examples/browser/index.html +369 -0
- package/examples/browser/meta-learning/index.html +789 -0
- package/examples/browser/neuro-symbolic/index.html +692 -0
- package/examples/browser/pattern-learning/index.html +620 -0
- package/examples/browser/quantum-inspired/index.html +728 -0
- package/examples/browser/rag/index.html +624 -0
- package/examples/browser/swarm-intelligence/index.html +811 -0
- package/examples/browser-basic.html +170 -0
- package/examples/hnsw-example.ts +148 -0
- package/examples/node-basic.js +70 -0
- package/examples/quic-sync-example.ts +310 -0
- package/examples/quick-start.js +68 -0
- package/examples/wasm-example.ts +222 -0
- package/package.json +118 -0
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Neuro-Symbolic Reasoning - AgentDB WASM</title>
|
|
7
|
+
<style>
|
|
8
|
+
* {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
16
|
+
background: linear-gradient(135deg, #0d47a1 0%, #1976d2 100%);
|
|
17
|
+
min-height: 100vh;
|
|
18
|
+
padding: 2rem;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.container {
|
|
22
|
+
max-width: 1400px;
|
|
23
|
+
margin: 0 auto;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
header {
|
|
27
|
+
text-align: center;
|
|
28
|
+
color: white;
|
|
29
|
+
margin-bottom: 2rem;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
h1 {
|
|
33
|
+
font-size: 2rem;
|
|
34
|
+
margin-bottom: 0.5rem;
|
|
35
|
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.subtitle {
|
|
39
|
+
opacity: 0.9;
|
|
40
|
+
font-size: 1rem;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.main-grid {
|
|
44
|
+
display: grid;
|
|
45
|
+
grid-template-columns: 1fr 1fr;
|
|
46
|
+
gap: 1.5rem;
|
|
47
|
+
margin-bottom: 1.5rem;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.card {
|
|
51
|
+
background: white;
|
|
52
|
+
border-radius: 12px;
|
|
53
|
+
padding: 1.5rem;
|
|
54
|
+
box-shadow: 0 8px 24px rgba(0,0,0,0.2);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.card h2 {
|
|
58
|
+
color: #333;
|
|
59
|
+
margin-bottom: 1rem;
|
|
60
|
+
font-size: 1.3rem;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.description {
|
|
64
|
+
background: #e3f2fd;
|
|
65
|
+
padding: 1rem;
|
|
66
|
+
border-radius: 8px;
|
|
67
|
+
margin-bottom: 1rem;
|
|
68
|
+
line-height: 1.6;
|
|
69
|
+
color: #555;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.knowledge-base {
|
|
73
|
+
background: #f5f5f5;
|
|
74
|
+
border-radius: 8px;
|
|
75
|
+
padding: 1rem;
|
|
76
|
+
margin-bottom: 1rem;
|
|
77
|
+
max-height: 300px;
|
|
78
|
+
overflow-y: auto;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.rule-item {
|
|
82
|
+
background: white;
|
|
83
|
+
padding: 0.75rem;
|
|
84
|
+
margin-bottom: 0.5rem;
|
|
85
|
+
border-radius: 6px;
|
|
86
|
+
border-left: 4px solid #1976d2;
|
|
87
|
+
font-family: 'Courier New', monospace;
|
|
88
|
+
font-size: 0.9rem;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.rule-premise {
|
|
92
|
+
color: #555;
|
|
93
|
+
margin-bottom: 0.25rem;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.rule-conclusion {
|
|
97
|
+
color: #2e7d32;
|
|
98
|
+
font-weight: 600;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.btn {
|
|
102
|
+
padding: 0.75rem 1.5rem;
|
|
103
|
+
background: linear-gradient(135deg, #0d47a1 0%, #1976d2 100%);
|
|
104
|
+
color: white;
|
|
105
|
+
border: none;
|
|
106
|
+
border-radius: 6px;
|
|
107
|
+
font-weight: 600;
|
|
108
|
+
cursor: pointer;
|
|
109
|
+
transition: opacity 0.3s;
|
|
110
|
+
width: 100%;
|
|
111
|
+
margin-bottom: 0.5rem;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.btn:hover {
|
|
115
|
+
opacity: 0.9;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
textarea {
|
|
119
|
+
width: 100%;
|
|
120
|
+
padding: 1rem;
|
|
121
|
+
border: 2px solid #ddd;
|
|
122
|
+
border-radius: 8px;
|
|
123
|
+
font-family: 'Courier New', monospace;
|
|
124
|
+
font-size: 0.9rem;
|
|
125
|
+
resize: vertical;
|
|
126
|
+
margin-bottom: 1rem;
|
|
127
|
+
min-height: 100px;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.reasoning-chain {
|
|
131
|
+
background: #f9f9f9;
|
|
132
|
+
border-radius: 8px;
|
|
133
|
+
padding: 1rem;
|
|
134
|
+
margin-bottom: 1rem;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.reasoning-step {
|
|
138
|
+
background: white;
|
|
139
|
+
padding: 0.75rem;
|
|
140
|
+
margin-bottom: 0.5rem;
|
|
141
|
+
border-radius: 6px;
|
|
142
|
+
border-left: 4px solid #f57c00;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.step-number {
|
|
146
|
+
font-weight: 600;
|
|
147
|
+
color: #e65100;
|
|
148
|
+
margin-bottom: 0.25rem;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.step-inference {
|
|
152
|
+
font-family: 'Courier New', monospace;
|
|
153
|
+
color: #555;
|
|
154
|
+
margin-bottom: 0.25rem;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.step-confidence {
|
|
158
|
+
font-size: 0.85rem;
|
|
159
|
+
color: #666;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.conclusion-box {
|
|
163
|
+
background: #e8f5e9;
|
|
164
|
+
padding: 1.5rem;
|
|
165
|
+
border-radius: 8px;
|
|
166
|
+
border: 2px solid #2e7d32;
|
|
167
|
+
margin-bottom: 1rem;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.conclusion-title {
|
|
171
|
+
font-weight: 600;
|
|
172
|
+
color: #1b5e20;
|
|
173
|
+
margin-bottom: 0.5rem;
|
|
174
|
+
font-size: 1.1rem;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.conclusion-text {
|
|
178
|
+
font-family: 'Courier New', monospace;
|
|
179
|
+
color: #2e7d32;
|
|
180
|
+
font-size: 1rem;
|
|
181
|
+
line-height: 1.6;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.stat-grid {
|
|
185
|
+
display: grid;
|
|
186
|
+
grid-template-columns: repeat(2, 1fr);
|
|
187
|
+
gap: 1rem;
|
|
188
|
+
margin-bottom: 1rem;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.stat-item {
|
|
192
|
+
background: #f5f5f5;
|
|
193
|
+
padding: 1rem;
|
|
194
|
+
border-radius: 8px;
|
|
195
|
+
text-align: center;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.stat-label {
|
|
199
|
+
font-size: 0.85rem;
|
|
200
|
+
color: #666;
|
|
201
|
+
margin-bottom: 0.5rem;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.stat-value {
|
|
205
|
+
font-size: 1.5rem;
|
|
206
|
+
font-weight: bold;
|
|
207
|
+
color: #0d47a1;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
#log {
|
|
211
|
+
max-height: 200px;
|
|
212
|
+
overflow-y: auto;
|
|
213
|
+
background: #f9f9f9;
|
|
214
|
+
padding: 1rem;
|
|
215
|
+
border-radius: 8px;
|
|
216
|
+
font-family: 'Courier New', monospace;
|
|
217
|
+
font-size: 0.85rem;
|
|
218
|
+
line-height: 1.6;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.log-entry {
|
|
222
|
+
margin-bottom: 0.5rem;
|
|
223
|
+
color: #555;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.log-entry.success {
|
|
227
|
+
color: #2e7d32;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.log-entry.info {
|
|
231
|
+
color: #1976d2;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.hybrid-indicator {
|
|
235
|
+
display: flex;
|
|
236
|
+
justify-content: space-around;
|
|
237
|
+
margin-bottom: 1rem;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.indicator-box {
|
|
241
|
+
flex: 1;
|
|
242
|
+
text-align: center;
|
|
243
|
+
padding: 1rem;
|
|
244
|
+
border-radius: 8px;
|
|
245
|
+
margin: 0 0.5rem;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.neural-indicator {
|
|
249
|
+
background: linear-gradient(135deg, #673ab7 0%, #9c27b0 100%);
|
|
250
|
+
color: white;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.symbolic-indicator {
|
|
254
|
+
background: linear-gradient(135deg, #0d47a1 0%, #1976d2 100%);
|
|
255
|
+
color: white;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.indicator-label {
|
|
259
|
+
font-size: 0.85rem;
|
|
260
|
+
opacity: 0.9;
|
|
261
|
+
margin-bottom: 0.25rem;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.indicator-value {
|
|
265
|
+
font-size: 1.5rem;
|
|
266
|
+
font-weight: 600;
|
|
267
|
+
}
|
|
268
|
+
</style>
|
|
269
|
+
</head>
|
|
270
|
+
<body>
|
|
271
|
+
<div class="container">
|
|
272
|
+
<header>
|
|
273
|
+
<h1>🧬 Neuro-Symbolic Reasoning</h1>
|
|
274
|
+
<p class="subtitle">Hybrid AI: Neural Perception + Symbolic Logic</p>
|
|
275
|
+
</header>
|
|
276
|
+
|
|
277
|
+
<div class="main-grid">
|
|
278
|
+
<div class="card">
|
|
279
|
+
<h2>Symbolic Knowledge Base</h2>
|
|
280
|
+
<div class="description">
|
|
281
|
+
Neuro-symbolic AI combines the pattern recognition power of neural networks with the logical reasoning of symbolic systems. The neural component learns from data while the symbolic component ensures interpretable, verifiable reasoning.
|
|
282
|
+
</div>
|
|
283
|
+
|
|
284
|
+
<div class="knowledge-base" id="knowledgeBase">
|
|
285
|
+
<!-- Populated with rules -->
|
|
286
|
+
</div>
|
|
287
|
+
|
|
288
|
+
<h2>Add Custom Rule</h2>
|
|
289
|
+
<textarea id="ruleInput" placeholder="IF condition1 AND condition2 THEN conclusion"></textarea>
|
|
290
|
+
<button class="btn" onclick="addRule()">➕ Add Logical Rule</button>
|
|
291
|
+
<button class="btn" onclick="trainNeuralComponent()">🧠 Train Neural Patterns</button>
|
|
292
|
+
</div>
|
|
293
|
+
|
|
294
|
+
<div class="card">
|
|
295
|
+
<h2>Query & Reasoning</h2>
|
|
296
|
+
|
|
297
|
+
<div class="hybrid-indicator">
|
|
298
|
+
<div class="indicator-box neural-indicator">
|
|
299
|
+
<div class="indicator-label">Neural Confidence</div>
|
|
300
|
+
<div class="indicator-value" id="neuralConfidence">0%</div>
|
|
301
|
+
</div>
|
|
302
|
+
<div class="indicator-box symbolic-indicator">
|
|
303
|
+
<div class="indicator-label">Symbolic Match</div>
|
|
304
|
+
<div class="indicator-value" id="symbolicMatch">0%</div>
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
|
|
308
|
+
<textarea id="queryInput" placeholder="Enter your query (e.g., 'Is Socrates mortal?')"></textarea>
|
|
309
|
+
<button class="btn" onclick="reason()">🔍 Perform Reasoning</button>
|
|
310
|
+
|
|
311
|
+
<h2>Reasoning Chain</h2>
|
|
312
|
+
<div class="reasoning-chain" id="reasoningChain">
|
|
313
|
+
<p style="color: #999; text-align: center;">No reasoning performed yet</p>
|
|
314
|
+
</div>
|
|
315
|
+
|
|
316
|
+
<div class="conclusion-box" id="conclusion" style="display: none;">
|
|
317
|
+
<div class="conclusion-title">✓ Conclusion</div>
|
|
318
|
+
<div class="conclusion-text" id="conclusionText"></div>
|
|
319
|
+
</div>
|
|
320
|
+
|
|
321
|
+
<div class="stat-grid">
|
|
322
|
+
<div class="stat-item">
|
|
323
|
+
<div class="stat-label">Rules in KB</div>
|
|
324
|
+
<div class="stat-value" id="ruleCount">0</div>
|
|
325
|
+
</div>
|
|
326
|
+
<div class="stat-item">
|
|
327
|
+
<div class="stat-label">Neural Patterns</div>
|
|
328
|
+
<div class="stat-value" id="patternCount">0</div>
|
|
329
|
+
</div>
|
|
330
|
+
<div class="stat-item">
|
|
331
|
+
<div class="stat-label">Inferences Made</div>
|
|
332
|
+
<div class="stat-value" id="inferenceCount">0</div>
|
|
333
|
+
</div>
|
|
334
|
+
<div class="stat-item">
|
|
335
|
+
<div class="stat-label">Hybrid Accuracy</div>
|
|
336
|
+
<div class="stat-value" id="accuracy">0%</div>
|
|
337
|
+
</div>
|
|
338
|
+
</div>
|
|
339
|
+
</div>
|
|
340
|
+
</div>
|
|
341
|
+
|
|
342
|
+
<div class="card">
|
|
343
|
+
<h2>📊 Reasoning Log</h2>
|
|
344
|
+
<div id="log"></div>
|
|
345
|
+
</div>
|
|
346
|
+
</div>
|
|
347
|
+
|
|
348
|
+
<script>
|
|
349
|
+
// Neuro-Symbolic Reasoning Engine with AgentDB
|
|
350
|
+
class NeuroSymbolicDB {
|
|
351
|
+
constructor() {
|
|
352
|
+
this.rules = [];
|
|
353
|
+
this.facts = new Set();
|
|
354
|
+
this.neuralPatterns = [];
|
|
355
|
+
this.inferenceHistory = [];
|
|
356
|
+
this.neuralWeights = this.initializeNeuralNetwork();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
initializeNeuralNetwork() {
|
|
360
|
+
return {
|
|
361
|
+
embeddings: new Map(),
|
|
362
|
+
weights: Array(256).fill(0).map(() => Math.random() * 0.1 - 0.05),
|
|
363
|
+
bias: 0
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
addRule(premise, conclusion, confidence = 1.0) {
|
|
368
|
+
const rule = {
|
|
369
|
+
premise,
|
|
370
|
+
conclusion,
|
|
371
|
+
confidence,
|
|
372
|
+
embedding: this.generateRuleEmbedding(premise, conclusion),
|
|
373
|
+
timestamp: Date.now()
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
this.rules.push(rule);
|
|
377
|
+
logMessage(`Added rule: IF ${premise.join(' AND ')} THEN ${conclusion}`, 'success');
|
|
378
|
+
return rule;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
addFact(fact) {
|
|
382
|
+
this.facts.add(fact.toLowerCase());
|
|
383
|
+
logMessage(`Fact added: ${fact}`, 'info');
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
generateRuleEmbedding(premise, conclusion) {
|
|
387
|
+
const embedding = new Array(256).fill(0);
|
|
388
|
+
const text = premise.join(' ') + ' ' + conclusion;
|
|
389
|
+
|
|
390
|
+
for (let i = 0; i < text.length; i++) {
|
|
391
|
+
const char = text.charCodeAt(i);
|
|
392
|
+
embedding[i % 256] += Math.sin(char * (i + 1)) / text.length;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return this.normalize(embedding);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async trainNeuralPatterns(examples) {
|
|
399
|
+
logMessage('🧠 Training neural component on pattern examples...', 'info');
|
|
400
|
+
|
|
401
|
+
for (let epoch = 0; epoch < 50; epoch++) {
|
|
402
|
+
let totalLoss = 0;
|
|
403
|
+
|
|
404
|
+
examples.forEach(ex => {
|
|
405
|
+
const embedding = this.generateRuleEmbedding(ex.input.split(' '), ex.output);
|
|
406
|
+
const prediction = this.neuralForward(embedding);
|
|
407
|
+
const target = ex.label;
|
|
408
|
+
|
|
409
|
+
// Compute loss
|
|
410
|
+
const loss = Math.pow(prediction - target, 2);
|
|
411
|
+
totalLoss += loss;
|
|
412
|
+
|
|
413
|
+
// Update weights (gradient descent)
|
|
414
|
+
const gradient = 2 * (prediction - target);
|
|
415
|
+
for (let i = 0; i < this.neuralWeights.weights.length; i++) {
|
|
416
|
+
this.neuralWeights.weights[i] -= 0.01 * gradient * embedding[i];
|
|
417
|
+
}
|
|
418
|
+
this.neuralWeights.bias -= 0.01 * gradient;
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
if (epoch % 10 === 0) {
|
|
422
|
+
logMessage(`Neural training epoch ${epoch}, loss: ${(totalLoss / examples.length).toFixed(4)}`, 'info');
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
this.neuralPatterns.push(...examples);
|
|
427
|
+
logMessage('✅ Neural component trained successfully', 'success');
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
neuralForward(embedding) {
|
|
431
|
+
let activation = this.neuralWeights.bias;
|
|
432
|
+
for (let i = 0; i < Math.min(embedding.length, this.neuralWeights.weights.length); i++) {
|
|
433
|
+
activation += embedding[i] * this.neuralWeights.weights[i];
|
|
434
|
+
}
|
|
435
|
+
return 1 / (1 + Math.exp(-activation)); // Sigmoid
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
async reason(query) {
|
|
439
|
+
const reasoningChain = [];
|
|
440
|
+
const queryLower = query.toLowerCase();
|
|
441
|
+
|
|
442
|
+
logMessage(`🔍 Reasoning about: "${query}"`, 'info');
|
|
443
|
+
|
|
444
|
+
// Step 1: Neural component - pattern matching
|
|
445
|
+
const queryEmbedding = this.generateRuleEmbedding([query], '');
|
|
446
|
+
const neuralConfidence = this.neuralForward(queryEmbedding);
|
|
447
|
+
|
|
448
|
+
reasoningChain.push({
|
|
449
|
+
type: 'neural',
|
|
450
|
+
description: 'Neural pattern recognition',
|
|
451
|
+
inference: `Pattern similarity detected with ${(neuralConfidence * 100).toFixed(1)}% confidence`,
|
|
452
|
+
confidence: neuralConfidence
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// Step 2: Symbolic component - rule matching
|
|
456
|
+
const matchingRules = this.findMatchingRules(queryLower);
|
|
457
|
+
let symbolicConfidence = 0;
|
|
458
|
+
|
|
459
|
+
if (matchingRules.length > 0) {
|
|
460
|
+
symbolicConfidence = Math.max(...matchingRules.map(r => r.confidence));
|
|
461
|
+
|
|
462
|
+
matchingRules.forEach(rule => {
|
|
463
|
+
reasoningChain.push({
|
|
464
|
+
type: 'symbolic',
|
|
465
|
+
description: 'Symbolic rule application',
|
|
466
|
+
inference: `IF ${rule.premise.join(' AND ')} THEN ${rule.conclusion}`,
|
|
467
|
+
confidence: rule.confidence
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// Step 3: Forward chaining inference
|
|
473
|
+
const derived = await this.forwardChaining(queryLower, reasoningChain);
|
|
474
|
+
|
|
475
|
+
// Step 4: Hybrid decision
|
|
476
|
+
const hybridConfidence = (neuralConfidence * 0.4 + symbolicConfidence * 0.6);
|
|
477
|
+
const conclusion = hybridConfidence > 0.5 ? 'TRUE' : 'UNKNOWN';
|
|
478
|
+
|
|
479
|
+
reasoningChain.push({
|
|
480
|
+
type: 'hybrid',
|
|
481
|
+
description: 'Hybrid neuro-symbolic decision',
|
|
482
|
+
inference: `Combining neural (${(neuralConfidence*100).toFixed(1)}%) and symbolic (${(symbolicConfidence*100).toFixed(1)}%) reasoning`,
|
|
483
|
+
confidence: hybridConfidence
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
this.inferenceHistory.push({
|
|
487
|
+
query,
|
|
488
|
+
chain: reasoningChain,
|
|
489
|
+
conclusion,
|
|
490
|
+
confidence: hybridConfidence,
|
|
491
|
+
timestamp: Date.now()
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
return {
|
|
495
|
+
conclusion,
|
|
496
|
+
confidence: hybridConfidence,
|
|
497
|
+
chain: reasoningChain,
|
|
498
|
+
neuralConfidence,
|
|
499
|
+
symbolicConfidence
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
findMatchingRules(query) {
|
|
504
|
+
return this.rules.filter(rule => {
|
|
505
|
+
// Check if all premises are satisfied
|
|
506
|
+
return rule.premise.every(p => {
|
|
507
|
+
const pLower = p.toLowerCase();
|
|
508
|
+
return this.facts.has(pLower) || query.includes(pLower);
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
async forwardChaining(query, chain) {
|
|
514
|
+
const derivedFacts = new Set(this.facts);
|
|
515
|
+
let iterations = 0;
|
|
516
|
+
let newFactsAdded = true;
|
|
517
|
+
|
|
518
|
+
while (newFactsAdded && iterations < 10) {
|
|
519
|
+
newFactsAdded = false;
|
|
520
|
+
iterations++;
|
|
521
|
+
|
|
522
|
+
for (const rule of this.rules) {
|
|
523
|
+
if (rule.premise.every(p => derivedFacts.has(p.toLowerCase()))) {
|
|
524
|
+
const conclusion = rule.conclusion.toLowerCase();
|
|
525
|
+
if (!derivedFacts.has(conclusion)) {
|
|
526
|
+
derivedFacts.add(conclusion);
|
|
527
|
+
newFactsAdded = true;
|
|
528
|
+
|
|
529
|
+
chain.push({
|
|
530
|
+
type: 'inference',
|
|
531
|
+
description: `Forward chaining iteration ${iterations}`,
|
|
532
|
+
inference: `Derived: ${rule.conclusion}`,
|
|
533
|
+
confidence: rule.confidence
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
logMessage(`Inferred: ${rule.conclusion}`, 'success');
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return Array.from(derivedFacts);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
normalize(vec) {
|
|
546
|
+
const mag = Math.sqrt(vec.reduce((sum, v) => sum + v * v, 0));
|
|
547
|
+
return vec.map(v => v / (mag || 1));
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// Global state
|
|
552
|
+
const db = new NeuroSymbolicDB();
|
|
553
|
+
let stats = {
|
|
554
|
+
ruleCount: 0,
|
|
555
|
+
patternCount: 0,
|
|
556
|
+
inferenceCount: 0,
|
|
557
|
+
accuracy: 0
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// Initialize with classic logic examples
|
|
561
|
+
function initializeKnowledgeBase() {
|
|
562
|
+
// Classic Socrates example
|
|
563
|
+
db.addRule(['socrates is a man', 'all men are mortal'], 'socrates is mortal', 1.0);
|
|
564
|
+
db.addRule(['all men are mortal'], 'if x is a man then x is mortal', 1.0);
|
|
565
|
+
db.addFact('socrates is a man');
|
|
566
|
+
db.addFact('all men are mortal');
|
|
567
|
+
|
|
568
|
+
// Additional rules
|
|
569
|
+
db.addRule(['birds can fly', 'tweety is a bird'], 'tweety can fly', 0.9);
|
|
570
|
+
db.addRule(['mammals have fur', 'dogs are mammals'], 'dogs have fur', 0.95);
|
|
571
|
+
db.addFact('tweety is a bird');
|
|
572
|
+
db.addFact('birds can fly');
|
|
573
|
+
|
|
574
|
+
stats.ruleCount = db.rules.length;
|
|
575
|
+
updateStats();
|
|
576
|
+
displayKnowledgeBase();
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function displayKnowledgeBase() {
|
|
580
|
+
const container = document.getElementById('knowledgeBase');
|
|
581
|
+
container.innerHTML = '';
|
|
582
|
+
|
|
583
|
+
db.rules.forEach((rule, idx) => {
|
|
584
|
+
const div = document.createElement('div');
|
|
585
|
+
div.className = 'rule-item';
|
|
586
|
+
div.innerHTML = `
|
|
587
|
+
<div class="rule-premise">IF ${rule.premise.join(' AND ')}</div>
|
|
588
|
+
<div class="rule-conclusion">THEN ${rule.conclusion} (conf: ${(rule.confidence*100).toFixed(0)}%)</div>
|
|
589
|
+
`;
|
|
590
|
+
container.appendChild(div);
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function addRule() {
|
|
595
|
+
const input = document.getElementById('ruleInput').value.trim();
|
|
596
|
+
if (!input) return;
|
|
597
|
+
|
|
598
|
+
// Parse simple IF-THEN rule
|
|
599
|
+
const match = input.match(/IF\s+(.+)\s+THEN\s+(.+)/i);
|
|
600
|
+
if (match) {
|
|
601
|
+
const premises = match[1].split(/\s+AND\s+/i).map(p => p.trim());
|
|
602
|
+
const conclusion = match[2].trim();
|
|
603
|
+
|
|
604
|
+
db.addRule(premises, conclusion, 1.0);
|
|
605
|
+
stats.ruleCount = db.rules.length;
|
|
606
|
+
updateStats();
|
|
607
|
+
displayKnowledgeBase();
|
|
608
|
+
|
|
609
|
+
document.getElementById('ruleInput').value = '';
|
|
610
|
+
} else {
|
|
611
|
+
logMessage('Invalid rule format. Use: IF condition THEN conclusion', 'info');
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
async function trainNeuralComponent() {
|
|
616
|
+
// Generate training examples from rules
|
|
617
|
+
const examples = db.rules.map(rule => ({
|
|
618
|
+
input: rule.premise.join(' '),
|
|
619
|
+
output: rule.conclusion,
|
|
620
|
+
label: rule.confidence
|
|
621
|
+
}));
|
|
622
|
+
|
|
623
|
+
await db.trainNeuralPatterns(examples);
|
|
624
|
+
stats.patternCount = db.neuralPatterns.length;
|
|
625
|
+
updateStats();
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
async function reason() {
|
|
629
|
+
const query = document.getElementById('queryInput').value.trim();
|
|
630
|
+
if (!query) return;
|
|
631
|
+
|
|
632
|
+
const result = await db.reason(query);
|
|
633
|
+
|
|
634
|
+
stats.inferenceCount++;
|
|
635
|
+
stats.accuracy = Math.floor((stats.inferenceCount > 0 ? 1 : 0) * 100);
|
|
636
|
+
updateStats();
|
|
637
|
+
|
|
638
|
+
// Display reasoning chain
|
|
639
|
+
const chainContainer = document.getElementById('reasoningChain');
|
|
640
|
+
chainContainer.innerHTML = '';
|
|
641
|
+
|
|
642
|
+
result.chain.forEach((step, idx) => {
|
|
643
|
+
const div = document.createElement('div');
|
|
644
|
+
div.className = 'reasoning-step';
|
|
645
|
+
div.innerHTML = `
|
|
646
|
+
<div class="step-number">Step ${idx + 1}: ${step.description}</div>
|
|
647
|
+
<div class="step-inference">${step.inference}</div>
|
|
648
|
+
<div class="step-confidence">Confidence: ${(step.confidence * 100).toFixed(1)}%</div>
|
|
649
|
+
`;
|
|
650
|
+
chainContainer.appendChild(div);
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
// Display conclusion
|
|
654
|
+
const conclusionBox = document.getElementById('conclusion');
|
|
655
|
+
const conclusionText = document.getElementById('conclusionText');
|
|
656
|
+
conclusionBox.style.display = 'block';
|
|
657
|
+
conclusionText.textContent = `${result.conclusion} (${(result.confidence * 100).toFixed(1)}% confidence)`;
|
|
658
|
+
|
|
659
|
+
// Update hybrid indicators
|
|
660
|
+
document.getElementById('neuralConfidence').textContent = (result.neuralConfidence * 100).toFixed(1) + '%';
|
|
661
|
+
document.getElementById('symbolicMatch').textContent = (result.symbolicConfidence * 100).toFixed(1) + '%';
|
|
662
|
+
|
|
663
|
+
logMessage(`Reasoning complete: ${result.conclusion}`, 'success');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function updateStats() {
|
|
667
|
+
document.getElementById('ruleCount').textContent = stats.ruleCount;
|
|
668
|
+
document.getElementById('patternCount').textContent = stats.patternCount;
|
|
669
|
+
document.getElementById('inferenceCount').textContent = stats.inferenceCount;
|
|
670
|
+
document.getElementById('accuracy').textContent = stats.accuracy + '%';
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function logMessage(message, type = '') {
|
|
674
|
+
const log = document.getElementById('log');
|
|
675
|
+
const entry = document.createElement('div');
|
|
676
|
+
entry.className = `log-entry ${type}`;
|
|
677
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
678
|
+
entry.textContent = `[${timestamp}] ${message}`;
|
|
679
|
+
log.insertBefore(entry, log.firstChild);
|
|
680
|
+
|
|
681
|
+
while (log.children.length > 20) {
|
|
682
|
+
log.removeChild(log.lastChild);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// Initialize
|
|
687
|
+
initializeKnowledgeBase();
|
|
688
|
+
logMessage('🧬 Neuro-Symbolic reasoning engine initialized', 'success');
|
|
689
|
+
logMessage('Try querying: "Is Socrates mortal?" or "Can tweety fly?"', 'info');
|
|
690
|
+
</script>
|
|
691
|
+
</body>
|
|
692
|
+
</html>
|