File size: 71,427 Bytes
3f9e2e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 |
# NullAI ใใญใธใงใฏใๅฎๅ
จ็่งฃใฌใคใ
**ๆ็ตๆดๆฐ**: 2025-12-02
**ๅฏพ่ฑก่ชญ่
**: ใใฎใใญใธใงใฏใใๅผใ็ถใๅ
จใฆใฎ้็บ่
**็ฎ็**: ใใญใธใงใฏใใฎๅ
จไฝๅใๅฎๅ
จใซ็่งฃใใ่จญ่จๆๆณใๆญฃใใ็ถๆฟใใ
---
## ๐ ็ฎๆฌก
1. [ใใญใธใงใฏใๆฆ่ฆ](#ใใญใธใงใฏใๆฆ่ฆ)
2. [4ใคใฎๆ ธๅฟๆๆณ๏ผใใ ใใใใคใณใ๏ผ](#4ใคใฎๆ ธๅฟๆๆณใใ ใใใใคใณใ)
3. [ใทในใใ ใขใผใญใใฏใใฃๅ
จไฝๅณ](#ใทในใใ ใขใผใญใใฏใใฃๅ
จไฝๅณ)
4. [ๅใทในใใ ใฎ่ฉณ็ดฐ่งฃ่ชฌ](#ๅใทในใใ ใฎ่ฉณ็ดฐ่งฃ่ชฌ)
5. [ใใผใฟใใญใผๅฎๅ
จๅณ่งฃ](#ใใผใฟใใญใผๅฎๅ
จๅณ่งฃ)
6. [ๆ่กในใฟใใฏ่ฉณ็ดฐ](#ๆ่กในใฟใใฏ่ฉณ็ดฐ)
7. [ใใใใ่ชค่งฃใจๆณจๆ็น](#ใใใใ่ชค่งฃใจๆณจๆ็น)
8. [่จญ่จๅคๆญใฎ็็ฑ](#่จญ่จๅคๆญใฎ็็ฑ)
9. [ๆกๅผตๆใฎ่ๆ
ฎไบ้
](#ๆกๅผตๆใฎ่ๆ
ฎไบ้
)
---
## ใใญใธใงใฏใๆฆ่ฆ
### NullAIใจใฏไฝใ
**NullAI**ใฏใ**่ชๅทฑ้ฒๅๅๅคใใกใคใณ็ฅ่ญๆจ่ซใจใณใธใณ**ใงใใ
#### ๆ ธๅฟ็ใชๅใใจ็ญใ
**Q: ไฝใ่งฃๆฑบใใใใจใใฆใใใฎใ๏ผ**
A: ใAIใฎใใซใทใใผใทใงใณ๏ผๅนป่ฆ๏ผใใจใๅฐๅใขใใซใฎๆง่ฝไธ่ถณใใฎไธกๆนใๅๆใซ่งฃๆฑบ
**Q: ใฉใใใฃใฆ่งฃๆฑบใใใฎใ๏ผ**
A:
1. **DBๅชๅ
ๆจ่ซ๏ผRAG๏ผ** โ ใใซใทใใผใทใงใณๅๆธ
2. **ๅธซๅ โๅผๅญใฎใใกใคใณใใฅใผใใณใฐ** โ ๅฐๅใขใใซใฎๆง่ฝๅไธ
3. **ๆจนๆจๅ็ฉบ้่จๆถ** โ ็ฅ่ญใฎๆๅณ็ๆด็ใจ้ซ้ๆค็ดข
4. **่ชๅทฑๆกๅ
ใตใคใฏใซ** โ ็ฅ่ญใใผในใฎ่ชๅๆ้ท
**Q: ไปใฎRAGใทในใใ ใจใฎ้ใใฏ๏ผ**
A:
- โ ๆฎ้ใฎRAG: ใใฏใใซDBใงๆค็ดขใใใ ใ
- โ
NullAI: **6ๆฌกๅ
็ฉบ้ๅบงๆจ**ใง็ฅ่ญใ้
็ฝฎใใๆๅณ็ใช่ฟๅๆค็ดขใๅฏ่ฝ
**Q: ไปใฎใใกใคใณใใฅใผใใณใฐใทในใใ ใจใฎ้ใใฏ๏ผ**
A:
- โ ๆฎ้ใฎFT: ไบบ้ใ่จ็ทดใใผใฟใๆๅไฝๆ
- โ
NullAI: **ๅธซๅ AIใ่ชๅ็ใซ่จ็ทดใใผใฟใ็ๆ** โ ๅผๅญใๅญฆ็ฟ โ ๅผๅญใๅธซๅ ใซๆๆ ผ โ ็ก้ใตใคใฏใซ
### ใใญใธใงใฏใๅใฎ็ฑๆฅ
**Null** = ใผใญ๏ผใใซใทใใผใทใงใณ๏ผ
**AI** = Artificial Intelligence
โ **ใผใญใปใใซใทใใผใทใงใณใ็ฎๆใAI**
---
## 4ใคใฎๆ ธๅฟๆๆณ๏ผใใ ใใใใคใณใ๏ผ
### 1๏ธโฃ ๅๆจใทในใใ ๏ผFallen Tree System๏ผ
#### ๆฏๅฉใฎๆๅณ
ๆฃฎใงๅคงๆจ๏ผ่ใใๆจ๏ผใๅใใใจใใใฎ้คๅใงๆฐใใ่ฅๆจใ่ฒใคใNullAIใงใฏ๏ผ
- ๐ฒ **ๅคงๆจ๏ผๅธซๅ ใขใใซ๏ผ**: ้ซๆง่ฝใ ใ้ใAI๏ผไพ: DeepSeek R1 32B๏ผ
- ๐ฑ **่ฅๆจ๏ผๅผๅญใขใใซ๏ผ**: ๆๅใฏ็ฉบใฃใฝใ ใ่ปฝ้ใชAI๏ผไพ: Phi-2 2.7B๏ผ
- ๐ **้คๅ๏ผ่จ็ทดใใผใฟ๏ผ**: ๅธซๅ ใฎ้ซๅ่ณชใชๅบๅ๏ผAlpacaๅฝขๅผJSONL๏ผ
#### ใทในใใ ใฎๆตใ
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Phase 1: ๅธซๅ ใฎ็ตฑๆฒปๆไปฃ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ๅธซๅ ๏ผDeepSeek R1๏ผใๆจ่ซใๆ
ๅฝ โ
โ โ โ
โ ้ซๅ่ณชใชๅบๅ๏ผconfidence >= 0.8๏ผใ่ชๅไฟๅญ โ
โ โ โ
โ training_data/master_outputs/*.jsonl โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Phase 2: ใใกใคใณใใฅใผใใณใฐ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ่จ็ทดใใผใฟใไฝฟใฃใฆๅผๅญ๏ผPhi-2๏ผใ่จ็ทด โ
โ โ โ
โ ๅผๅญใฎๆง่ฝใๅไธ๏ผๅธซๅ ใฎ็ฅ่ญใๅธๅ๏ผ โ
โ โ โ
โ training_data/checkpoints/apprentice_*/ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Phase 3: ไธไปฃไบคไปฃ๏ผๅๆจ๏ผ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ๅผๅญใๅๅๆ้ท โ ๅธซๅ ใซๆๆ ผ โ
โ โ โ
โ ๆงๅธซๅ ๏ผDeepSeek๏ผใฏๅผ้๏ผใงใ็นๅฅใชๅฝนๅฒใใ๏ผ โ
โ โ โ
โ ๆฐใใ็ฉบใฎๅผๅญใ็ๆ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
ใตใคใฏใซ็นฐใ่ฟใ
```
#### ้่ฆใช่จญ่จๅคๆญ
**Q: ใชใๅธซๅ ใๅฎๅ
จใซๅ้คใใชใใฎใ๏ผ**
A: ๅผ้ใใๅธซๅ ๏ผDeepSeek๏ผใฏใ**ๆฐธไน
็ๆๅฐ่
**ใใจใใฆๆฎใ
- DBๆกๅ
ๆใฎใใญใณใใ็ๆ
- ๆฐใใใใกใคใณใฎๅๆ็ฅ่ญ็ๆ
- ๅ่ณชใใงใใฏ
**Q: ๅผๅญใฏใใคๅธซๅ ใซใชใใใฎใ๏ผ**
A:
- ใใกใคใณใใฅใผใใณใฐๅฎไบๅพใๆๅใงๆๆ ผ
- ๅฐๆฅ็ใซใฏ่ชๅ่ฉไพกใงๆๆ ผๅคๅฎ๏ผๆชๅฎ่ฃ
๏ผ
**Q: ่คๆฐใฎๅผๅญใๅๆใซ่จ็ทดใงใใใฎใ๏ผ**
A: ใงใใใใใกใคใณๅฅใซ็ฐใชใๅผๅญใ่จ็ทดๅฏ่ฝ
- ๅป็ใใกใคใณๅผๅญ
- ๆณๅพใใกใคใณๅผๅญ
- ไธ่ฌ็ฅ่ญๅผๅญ
### 2๏ธโฃ DBๅ้ขๆง้ ๏ผDatabase Separation Structure๏ผ
#### ่จญ่จๆๆณ
```
่ณชๅใๆฅใๆใฎๅคๆญใใญใผ๏ผ
่ณชๅ โ ใพใ็ฅ่ญDBใๆค็ดข
โโ ่ฆใคใใฃใ โ DB็ฅ่ญใไฝฟใฃใฆๆจ่ซ๏ผRAG๏ผโ
ไฟก้ ผๆง้ซ
โโ ่ฆใคใใใชใ โ AIๅ
้จ็ฅ่ญใงๆจ่ซ โ ๏ธ ใใซใทใใผใทใงใณใชในใฏ
โ
ใใฎๅบๅใDBใซไฟๅญ๏ผ่ชๅทฑๆกๅ
๏ผ
```
#### DBๅชๅ
ใฎ็็ฑ
| ็ฅ่ญใฝใผใน | ไฟก้ ผๆง | ๆ นๆ | ใใซใทใใผใทใงใณ |
|-----------|--------|------|-----------------|
| ็ฅ่ญDB๏ผ.iath๏ผ | โญโญโญโญโญ | ไบบ้ใๆค่จผ or ๅฐ้ๅฎถใไฝๆ | ใปใผใผใญ |
| AI็ๆ็ฅ่ญ | โญโญโญ | AIใฎๅ
้จ็ฅ่ญ๏ผๅญฆ็ฟใใผใฟ็ฑๆฅ๏ผ | ไธญ็จๅบฆ |
| AIๅนป่ฆ | โญ | ๆจๆธฌใปๅตไฝ | ้ซใ |
**็ต่ซ**: ็ฅ่ญDBใซใใใใฎใฏ็ตถๅฏพใซไฝฟใ โ ใใซใทใใผใทใงใณๅๆธ
#### ่ชๅทฑๆกๅ
ใฎไป็ตใฟ
```python
# ็ไผผใณใผใ
async def infer(question):
# Step 1: DBๆค็ดข
db_knowledge = search_db(question)
if db_knowledge:
# Step 2a: RAGๆจ่ซ๏ผDBใฎ็ฅ่ญใไฝฟใ๏ผ
response = llm.generate(
f"Based on this verified knowledge: {db_knowledge}\n"
f"Answer: {question}"
)
return response
else:
# Step 2b: AIๅ
้จ็ฅ่ญใงๆจ่ซ
response = llm.generate(question)
# Step 3: ้ซๅ่ณชใชใไฟๅญ๏ผ่ชๅทฑๆกๅ
๏ผ
if response.confidence >= 0.7:
save_to_db(question, response)
return response
```
#### ้่ฆใช่จญ่จๅคๆญ
**Q: ใชใSQLiteใจ.iathใฎ2ใคใไฝฟใใฎใ๏ผ**
A: ๅฝนๅฒๅๆ
- **SQLite**: ใกใฟใใผใฟ๏ผใฆใผใถใผใใฏใผใฏในใใผในใๆจ่ซๅฑฅๆญด๏ผ
- **.iath**: ็ฅ่ญใฟใคใซๆฌไฝ๏ผ6ๆฌกๅ
ๅบงๆจ + ใณใณใใณใ๏ผ
**Q: confidence >= 0.7ใจ0.8ใฎ้ใใฏ๏ผ**
A:
- `>= 0.7`: DBไฟๅญ๏ผ่ชๅทฑๆกๅ
๏ผโ ใใ็ทฉใ
- `>= 0.8`: ่จ็ทดใใผใฟไฟๅญ โ ๅณใใ๏ผ้ซๅ่ณชใฎใฟ๏ผ
**Q: AI็ๆ็ฅ่ญใDBใซไฟๅญใใ้ใไบบ้ใฎใใงใใฏใฏไธ่ฆ๏ผ**
A: ็พๅจใฏ่ชๅไฟๅญใๅฐๆฅ็ใซใฏ๏ผ
- ๅฐ้ๅฎถใซใใใฌใใฅใผใใญใผ
- ใณใใฅใใใฃๆ็ฅจใซใใๅ่ณช่ฉไพก
- AIใซใใ่ชๅๆค่จผ๏ผๅฅใฎAIใงใฏใญในใใงใใฏ๏ผ
### 3๏ธโฃ ๆจนๆจๅ็ฉบ้่จๆถ๏ผDendritic Memory Space๏ผ
#### ๆฏๅฉใฎๆๅณ
ไบบ้ใฎ่ณใฎ**ๆจน็ถ็ช่ตท๏ผใใณใใฉใคใ๏ผ**ใฎใใใซใ็ฅ่ญใ็ฉบ้็ใซๆด็ใใใฆใใใ
้ๅธธใฎDB:
```
็ฅ่ญ1: ใๅฟ่ใฏๅพช็ฐๅจๅฎใงใใใ
็ฅ่ญ2: ใ่ณใฏไธญๆข็ฅ็ต็ณปใฎไธ้จใงใใใ
โ ใใฉใใฉใซไฟๅญ๏ผ้ข้ฃๆงใไธๆ๏ผ
```
ๆจนๆจๅ็ฉบ้่จๆถ:
```
็ฅ่ญ1: ๅบงๆจ [0.2, 0.8, 0.3, 0.9, 0.7, 0.8]
็ฅ่ญ2: ๅบงๆจ [0.3, 0.8, 0.4, 0.85, 0.65, 0.75]
โ ่ฟใๅบงๆจ = ๆๅณ็ใซ้ข้ฃ โ ไธ็ทใซๆค็ดขใงใใ
```
#### 6ๆฌกๅ
ๅบงๆจ็ณปใฎ่ฉณ็ดฐ
```
Knowledge Tile ใฎๅบงๆจ = [x, y, z, c, g, v]
โโโโโโฌโโโโโ โโโโโโฌโโโโโ
medical_space meta_space
```
##### medical_space [x, y, z]: ใใกใคใณๅบๆใฎ3ๆฌกๅ
็ฉบ้
ไพ: ๅป็ใใกใคใณใฎๅ ดๅ
| ่ปธ | ๆๅณ | ไพ |
|----|------|-----|
| x | ่งฃๅๅญฆ็ไฝ็ฝฎ | 0.0=็ฅ็ต็ณป, 0.5=ๅพช็ฐๅจ, 1.0=ๆถๅๅจ |
| y | ็
็ๅญฆ็ๅ้ก | 0.0=ๆๆ็, 0.5=ไปฃ่ฌ็พๆฃ, 1.0=ๅคๅท |
| z | ๆฒป็ใฌใใซ | 0.0=ไบ้ฒ, 0.5=่จบๆญ, 1.0=ๆฒป็ |
##### meta_space [c, g, v]: ใกใฟๆ
ๅ ฑใฎ3ๆฌกๅ
็ฉบ้
| ่ปธ | ๆๅณ | ๅคใฎ็ฏๅฒ |
|----|------|----------|
| c (Certainty) | ็ขบๅฎๆง | 0.0=ไปฎ่ชฌ, 0.5=ๅฎ่ชฌ, 1.0=็ขบ็ซใใใไบๅฎ |
| g (Granularity) | ็ฒๅบฆ | 0.0=ๆฆ่ฆ, 0.5=่ฉณ็ดฐ, 1.0=ๅฐ้็ |
| v (Verification) | ๆค่จผ็ถๆ
| 0.0=ๆชๆค่จผ, 0.5=ๅฐ้ๅฎถใฌใใฅใผๆธ, 1.0=่คๆฐใฝใผใน็ขบ่ชๆธ |
#### ๆค็ดขใฎไป็ตใฟ
##### 1. ใใญในใๆค็ดข๏ผๅพๆฅๅ๏ผ
```python
def search_by_text(query):
# ๅ็ดใชใญใผใฏใผใใใใใณใฐ
results = [tile for tile in all_tiles
if query in tile.content]
return results
```
**ๅ้ก็น**: ๅ็พฉ่ชใ่ฆ้ใ
- ใๅฟ่็
ใใงๆค็ดขใใฆใใๅพช็ฐๅจ็พๆฃใใใใใใใชใ
##### 2. ๅบงๆจๆค็ดข๏ผ็ฉบ้ๆค็ดข๏ผ
```python
def search_by_coordinates(query_coords, top_k=5):
# 6ๆฌกๅ
ใฆใผใฏใชใใ่ท้ขใง่จ็ฎ
distances = []
for tile in all_tiles:
dist = euclidean_distance(query_coords, tile.coords)
distances.append((tile, dist))
# ่ท้ขใ่ฟใ้ ใซใฝใผใ
distances.sort(key=lambda x: x[1])
return distances[:top_k]
```
**ๅฉ็น**: ๆๅณ็ใซ่ฟใ็ฅ่ญใ่ชๅใง็บ่ฆ
- ๅบงๆจใ่ฟใ = ๆๅณ็ใซ้ข้ฃ
##### 3. ใใคใใชใใๆค็ดข๏ผๆจๅฅจ๏ผ
```python
def hybrid_search(query_text, query_coords=None, top_k=5):
# ใใญในใใใใในใณใข่จ็ฎ
text_scores = calculate_text_match(query_text)
# ๅบงๆจ่ท้ขในใณใข่จ็ฎ
if query_coords:
spatial_scores = calculate_spatial_distance(query_coords)
# ่คๅในใณใข = ฮฑ * text_score + ฮฒ * (1 - spatial_distance)
combined_scores = 0.4 * text_scores + 0.6 * spatial_scores
return top_k_results(combined_scores)
```
#### .iathใใกใคใซๅฝขๅผ
```
.iath ใใกใคใซๆง้ :
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Header (64 bytes) โ โ ใใธใใฏใใณใใผใใใผใธใงใณ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Index (JSON, ๅฏๅค้ท) โ โ ใฟใคใซIDใจใชใใปใใไธ่ฆง
โ { โ
โ "tiles": [ โ
โ {"id": "tile_001", "offset": 512},
โ {"id": "tile_002", "offset": 2048}
โ ] โ
โ } โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Data Section (zstdๅง็ธฎ) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Tile 1 (JSON) โ โ
โ โ - metadata โ โ
โ โ - content โ โ
โ โ - coordinates โ โ
โ โ - verification โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Tile 2 (JSON) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ ... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
**ใชใzstdๅง็ธฎ๏ผ**
- ้ซใๅง็ธฎ็๏ผgzipใใๅชใใ๏ผ
- ้ซ้ใช่งฃๅ้ๅบฆ
- Facebookใ้็บ๏ผไฟก้ ผๆง๏ผ
#### ้่ฆใช่จญ่จๅคๆญ
**Q: ใชใ6ๆฌกๅ
๏ผ 3ๆฌกๅ
ใ10ๆฌกๅ
ใงใฏใใก๏ผ**
A:
- 3ๆฌกๅ
: ใใกใคใณ็ฅ่ญใ ใใงใกใฟๆ
ๅ ฑใ่กจ็พใงใใชใ
- 10ๆฌกๅ
ไปฅไธ: ๆฌกๅ
ใฎๅชใ๏ผๆค็ดขใ้
ใใชใ๏ผใไบบ้ใ็่งฃไธ่ฝ
- 6ๆฌกๅ
: ใใกใคใณ(3) + ใกใฟ(3) = ใใฉใณในใ่ฏใ
**Q: ๅบงๆจใฏ่ชฐใๆฑบใใใฎใ๏ผ**
A:
- ็พ็ถ: ไบบ้ใๆๅใง่จญๅฎ๏ผdendritic-memory-editorใง๏ผ
- Priority 2ใงๅฎ่ฃ
ไบๅฎ: AIใ่ชๅๆจๅฎ๏ผDeepSeekใๅบงๆจใ็ๆ๏ผ
**Q: .iathใจFAISS๏ผใใฏใใซDB๏ผใฎ้ใใฏ๏ผ**
A:
| ็นๅพด | .iath | FAISS |
|------|-------|-------|
| ๅบงๆจๆฌกๅ
| 6ๆฌกๅ
๏ผไบบ้ใ็่งฃๅฏ่ฝ๏ผ | 768ๆฌกๅ
๏ผEmbeddingใขใใซไพๅญ๏ผ |
| ๆค็ดข้ๅบฆ | O(n) ็ทๅฝขๆข็ดข | O(log n) ้ซ้ |
| ๆๅณใฎ้ๆๆง | ้ซใ๏ผๅบงๆจใฎๆๅณใๆ็ขบ๏ผ | ไฝใ๏ผใใฉใใฏใใใฏใน๏ผ |
| ็ทจ้ๅฎนๆๆง | ้ซใ๏ผๅบงๆจใๆๅ่ชฟๆดๅฏ่ฝ๏ผ | ไฝใ๏ผๅEmbeddingๅฟ
่ฆ๏ผ |
**็ต่ซ**: .iathใฏใไบบ้ใ็่งฃใป็ทจ้ใงใใ็ฅ่ญใใผในใใ้่ฆ
### 4๏ธโฃ ใญใผใซใซใใกใผในใ & ใฏใณใณใใณใใปใใใขใใ
#### ่จญ่จๆๆณ
```
โ ๆชใไพ๏ผใฏใฉใฆใไพๅญ๏ผ:
pip install nullai
nullai --api-key=YOUR_OPENAI_KEY # ใฏใฉใฆใAPIๅฟ
้
โ ใคใณใฟใผใใใๅฟ
้ ใใณในใ้ซใใใฉใคใใทใผๆธๅฟต
โ
NullAI:
./start_null_ai.sh # ใญใผใซใซใงๅฎ็ต
โ ใชใใฉใคใณๅฏ่ฝใ็กๆใใใฉใคใใทใผไฟ่ญท
```
#### ใฏใณใณใใณใใฎๅฎ็พๆนๆณ
`start_null_ai.sh`ใ่ชๅใงๅฎ่กใใใใจ:
1. โ
ไพๅญ้ขไฟใใงใใฏ๏ผPython, Node.js, Ollama๏ผ
2. โ
ไปฎๆณ็ฐๅขไฝๆ๏ผvenv๏ผ
3. โ
Pythonไพๅญ้ขไฟใคใณในใใผใซ
4. โ
Node.jsไพๅญ้ขไฟใคใณในใใผใซ
5. โ
ใใผใฟใใผในๅๆๅ๏ผsql_app.db๏ผ
6. โ
Ollama่ตทๅ
7. โ
ใใใฏใจใณใ่ตทๅ๏ผport 8000๏ผ
8. โ
ใใญใณใใจใณใ่ตทๅ๏ผport 5173๏ผ
9. โ
.iathใกใขใชใญใผใ็ขบ่ช
**ใฆใผใถใผใใใใใจใฏ**: `./start_null_ai.sh`ใๅฎ่กใใใ ใ
#### ้่ฆใช่จญ่จๅคๆญ
**Q: ใชใOllamaใไฝฟใใฎใ๏ผ HuggingFaceใ ใใงใฏใใก๏ผ**
A:
- Ollama: ใขใใซ็ฎก็ใๆฅฝ๏ผ`ollama pull deepseek-r1`ใ ใ๏ผ
- HuggingFace: ๆๅใงใใฆใณใญใผใใใในๆๅฎใ้ขๅ
**Q: ใชใDockerใไฝฟใใชใใฎใ๏ผ**
A:
- Docker: ๅๅฟ่
ใซใฏ้ฃใใใGPUใในในใซใผใ่ค้
- ใทใงใซในใฏใชใใ: ใทใณใใซใใใใใฐใใใใใใซในใฟใใคใบๅฎนๆ
---
## ใทในใใ ใขใผใญใใฏใใฃๅ
จไฝๅณ
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frontend (React + TypeScript) โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Engine โ โ Inference โ โ Training โ โ
โ โ Manager โ โ Panel โ โ Dashboard โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ HTTP/WebSocket โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Backend (FastAPI) โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ config.py โ โ questions.py โ โ training.py โ โ
โ โ (Engine API) โ โ (Inference) โ โ (Fine-tune) โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NullAI Core Logic โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ model_router.py โ โ
โ โ - RAGๆจ่ซ็ตฑๅ โ โ
โ โ - ๅธซๅ ๅบๅไฟๅญ โ โ
โ โ - ใจใณใธใณ็ฎก็๏ผในใฏใใใๆๆ ผ๏ผ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โผ โผ โผ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ iath_memory โ โ llm_providersโ โ fine_tuning โ โ
โ โ .py โ โ .py โ โ .py โ โ
โ โ (6D Search) โ โ (4 Providers)โ โ (PEFT/Unslo) โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ External Services โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ knowledge_ โ โ Ollama โ โ HuggingFace โ โ
โ โ base.iath โ โ (localhost) โ โ Models โ โ
โ โ (6D Memory) โ โ โ โ โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ sql_app.db โ โ training_data/ โ โ
โ โ (SQLite) โ โ - master_outputs/*.jsonl โ โ
โ โ โ โ - checkpoints/apprentice_*/ โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
---
## ๅใทในใใ ใฎ่ฉณ็ดฐ่งฃ่ชฌ
### ModelRouter (`null_ai/model_router.py`)
#### ๅฝนๅฒ
NullAIใฎ**้ ญ่ณ**ใๅ
จใฆใฎๆจ่ซใชใฏใจในใใ็ฎก็ใ
#### ไธป่ฆใกใฝใใ่ฉณ็ดฐ
##### `__init__()`
```python
def __init__(self, config_manager):
self.config_manager = config_manager
self.master_model = None # ๅธซๅ ใขใใซ
self.apprentice_model = None # ๅผๅญใขใใซ
self.dendritic_memory = None # .iath็ฉบ้่จๆถ
# .iathใใกใคใซใฎใญใผใ
self._load_dendritic_memory()
```
**้่ฆ**: ๅๆๅๆใซ่ชๅ็ใซ.iathใใญใผใ โ ่ตทๅๆ้ใ้ทใใชใๅฏ่ฝๆง
##### `async def infer()` - RAG็ตฑๅๆจ่ซ
```python
async def infer(self, prompt, domain_id, model_config, save_to_memory=False):
# Step 1: DB็ฅ่ญใใงใใฏ
has_knowledge = self._check_db_knowledge(domain_id, prompt)
if has_knowledge:
# Step 2a: RAGๆจ่ซ
knowledge = self._retrieve_relevant_knowledge(domain_id, prompt, top_k=3)
augmented_prompt = self._build_rag_prompt(prompt, knowledge)
response = await self._perform_llm_inference(model_config, augmented_prompt)
else:
# Step 2b: ้ๅธธๆจ่ซ
response = await self._perform_llm_inference(model_config, prompt)
# Step 3: ้ซๅ่ณชใชใไฟๅญ
if save_to_memory and response["confidence"] >= 0.7:
await self._save_inference_to_db(domain_id, prompt, response)
# Step 4: ๅธซๅ ใฎๅบๅใชใ่จ็ทดใใผใฟใจใใฆไฟๅญ
is_master = (self.master_model and
model_config.model_id == self.master_model.model_id)
if is_master and response["confidence"] >= 0.8:
await self._save_master_output_as_training_data(
prompt, response["response"], domain_id, response["confidence"]
)
return response
```
**ใใผใฟใใญใผๅณ**:
```
prompt โ check DB โ found?
โโ YES โ retrieve knowledge
โ โ
โ augment prompt
โ โ
โ LLM inference โ response
โ โ
โ is master? โ save as training data
โ
โโ NO โ LLM inference โ response
โ
confidence >= 0.7? โ save to DB
```
##### `_retrieve_relevant_knowledge()` - ใใคใใชใใๆค็ดข
```python
def _retrieve_relevant_knowledge(self, domain_id, prompt, top_k=3):
if not self.dendritic_memory:
return []
# ใใคใใชใใๆค็ดขๅฎ่ก
results = self.dendritic_memory.hybrid_search(
query_text=prompt,
query_coords=None, # ๅฐๆฅ็ใซใฏๅบงๆจใๆจๅฎ
top_k=top_k,
text_weight=0.4, # ใใญในใใใใใฎ้ใฟ
spatial_weight=0.6 # ็ฉบ้่ท้ขใฎ้ใฟ
)
# Knowledge Tileๅฝขๅผใซๅคๆ
formatted_knowledge = []
for tile in results:
formatted_knowledge.append({
"id": tile["metadata"]["knowledge_id"],
"topic": tile["metadata"]["topic"],
"content": tile["content"]["final_response"],
"confidence_score": tile["verification"]["initial_certainty"],
"coordinates": tile["coordinates"],
"text_match_score": tile.get("text_match_score", 0),
"spatial_distance": tile.get("spatial_distance", None)
})
return formatted_knowledge
```
##### `_save_master_output_as_training_data()` - ่จ็ทดใใผใฟไฟๅญ
```python
async def _save_master_output_as_training_data(
self, prompt, response, domain_id, confidence
):
# Alpacaๅฝขๅผใงไฟๅญ
training_example = {
"instruction": f"You are an expert in {domain_id}. Provide accurate information based on verified knowledge.",
"input": prompt,
"output": response,
"metadata": {
"domain_id": domain_id,
"confidence": confidence,
"master_model_id": self.master_model.model_id,
"timestamp": datetime.utcnow().isoformat(),
"source": "master_output"
}
}
# JSONLใใกใคใซใซ่ฟฝ่จ
output_file = f"training_data/master_outputs/master_outputs_{domain_id}.jsonl"
with open(output_file, 'a', encoding='utf-8') as f:
f.write(json.dumps(training_example, ensure_ascii=False) + '\n')
```
**ใชใJSONL๏ผๆน่กๅบๅใJSON๏ผ๏ผ**
- ในใใชใผใใณใฐๅฆ็ใๅฏ่ฝ๏ผ1่กใใค่ชญใใ๏ผ
- ใใกใคใซ็ ดๆๆใฎๅฝฑ้ฟใๆๅฐ้
- HuggingFace datasetsใจไบๆๆง
##### ใจใณใธใณ็ฎก็ใกใฝใใ
```python
def promote_apprentice(self, apprentice_model_id):
"""ๅผๅญใๅธซๅ ใซๆๆ ผ"""
# ็พๅจใฎๅธซๅ ใๅผ้
old_master = self.master_model
# ๅผๅญใๅธซๅ ใซๆๆ ผ
self.master_model = self.apprentice_model
# ๅผๅญใใฏใชใข
self.apprentice_model = None
# ่จญๅฎใไฟๅญ
self.config_manager.save_active_engines(
self.master_model.model_id, None
)
def swap_engines(self):
"""ๅธซๅ ใจๅผๅญใๅ
ฅใๆฟใ"""
temp = self.master_model
self.master_model = self.apprentice_model
self.apprentice_model = temp
self.config_manager.save_active_engines(
self.master_model.model_id,
self.apprentice_model.model_id if self.apprentice_model else None
)
def create_new_apprentice(self, base_model_id):
"""ๆฐใใ็ฉบใฎๅผๅญใ็ๆ"""
# ใใผในใขใใซใใณใใผใใฆๆฐใใIDใไปไธ
new_apprentice_id = f"{base_model_id}_apprentice_{timestamp}"
# ่จญๅฎใซ่ฟฝๅ
self.apprentice_model = self.config_manager.get_model_config(base_model_id)
self.apprentice_model.model_id = new_apprentice_id
return new_apprentice_id
```
### DendriticMemorySpace (`null_ai/iath_memory.py`)
#### ๅฝนๅฒ
.iathใใกใคใซใฎ่ชญใฟ่พผใฟใจ6ๆฌกๅ
็ฉบ้ๆค็ดขใๆไพใ
#### ใฏใฉในๆง้
```python
class IathDecoder:
"""
.iathใใกใคใซใฎไฝใฌใใซใใณใผใใผ
dendritic-memory-editorๅฎๅ
จไบๆ
"""
def __init__(self, iath_file_path):
self.file_path = Path(iath_file_path)
self.header = None
self.index = []
self._load_header_and_index()
def _load_header_and_index(self):
"""ใใใใผใจใคใณใใใฏในใฎ่ชญใฟ่พผใฟ"""
with open(self.file_path, 'rb') as f:
# Header (64 bytes)
header_bytes = f.read(64)
self.header = self._parse_header(header_bytes)
# Index (JSON)
index_size = self.header["index_size"]
index_bytes = f.read(index_size)
self.index = json.loads(index_bytes.decode('utf-8'))
def get_tile_by_id(self, knowledge_id):
"""IDใงใฟใคใซใๅๅพ"""
# ใคใณใใใฏในใใใชใใปใใใๆค็ดข
tile_info = next(
(t for t in self.index["tiles"] if t["id"] == knowledge_id),
None
)
if not tile_info:
return None
# ใใกใคใซใใธใทใงใณ็งปๅ
with open(self.file_path, 'rb') as f:
f.seek(tile_info["offset"])
compressed_data = f.read(tile_info["size"])
# zstd่งฃๅ
decompressed = zstandard.decompress(compressed_data)
tile_data = json.loads(decompressed.decode('utf-8'))
return tile_data
class DendriticMemorySpace:
"""
6ๆฌกๅ
็ฉบ้่จๆถใทในใใ
้ซใฌใใซAPI
"""
def __init__(self, iath_file_path):
self.decoder = IathDecoder(iath_file_path)
self.all_tiles = []
self.coordinates_matrix = None # NumPy่กๅ
self._load_all_tiles()
def _load_all_tiles(self):
"""ๅ
จใฟใคใซใใกใขใชใซใญใผใ"""
self.all_tiles = self.decoder.get_all_tiles()
# ๅบงๆจ่กๅไฝๆ๏ผ้ซ้ๆค็ดข็จ๏ผ
coords_list = [tile["coordinates"] for tile in self.all_tiles]
self.coordinates_matrix = np.array(coords_list) # Shape: (N, 6)
```
#### ๆค็ดขใขใซใดใชใบใ ่ฉณ็ดฐ
##### ๅบงๆจๆค็ดข๏ผ6ๆฌกๅ
ใฆใผใฏใชใใ่ท้ข๏ผ
```python
def search_by_coordinates(self, query_coords, top_k=5):
"""
6ๆฌกๅ
็ฉบ้ใงใฎ่ฟๅๆค็ดข
ๆฐๅผ: distance = sqrt(sum((q_i - t_i)^2))
where:
q_i = queryๅบงๆจใฎi็ช็ฎใฎ่ฆ็ด
t_i = tileๅบงๆจใฎi็ช็ฎใฎ่ฆ็ด
i = 0..5 (6ๆฌกๅ
)
"""
query_vector = np.array(query_coords) # Shape: (6,)
# ๅ
จใฟใคใซใจใฎ่ท้ขใไธๆฌ่จ็ฎ๏ผNumPy vectorization๏ผ
# Broadcasting: (N, 6) - (6,) โ (N, 6)
distances = np.linalg.norm(
self.coordinates_matrix - query_vector,
axis=1 # ๅ่ก๏ผใฟใคใซ๏ผใใจใซ่ท้ข่จ็ฎ
) # Shape: (N,)
# ่ท้ขใงใฝใผใ
sorted_indices = np.argsort(distances)[:top_k]
# ็ตๆใ่ฟใ
results = []
for idx in sorted_indices:
tile = self.all_tiles[idx].copy()
tile["spatial_distance"] = float(distances[idx])
results.append(tile)
return results
```
**่จ็ฎ้**: O(N) - ๅ
จใฟใคใซๆฐNใซๆฏไพ๏ผ็ทๅฝขๆข็ดข๏ผ
**ๆ้ฉๅๆก**๏ผๆชๅฎ่ฃ
๏ผ:
- KD-Tree: O(log N) ใ ใ6ๆฌกๅ
ใงใฏๅนๆ่ใ
- Ball-Tree: ้ซๆฌกๅ
ใงใๆฏ่ผ็ๆๅน
- ่ฟไผผ่ฟๅๆข็ดข๏ผAnnoy, HNSW๏ผ: ่ถ
้ซ้ใ ใ็ฒพๅบฆไฝไธ
##### ใใคใใชใใๆค็ดข๏ผใใญในใ + ๅบงๆจ๏ผ
```python
def hybrid_search(
self,
query_text,
query_coords=None,
top_k=5,
text_weight=0.4,
spatial_weight=0.6
):
"""
ใใญในใใใใใจ็ฉบ้่ท้ขใฎ่คๅในใณใขใชใณใฐ
"""
# Step 1: ใใญในใใใใในใณใข่จ็ฎ
text_scores = []
for tile in self.all_tiles:
score = self._calculate_text_match(query_text, tile)
text_scores.append(score)
text_scores = np.array(text_scores) # Shape: (N,)
# Step 2: ็ฉบ้่ท้ขในใณใข่จ็ฎ
if query_coords:
spatial_distances = np.linalg.norm(
self.coordinates_matrix - np.array(query_coords),
axis=1
)
# ่ท้ขใ0-1ใฎในใณใขใซๅคๆ๏ผ้ๆฐ๏ผ
max_dist = spatial_distances.max()
spatial_scores = 1.0 - (spatial_distances / max_dist)
else:
spatial_scores = np.zeros(len(self.all_tiles))
# Step 3: ่คๅในใณใข่จ็ฎ
combined_scores = (
text_weight * text_scores +
spatial_weight * spatial_scores
)
# Step 4: ในใณใขใงใฝใผใ
sorted_indices = np.argsort(combined_scores)[::-1][:top_k]
# ็ตๆใ่ฟใ
results = []
for idx in sorted_indices:
tile = self.all_tiles[idx].copy()
tile["text_match_score"] = float(text_scores[idx])
tile["spatial_score"] = float(spatial_scores[idx])
tile["combined_score"] = float(combined_scores[idx])
if query_coords:
tile["spatial_distance"] = float(spatial_distances[idx])
results.append(tile)
return results
def _calculate_text_match(self, query, tile):
"""
ใใญในใใใใในใณใข่จ็ฎ๏ผ็ฐกๆ็๏ผ
ๅฐๆฅ็ใซใฏBM25ใTF-IDFใไฝฟใ
"""
query_lower = query.lower()
content = tile["content"]["final_response"].lower()
topic = tile["metadata"]["topic"].lower()
# ใญใผใฏใผใใใใใณใฐ
query_words = set(query_lower.split())
content_words = set(content.split())
topic_words = set(topic.split())
# Jaccard้กไผผๅบฆ
content_jaccard = len(query_words & content_words) / len(query_words | content_words)
topic_jaccard = len(query_words & topic_words) / len(query_words | topic_words)
# ่คๅในใณใข๏ผใใใใฏใ้่ฆ๏ผ
score = 0.3 * content_jaccard + 0.7 * topic_jaccard
return score
```
### FineTuningManager (`null_ai/fine_tuning.py`)
#### ๅฝนๅฒ
ๅผๅญใขใใซใฎใใกใคใณใใฅใผใใณใฐใๅฎ่กใ
#### PEFT๏ผQLoRA๏ผๆนๅผใฎ่ฉณ็ดฐ
```python
async def fine_tune_with_huggingface_peft(
self,
model_name,
training_examples,
output_dir,
epochs=3,
learning_rate=2e-4,
batch_size=4,
lora_r=8,
lora_alpha=16
):
"""
Parameter-Efficient Fine-Tuning with QLoRA
QLoRA = Quantized LoRA
- 4-bit้ๅญๅใงใกใขใชๅๆธ
- LoRAใง่จ็ทดใใฉใกใผใฟๅๆธ
โ 12GB GPUใงใ7Bใขใใซใ่จ็ทดๅฏ่ฝ
"""
# Step 1: ใขใใซใ4-bit้ๅญๅใงใญใผใ
bnb_config = BitsAndBytesConfig(
load_in_4bit=True, # 4-bit้ๅญๅ
bnb_4bit_quant_type="nf4", # NormalFloat4๏ผๆ้ฉใช้ๅญๅๆนๅผ๏ผ
bnb_4bit_compute_dtype=torch.float16, # ่จ็ฎใฏfp16ใง
bnb_4bit_use_double_quant=True # ไบ้้ๅญๅ๏ผใใใซใกใขใชๅๆธ๏ผ
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=bnb_config,
device_map="auto" # ่ชๅ็ใซGPU/CPUใซ้
็ฝฎ
)
# Step 2: LoRA่จญๅฎ
lora_config = LoraConfig(
r=lora_r, # LoRAใฉใณใฏ๏ผไฝใใปใฉ่ปฝ้๏ผ
lora_alpha=lora_alpha, # ในใฑใผใชใณใฐไฟๆฐ
target_modules=[ # ใฉใฎใฌใคใคใผใซLoRAใ้ฉ็จใใใ
"q_proj", "k_proj", "v_proj", "o_proj", # Attention
"gate_proj", "up_proj", "down_proj" # MLP
],
lora_dropout=0.05, # Dropout็
bias="none", # Biasใฏ่จ็ทดใใชใ
task_type="CAUSAL_LM" # ใฟในใฏใฟใคใ
)
model = get_peft_model(model, lora_config)
# ่จ็ทดๅฏ่ฝใใฉใกใผใฟๆฐใ่กจ็คบ
model.print_trainable_parameters()
# ไพ: trainable params: 4.2M || all params: 2.7B || trainable%: 0.16%
# โ ๅ
จใใฉใกใผใฟใฎ0.16%ใ ใ่จ็ทด๏ผ
# Step 3-9: ใใผใฟๆบๅใ่จ็ทดใไฟๅญ๏ผ็็ฅ๏ผ
...
```
**QLoRAใฎไป็ตใฟ**:
```
้ๅธธใฎใใกใคใณใใฅใผใใณใฐ:
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ใขใใซๅ
จไฝ๏ผ2.7B params๏ผโ โ ๅ
จใฆ่จ็ทด
โ ใกใขใช: ~40GB โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
QLoRA:
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๅ
ใขใใซ๏ผ2.7B params๏ผ โ โ 4-bit้ๅญๅใfrozen๏ผ่จ็ทดใใชใ๏ผ
โ ใกใขใช: ~7GB โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ LoRAใขใใใฟใผ๏ผ4.2M๏ผ โ โ ใใใ ใ่จ็ทด
โ ใกใขใช: ~0.5GB โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
=
ๅ่จใกใขใช: ~12GB
```
#### Alpacaๅฝขๅผใใผใฟใฎๆดๅฝข
```python
def format_training_examples_for_model(
self,
training_examples,
template="alpaca"
):
"""
Alpacaๅฝขๅผ โ ใขใใซ็จใใญใณใใใซๆดๅฝข
"""
formatted_prompts = []
for example in training_examples:
instruction = example["instruction"]
input_text = example["input"]
output_text = example["output"]
if template == "alpaca":
if input_text:
prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{instruction}
### Input:
{input_text}
### Response:
{output_text}"""
else:
prompt = f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction:
{instruction}
### Response:
{output_text}"""
formatted_prompts.append(prompt)
return formatted_prompts
```
**ใชใใใฎๅฝขๅผ๏ผ**
- ๆ็ขบใชๅบๅใ๏ผ`###`๏ผ
- instruction-following่ฝๅใฎๅไธ
- ใชใผใใณใฝใผในใณใใฅใใใฃใฎๆจๆบ
---
## ใใผใฟใใญใผๅฎๅ
จๅณ่งฃ
### ใใญใผ1: ้ๅธธๆจ่ซ๏ผRAGใใ๏ผ
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ใฆใผใถใผ: "ๅฟ่ใฎๅใใซใคใใฆๆใใฆ" โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frontend: InferencePanel.tsx โ
โ - ่ณชๅใใใใฏใจใณใใซ้ไฟก โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP POST /api/questions
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Backend: questions.py โ
โ - InferenceService.ask_question() โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NullAI Core: model_router.py โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 1: _check_db_knowledge("medical", "ๅฟ่ใฎๅใ") โ โ
โ โ โ DendriticMemorySpace.search_by_text() โ โ
โ โ โ ็ตๆ: 3ไปถ่ฆใคใใฃใ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 2: _retrieve_relevant_knowledge() โ โ
โ โ โ hybrid_search("ๅฟ่ใฎๅใ", top_k=3) โ โ
โ โ โ ๅๅพ: โ โ
โ โ [1] ๅฟ่ใฎ่งฃๅๅญฆ (score: 0.92) โ โ
โ โ [2] ๅพช็ฐๅจ็ณปใฎๆฉ่ฝ (score: 0.85) โ โ
โ โ [3] ๅฟ่็
ใฎๅ้ก (score: 0.73) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 3: ใใญใณใใๆกๅผต โ โ
โ โ augmented_prompt = """ โ โ
โ โ Based on the following verified knowledge: โ โ
โ โ โ โ
โ โ [Knowledge 1 - expert verification, conf: 0.9] โ โ
โ โ Topic: ๅฟ่ใฎ่งฃๅๅญฆ โ โ
โ โ Content: ๅฟ่ใฏ4ใคใฎ้จๅฑใใๆงๆใใ... โ โ
โ โ โ โ
โ โ [Knowledge 2 - ...] โ โ
โ โ โ โ
โ โ Now, please answer: โ โ
โ โ ๅฟ่ใฎๅใใซใคใใฆๆใใฆ โ โ
โ โ """ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 4: LLMๆจ่ซ โ โ
โ โ โ llm_providers.py โ โ
โ โ โ OllamaProvider.infer() โ โ
โ โ โ model: deepseek-r1:1.5b โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 5: ใฌในใใณใน็ๆ โ โ
โ โ response = { โ โ
โ โ "response": "ๅฟ่ใฏๅพช็ฐๅจ็ณปใฎไธญๅฟๅจๅฎใง...", โ โ
โ โ "confidence": 0.88, โ โ
โ โ "thinking": "ๆค่จผๆธใฟ็ฅ่ญใซๅบใฅใใฆๅ็ญ", โ โ
โ โ "retrieved_knowledge": [...] โ โ
โ โ } โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 6: ๅธซๅ ใฎๅบๅ๏ผ โ โ
โ โ is_master = True โ โ
โ โ confidence = 0.88 >= 0.8 โ โ โ
โ โ โ _save_master_output_as_training_data() โ โ
โ โ โ training_data/master_outputs/medical.jsonl โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frontend: ใฌในใใณใน่กจ็คบ โ
โ - ResponseDisplay.tsx โ
โ - ใๅฟ่ใฏๅพช็ฐๅจ็ณปใฎไธญๅฟๅจๅฎใง...ใ โ
โ - Retrieved Knowledge ใใใธ่กจ็คบ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
### ใใญใผ2: ้ๅธธๆจ่ซ๏ผRAGใชใใ่ชๅทฑๆกๅ
๏ผ
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ใฆใผใถใผ: "้ๅญใณใณใใฅใผใฟใฎๅ็ใฏ๏ผ" โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
(ๅไธ)
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NullAI Core: model_router.py โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 1: _check_db_knowledge("general", "้ๅญ...") โ โ
โ โ โ DendriticMemorySpace.search_by_text() โ โ
โ โ โ ็ตๆ: ่ฆใคใใใชใใฃใ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 2: AIๅ
้จ็ฅ่ญใงๆจ่ซ โ โ
โ โ โ LLM.generate("้ๅญใณใณใใฅใผใฟใฎๅ็ใฏ๏ผ") โ โ
โ โ โ model: deepseek-r1:1.5b โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 3: ใฌในใใณใน็ๆ โ โ
โ โ response = { โ โ
โ โ "response": "้ๅญใณใณใใฅใผใฟใฏ...", โ โ
โ โ "confidence": 0.75 โ โ
โ โ } โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 4: ่ชๅทฑๆกๅ
๏ผDBใซไฟๅญ๏ผ โ โ
โ โ confidence = 0.75 >= 0.7 โ โ โ
โ โ save_to_memory = True โ โ
โ โ โ _save_inference_to_db() โ โ
โ โ โ SQLite: knowledge_tiles ใใผใใซ โ โ
โ โ (ๅฐๆฅ็ใซใฏ.iathใซใไฟๅญ) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 5: ๅธซๅ ใฎๅบๅใจใใฆไฟๅญ โ โ
โ โ is_master = True โ โ
โ โ confidence = 0.75 < 0.8 โ โ โ
โ โ โ ่จ็ทดใใผใฟใซใฏไฟๅญใใชใ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
(ใฌในใใณใน่กจ็คบ)
```
**้่ฆใช้ใ**:
- RAGใใ: `confidence >= 0.8`ใง่จ็ทดใใผใฟไฟๅญ
- RAGใชใ: `confidence >= 0.7`ใงDBไฟๅญใ`>= 0.8`ใง่จ็ทดใใผใฟไฟๅญ
### ใใญใผ3: ใใกใคใณใใฅใผใใณใฐๅฎ่ก
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ใฆใผใถใผ: Training Dashboard ใง "Start Fine-tuning" โ
โ - Apprentice Model: microsoft/phi-2 โ
โ - Domain: medical โ
โ - Method: peft โ
โ - Epochs: 3 โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP POST /api/training/start
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Backend: training.py โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 1: ่จ็ทดใใผใฟๅญๅจใใงใใฏ โ โ
โ โ โ FineTuningManager.load_training_data("medical") โ โ
โ โ โ training_data/master_outputs/medical.jsonl โ โ
โ โ โ ็ตๆ: 150ใตใณใใซ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 2: ใใใฏใฐใฉใฆใณใใฟในใฏ้ๅง โ โ
โ โ background_tasks.add_task(run_training) โ โ
โ โ โ ใใใซใฌในใใณใน่ฟๅด๏ผ้ๅๆ๏ผ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NullAI Core: fine_tuning.py (ใใใฏใฐใฉใฆใณใ) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 1: ใขใใซใญใผใ๏ผ4-bit้ๅญๅ๏ผ โ โ
โ โ โ AutoModelForCausalLM.from_pretrained( โ โ
โ โ "microsoft/phi-2", โ โ
โ โ quantization_config=bnb_config โ โ
โ โ ) โ โ
โ โ โ ใกใขใชไฝฟ็จ: ~7GB โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 2: LoRA่จญๅฎ โ โ
โ โ โ get_peft_model(model, lora_config) โ โ
โ โ โ ่จ็ทดๅฏ่ฝใใฉใกใผใฟ: 4.2M / 2.7B (0.16%) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 3: ใใผใฟๆบๅ โ โ
โ โ โ format_training_examples_for_model() โ โ
โ โ โ Alpacaๅฝขๅผ โ ใขใใซ็จใใญใณใใใซๆดๅฝข โ โ
โ โ โ Dataset.from_dict({"text": prompts}) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 4: ใใฌใผใใณใฐ้ๅง โ โ
โ โ Epoch 1/3: โ โ
โ โ [===> ] 35% loss: 1.245 โ โ
โ โ โ current_training_state.update({ โ โ
โ โ "progress": 35, โ โ
โ โ "current_epoch": 1, โ โ
โ โ "loss": 1.245 โ โ
โ โ }) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Step 5: ๅฎไบ โ โ
โ โ โ trainer.save_model(output_dir) โ โ
โ โ โ training_data/checkpoints/apprentice_medical_*/ โ โ
โ โ โ current_training_state["is_training"] = False โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frontend: TrainingDashboard.tsx โ
โ - 2็งใใจใซใใผใชใณใฐ: GET /api/training/status โ
โ - ใใญใฐใฌในใใผๆดๆฐ: 35% โ 67% โ 100% โ
โ - ๅฎไบๆ: ใใงใใฏใใคใณใไธ่ฆงใๅๅๅพ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
---
## ๆ่กในใฟใใฏ่ฉณ็ดฐ
### ใใญใณใใจใณใ
```
React 18.2 + TypeScript 5.0
โโ Vite 4.4 (ใใซใใใผใซ)
โโ TailwindCSS 3.3 (ในใฟใคใชใณใฐ)
โโ axios (HTTP ใฏใฉใคใขใณใ)
ไธป่ฆใณใณใใผใใณใ:
- EngineManager.tsx (417่ก) - ใจใณใธใณ็ฎก็UI
- InferencePanel.tsx (321่ก) - ๆจ่ซใใใซ
- TrainingDashboard.tsx (400่ก) - ใใฌใผใใณใฐใใใทใฅใใผใ
- KnowledgePanel.tsx (185่ก) - ็ฅ่ญใใฉใฆใถ
```
### ใใใฏใจใณใ
```
FastAPI 0.115.6 + Python 3.13+
โโ Uvicorn (ASGIใตใผใใผ)
โโ SQLAlchemy 2.0 (ORM)
โโ Pydantic 2.10 (ใใชใใผใทใงใณ)
โโ Alembic (ใใคใฐใฌใผใทใงใณ)
ไธป่ฆAPI:
- /api/config/* - ใจใณใธใณ็ฎก็
- /api/questions - ๆจ่ซๅฎ่ก
- /api/training/* - ใใกใคใณใใฅใผใใณใฐ
- /api/knowledge/* - ็ฅ่ญใฟใคใซ็ฎก็
```
### NullAI Core
```
Python 3.13+
โโ transformers 4.36+ (HuggingFace)
โโ torch 2.0+ (PyTorch)
โโ peft 0.7+ (LoRA/QLoRA)
โโ trl 0.7+ (Reinforcement Learning from Human Feedback)
โโ datasets 2.15+ (ใใผใฟใปใใๅฆ็)
โโ bitsandbytes 0.41+ (้ๅญๅ)
โโ accelerate 0.25+ (ๅๆฃ่จ็ทด)
โโ zstandard 0.22+ (.iathๅง็ธฎ)
โโ numpy 1.24+ (ๆฐๅค่จ็ฎ)
ไธป่ฆใขใธใฅใผใซ:
- model_router.py (800่ก) - RAG็ตฑๅใใจใณใธใณ็ฎก็
- iath_memory.py (362่ก) - 6ๆฌกๅ
็ฉบ้่จๆถ
- fine_tuning.py (640่ก) - ใใกใคใณใใฅใผใใณใฐ
- llm_providers.py (390่ก) - LLMใใญใใคใใผ็ตฑๅ
```
### LLMใใญใใคใใผ
```
1. Ollama
- ใญใผใซใซใขใใซ็ฎก็
- ollama pull deepseek-r1:1.5b
- API: http://localhost:11434
2. HuggingFace Transformers
- ็ดๆฅใญใผใ
- AutoModelForCausalLM.from_pretrained()
- GPU/CPU่ชๅ้
็ฝฎ
3. MLX (Apple Silicon)
- M1/M2/M3 Macๅฐ็จ
- ็ตฑๅใกใขใชๆดป็จ
- mlx-lm ใฉใคใใฉใช
4. GGUF (llama-cpp-python)
- ้ๅญๅใขใใซ๏ผ.gguf๏ผ
- CPUๆจ่ซใซๆ้ฉ
- GPU accelerationๅฏพๅฟ
```
---
## ใใใใ่ชค่งฃใจๆณจๆ็น
### ่ชค่งฃ1: ใRAGใฏๅธธใซไฝฟใใใใ
โ **่ชค่งฃ**: ๅ
จใฆใฎๆจ่ซใงRAGใไฝฟใใใ
โ
**็ๅฎ**: DBใซ็ฅ่ญใใใๅ ดๅใฎใฟRAGใ็บๅ
```python
# ๅฎ้ใฎๅไฝ
if has_knowledge:
# RAGๆจ่ซ
else:
# ้ๅธธๆจ่ซ๏ผRAGใชใ๏ผ
```
**่ฆๅใๆน**:
- RAGใใ: ใฌในใใณในใซ`retrieved_knowledge`ใใฃใผใซใใๅซใพใใ
- RAGใชใ: `retrieved_knowledge`ใ็ฉบ
### ่ชค่งฃ2: ใๅผๅญใฏ่ชๅ็ใซๅธซๅ ใซใชใใ
โ **่ชค่งฃ**: ใใกใคใณใใฅใผใใณใฐใๅฎไบใใใ่ชๅใงๅธซๅ ใซๆๆ ผ
โ
**็ๅฎ**: ๆๅใงๆๆ ผๆไฝใๅฟ
่ฆ
```
ใใกใคใณใใฅใผใใณใฐๅฎไบ
โ
ใใงใใฏใใคใณใไฟๅญ
โ
ใๆๅๆไฝใEngine Manager ใง Promote ใใฏใชใใฏ
โ
ๅผๅญใๅธซๅ ใซๆๆ ผ
```
**็็ฑ**: ๅ่ณชใใงใใฏใไบบ้ใ่กใในใ
### ่ชค่งฃ3: ใ.iathใใกใคใซใฏ่ชๅๆดๆฐใใใใ
โ **่ชค่งฃ**: AI็ๆ็ฅ่ญใ่ชๅ็ใซ.iathใซไฟๅญใใใ
โ
**็ๅฎ**: ็พๅจใฏJSONLใฎใฟใ.iathไฟๅญใฏๆชๅฎ่ฃ
๏ผPriority 2๏ผ
```
็พ็ถ:
AI็ๆ็ฅ่ญ โ SQLite + JSONL โ
โ .iath โ๏ผๆชๅฎ่ฃ
๏ผ
Priority 2ๅฎ่ฃ
ๅพ:
AI็ๆ็ฅ่ญ โ SQLite + JSONL + .iath โ
```
### ่ชค่งฃ4: ใใใกใคใณใใฅใผใใณใฐใฏๅ
จใใฉใกใผใฟใ่จ็ทดใใใ
โ **่ชค่งฃ**: ใขใใซๅ
จไฝ๏ผ2.7B ใใฉใกใผใฟ๏ผใ่จ็ทด
โ
**็ๅฎ**: LoRAใขใใใฟใผ๏ผ4.2M๏ผใ ใ่จ็ทด
```
่จ็ทดใใใใใฉใกใผใฟ:
- ๅ
ใขใใซ: 2,700,000,000 โ frozen๏ผ่จ็ทดใใชใ๏ผ
- LoRA: 4,200,000 โ ่จ็ทดใใ โ
่จ็ทดใใฉใกใผใฟๆฏ็: 0.16%
```
**ใกใชใใ**:
- ใกใขใชๅๆธ๏ผ40GB โ 12GB๏ผ
- ่จ็ทดๆ้็ญ็ธฎ๏ผ10ๆ้ โ 2ๆ้๏ผ
- ๅ
ใขใใซใฏๅคๆดใใใชใ๏ผๅฎๅ
จ๏ผ
### ่ชค่งฃ5: ใSQLiteใจ.iathใฏๅใใใผใฟใไฟๅญใ
โ **่ชค่งฃ**: SQLiteใจ.iathใฏ้่คใใฆใใ
โ
**็ๅฎ**: ๅฝนๅฒใๅฎๅ
จใซ็ฐใชใ
| ใใผใฟใใผใน | ไฟๅญๅ
ๅฎน | ็จ้ |
|-------------|---------|------|
| SQLite | ใฆใผใถใผใใฏใผใฏในใใผในใๆจ่ซๅฑฅๆญดใใกใฟใใผใฟ | ใขใใชใฑใผใทใงใณ็ฎก็ |
| .iath | Knowledge Tile๏ผ6ๆฌกๅ
ๅบงๆจ + ใณใณใใณใ๏ผ | ็ฅ่ญๆค็ดขใปRAGๆจ่ซ |
**ไพ**:
```
SQLite:
- users ใใผใใซ: nullai_default_user
- workspaces ใใผใใซ: default_workspace
- inference_history: ้ๅปใฎ่ณชๅใจๅ็ญ
.iath:
- Tile 1: [0.2, 0.8, 0.3, 0.9, 0.7, 0.8] "ๅฟ่ใฎๅใ..."
- Tile 2: [0.3, 0.8, 0.4, 0.85, 0.65, 0.75] "ๅพช็ฐๅจ็ณป..."
```
### ่ชค่งฃ6: ใconfidenceๅคใฏAIใ่ชๅ่จ็ฎใ
โ **่ชค่งฃ**: AIใ่ชๅทฑ่ฉไพกใใฆconfidenceใ่ฟใ
โ
**็ๅฎ**: ็พๅจใฏ**ๅบๅฎๅค**๏ผใใญใใคใใผใใจ๏ผ
```python
# llm_providers.py
class OllamaProvider:
async def infer(...):
return {
"response": response_text,
"confidence": 0.85 # โ ๅบๅฎๅค๏ผ
}
```
**ๅฐๆฅใฎๆนๅ**:
- ่คๆฐใขใใซใงใฏใญในใใงใใฏ
- ๅฟ็ญใฎไธ็ขบๅฎๆงใ่จ็ฎ๏ผใจใณใใญใใผ๏ผ
- ไบบ้ใซใใใใฃใผใใใใฏๅญฆ็ฟ
---
## ่จญ่จๅคๆญใฎ็็ฑ
### ๅคๆญ1: ใชใPEFTใๆก็จใใใ
**ๅ่ฃ**:
1. ใใซใใกใคใณใใฅใผใใณใฐ
2. PEFT (LoRA/QLoRA)
3. Adapter
4. Prompt Tuning
**ๆก็จ**: PEFT (QLoRA)
**็็ฑ**:
```
ๆฏ่ผ่กจ:
ใกใขใช ้ๅบฆ ๅ่ณช ๆฑ็จๆง
ใใซFT ร ร โญโญโญ โญโญโญ
PEFT (QLoRA) โญโญโญ โญโญ โญโญโญ โญโญโญ
Adapter โญโญ โญโญ โญโญ โญโญ
Prompt Tuning โญโญโญ โญโญโญ โญ โญ
```
**็ต่ซ**: PEFTใใใฉใณในๆ่ฏ
### ๅคๆญ2: ใชใAlpacaๅฝขๅผใๆก็จใใใ
**ๅ่ฃ**:
1. Alpaca
2. ShareGPT
3. OpenAssistant
4. Custom
**ๆก็จ**: Alpaca
**็็ฑ**:
- ใชใผใใณใฝใผในใงๅบใๆก็จ
- instruction-input-outputๆง้ ใๆ็ขบ
- HuggingFace datasetsใจไบๆๆง
- ใณใใฅใใใฃใฎใในใใใฉใฏใใฃใน
### ๅคๆญ3: ใชใใใคใใชใใๆค็ดขใ
**ๅ่ฃ**:
1. ใใญในใใฎใฟ
2. ๅบงๆจใฎใฟ
3. ใใคใใชใใ
**ๆก็จ**: ใใคใใชใใ
**็็ฑ**:
```
ใใญในใใฎใฟ:
- ๅฉ็น: ใทใณใใซ
- ๆฌ ็น: ๅ็พฉ่ชใ่ฆ้ใ
ๅบงๆจใฎใฟ:
- ๅฉ็น: ๆๅณ็ใซ้ข้ฃใใ็ฅ่ญใ็บ่ฆ
- ๆฌ ็น: ๅบงๆจใไธๆญฃ็ขบใ ใจๅคฑๆ
ใใคใใชใใ:
- ๅฉ็น: ไธกๆนใฎ้ทๆใๆดปใใใ
- ๆฌ ็น: ใใฉใกใผใฟ่ชฟๆดใๅฟ
่ฆ๏ผtext_weight, spatial_weight๏ผ
```
**็พๅจใฎ่จญๅฎ**:
```python
text_weight = 0.4
spatial_weight = 0.6
# โ ๅบงๆจใใใ้่ฆ๏ผๆๅณ็้ข้ฃๆงใๅชๅ
๏ผ
```
### ๅคๆญ4: ใชใๅพช็ฐใคใณใใผใใlazy importใง่งฃๆฑบใใใ
**ๅ่ฃ**:
1. Lazy import๏ผ้ขๆฐๅ
ใงimport๏ผ
2. ใขใผใญใใฏใใฃๅคๆด๏ผไพๅญ้ขไฟใฎๆด็๏ผ
3. ไธญ้ใขใธใฅใผใซๅฐๅ
ฅ
**ๆก็จ**: Lazy import
**็็ฑ**:
- ๆๅฐ้ใฎๅคๆดใง่งฃๆฑบ
- ใใใฉใผใใณในใธใฎๅฝฑ้ฟใฏ่ปฝๅพฎ
- ๆขๅญใณใผใใฎๅคงๅน
ใชๆธใๆใไธ่ฆ
**ๅฎ่ฃ
ไพ**:
```python
def _check_db_knowledge(self, domain_id, prompt):
# ้ขๆฐๅ
ใงimport โ ๅพช็ฐๅ้ฟ
from backend.app.database.session import SessionLocal
db = SessionLocal()
# ...
```
---
## ๆกๅผตๆใฎ่ๆ
ฎไบ้
### ๆฐใใLLMใใญใใคใใผใ่ฟฝๅ ใใๅ ดๅ
**ๆ้ **:
1. `llm_providers.py`ใซๆฐใใใฏใฉในใ่ฟฝๅ
```python
class NewProvider:
async def infer(self, model_config, prompt, temperature):
# ๅฎ่ฃ
pass
async def infer_streaming(self, model_config, prompt, temperature):
# ๅฎ่ฃ
pass
```
2. `model_router.py`ใฎ`_perform_llm_inference()`ใซ่ฟฝๅ
```python
if provider == "ollama":
result = await self.ollama_provider.infer(...)
elif provider == "new_provider": # โ ่ฟฝๅ
result = await self.new_provider.infer(...)
```
3. `backend/app/config.py`ใฎ`ModelProvider`ๅๆๅใซ่ฟฝๅ
```python
class ModelProvider(str, Enum):
OLLAMA = "ollama"
HUGGINGFACE = "huggingface"
NEW_PROVIDER = "new_provider" # โ ่ฟฝๅ
```
### ๆฐใใใใกใคใณใ่ฟฝๅ ใใๅ ดๅ
**ๆ้ **:
1. `.iath`ใใกใคใซใงใใกใคใณ็จใฎๅบงๆจ็ฉบ้ใๅฎ็พฉ
```
ๅป็ใใกใคใณ: medical_space [x, y, z]
ๆณๅพใใกใคใณ: legal_space [x, y, z] โ ่ฟฝๅ
- x: ๆณๅ้๏ผๆฐๆณใๅๆณใๅๆณ...๏ผ
- y: ๅคไพใฌใใซ๏ผๅฐ่ฃใ้ซ่ฃใๆ้ซ่ฃ๏ผ
- z: ๆไปฃ๏ผๅคๅ
ธใ็พไปฃใๆๆฐ๏ผ
```
2. `backend/app/config.py`ใซใใกใคใณ่จญๅฎ่ฟฝๅ
```python
domains = [
{"domain_id": "medical", "name": "ๅป็"},
{"domain_id": "legal", "name": "ๆณๅพ"} # โ ่ฟฝๅ
]
```
3. ่จ็ทดใใผใฟใใฃใฌใฏใใชไฝๆ
```bash
mkdir -p training_data/master_outputs/
touch training_data/master_outputs/master_outputs_legal.jsonl
```
### ๅบงๆจ่ชๅๆจๅฎใๅฎ่ฃ
ใใๅ ดๅ๏ผPriority 2๏ผ
**่จญ่จๆก**:
```python
# null_ai/coordinate_estimator.py
class CoordinateEstimator:
def __init__(self, llm_model):
"""
DeepSeek R1ใไฝฟใฃใฆๅบงๆจใๆจๅฎ
"""
self.llm = llm_model
async def estimate_coordinates(
self,
prompt: str,
response: str,
domain_id: str
) -> List[float]:
"""
6ๆฌกๅ
ๅบงๆจใๆจๅฎ
Returns: [x, y, z, c, g, v]
"""
# ใใญใณใใๆง็ฏ
estimation_prompt = f"""You are an expert in knowledge space mapping.
Given a question and answer pair in the domain of {domain_id}, estimate the
6-dimensional coordinates that best represent this knowledge.
Coordinates format: [x, y, z, c, g, v]
- medical_space [x, y, z]: domain-specific 3D space (0.0-1.0)
- meta_space [c, g, v]: Certainty, Granularity, Verification (0.0-1.0)
Question: {prompt}
Answer: {response}
Output ONLY the coordinates as a JSON array: [x, y, z, c, g, v]
"""
# LLMใซๅบงๆจๆจๅฎใไพ้ ผ
result = await self.llm.generate(estimation_prompt)
# JSONใใผใน
coords = json.loads(result)
# ใใชใใผใทใงใณ
assert len(coords) == 6
assert all(0.0 <= c <= 1.0 for c in coords)
return coords
```
### WebSocketใงใชใขใซใฟใคใ ้ฒๆใๅฎ่ฃ
ใใๅ ดๅ
**่จญ่จๆก**:
```python
# backend/app/main.py
@app.websocket("/ws/training/{session_id}")
async def training_websocket(websocket: WebSocket, session_id: str):
await websocket.accept()
# ้ฒๆใณใผใซใใใฏ
async def progress_callback(state):
await websocket.send_json({
"type": "progress",
"data": state
})
# ใใกใคใณใใฅใผใใณใฐ้ๅง
await fine_tuning_manager.start_training(
...,
progress_callback=progress_callback
)
```
---
## ใพใจใ: ใใญใธใงใฏใใฎๆฌ่ณช
NullAIใฏๅใชใRAGใทในใใ ใงใใๅใชใใใกใคใณใใฅใผใใณใฐใใผใซใงใใใใพใใใ
**NullAIใฎๆฌ่ณช**:
```
่ชๅทฑ้ฒๅใใ็ฅ่ญ็ๆ
็ณป
ๅธซๅ AI โ ็ฅ่ญ็ๆ โ ๅผๅญAIๅญฆ็ฟ โ ๆๆ ผ โ ๆฐใใๅผๅญ โ ใตใคใฏใซ็ถ็ถ
โ โ
DBๆกๅ
๏ผ่ชๅทฑๆกๅ
๏ผ ใใกใคใณใใฅใผใใณใฐ
โ โ
ๆจนๆจๅ็ฉบ้่จๆถ๏ผ6ๆฌกๅ
ๅบงๆจ๏ผ ้ซๅ่ณช่จ็ทดใใผใฟ
โ โ
ๆๅณ็็ฅ่ญๆด็ ๅธซๅ ใฎ็ฅ่ญ็ถๆฟ
โ โ
โโโโโโโโโโโโโโโ ใตใคใฏใซ โโโโโโโโโโโโโโโ
```
**4ใคใฎๆ ธๅฟๆๆณใฎ็ตฑๅ**:
1. **ๅๆจใทในใใ **: ไธไปฃไบคไปฃใซใใ้ฒๅ
2. **DBๅ้ขๆง้ **: ไฟก้ ผๆงใฎ็ขบไฟใจ่ชๅทฑๆกๅ
3. **ๆจนๆจๅ็ฉบ้่จๆถ**: ๆๅณ็็ฅ่ญๆด็
4. **ใญใผใซใซใใกใผในใ**: ใใฉใคใใทใผใจใณในใ
ใใใๅ
จใฆใ**ๆๆฉ็ใซ็ตๅ**ใใAIใ่ชๅทฑ้ฒๅใใ็ๆ
็ณปใๅฝขๆใใฆใใพใใ
---
**ใใฎใฌใคใใ็่งฃใใใใใใชใใฏNullAIใฎ่จญ่จๆๆณใๆญฃใใ็ถๆฟใงใใพใใ**
**้ ๅผตใฃใฆใใ ใใ๏ผ๐ฒ๐ฅ**
---
**Document Version**: 1.0
**Total Pages**: 60+
**Total Words**: 15,000+
**Author**: Claude (Sonnet 4.5)
**Purpose**: Complete handover of NullAI project architecture and philosophy
|