Text Generation
Transformers
GGUF
English
phi
knowledge-system
reasoning
expert-verification
multi-domain
zero-hallucination
spatial-memory
knowledge-tiles
phi-4
microsoft
knowledge-tiles-iath
conversational
Eval Results (legacy)
Instructions to use kofdai/nullai-knowledge-system with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kofdai/nullai-knowledge-system with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kofdai/nullai-knowledge-system") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("kofdai/nullai-knowledge-system") model = AutoModelForCausalLM.from_pretrained("kofdai/nullai-knowledge-system", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use kofdai/nullai-knowledge-system with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf kofdai/nullai-knowledge-system:Q4_K_M # Run inference directly in the terminal: llama cli -hf kofdai/nullai-knowledge-system:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf kofdai/nullai-knowledge-system:Q4_K_M # Run inference directly in the terminal: llama cli -hf kofdai/nullai-knowledge-system:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf kofdai/nullai-knowledge-system:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf kofdai/nullai-knowledge-system:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf kofdai/nullai-knowledge-system:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf kofdai/nullai-knowledge-system:Q4_K_M
Use Docker
docker model run hf.co/kofdai/nullai-knowledge-system:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use kofdai/nullai-knowledge-system with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kofdai/nullai-knowledge-system" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kofdai/nullai-knowledge-system", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/kofdai/nullai-knowledge-system:Q4_K_M
- SGLang
How to use kofdai/nullai-knowledge-system with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "kofdai/nullai-knowledge-system" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kofdai/nullai-knowledge-system", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "kofdai/nullai-knowledge-system" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kofdai/nullai-knowledge-system", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use kofdai/nullai-knowledge-system with Ollama:
ollama run hf.co/kofdai/nullai-knowledge-system:Q4_K_M
- Unsloth Studio
How to use kofdai/nullai-knowledge-system with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for kofdai/nullai-knowledge-system to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for kofdai/nullai-knowledge-system to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for kofdai/nullai-knowledge-system to start chatting
- Docker Model Runner
How to use kofdai/nullai-knowledge-system with Docker Model Runner:
docker model run hf.co/kofdai/nullai-knowledge-system:Q4_K_M
- Lemonade
How to use kofdai/nullai-knowledge-system with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull kofdai/nullai-knowledge-system:Q4_K_M
Run and chat with the model
lemonade run user.nullai-knowledge-system-Q4_K_M
List all available models
lemonade list
- Atomic Chat
| import os | |
| from typing import Optional, List, Dict, Tuple | |
| import asyncio | |
| from pathlib import Path | |
| # 既存のIathDecoderをインポート | |
| # プロジェクトルートにiath_decoder.pyがあることを想定 | |
| from iath_decoder import IathDecoder | |
| class IathDBInterface: | |
| """ | |
| .iathファイルを使用するDBインターフェース | |
| """ | |
| def __init__(self, db_file_path: str): | |
| """ | |
| Args: | |
| db_file_path: .iathファイルのパス | |
| 例: "cardiology_prototype_v1.iath" | |
| """ | |
| self.db_file_path = db_file_path | |
| self.decoder = IathDecoder() | |
| self.loaded_tiles: Dict[str, Dict] = {} | |
| self.index: Dict[Tuple[int, int, int], str] = {} # 座標→タイルIDマップ | |
| self.is_loaded = False | |
| def load_db(self) -> bool: | |
| """ | |
| DBファイル全体をメモリに読み込む | |
| Returns: | |
| bool: ロード成功したか | |
| """ | |
| try: | |
| if not os.path.exists(self.db_file_path): | |
| print(f"❌ DBファイルが見つかりません: {self.db_file_path}") | |
| return False | |
| with open(self.db_file_path, 'rb') as f: | |
| db_content = f.read() | |
| # 複数タイルをデコードする decode_batch を使用 | |
| tiles = self.decoder.decode_batch(db_content) | |
| self.loaded_tiles = tiles | |
| # インデックスを構築 | |
| for tile_id, tile in tiles.items(): | |
| # ドメインスキーマに応じて空間名が変わることを想定 | |
| coord = tile.get("coordinates", {}).get("medical_space") | |
| if coord: | |
| rounded_coord = ( | |
| int(round(coord[0])), | |
| int(round(coord[1])), | |
| int(round(coord[2])) | |
| ) | |
| self.index[rounded_coord] = tile_id | |
| self.is_loaded = True | |
| print(f"✓ ロード完了: {len(tiles)}件のタイル") | |
| return True | |
| except Exception as e: | |
| print(f"❌ DBロード失敗: {e}") | |
| return False | |
| async def fetch_async( | |
| self, | |
| coordinate: Tuple[float, float, float], | |
| tolerance: float = 10.0 | |
| ) -> Optional[Dict]: | |
| """ | |
| 座標から該当タイルを非同期取得 | |
| Args: | |
| coordinate: (x, y, z) 座標 | |
| tolerance: 座標の許容誤差(デフォルト10) | |
| Returns: | |
| マッチしたタイル、またはNone | |
| """ | |
| if not self.is_loaded: | |
| # DBがロードされていない場合、先にロードを試みる | |
| print("⚠️ DBがロードされていません。ロードを試みます...") | |
| if not self.load_db(): | |
| return None | |
| # ブロッキング検索を別スレッドで実行 | |
| loop = asyncio.get_event_loop() | |
| return await loop.run_in_executor( | |
| None, | |
| self._search_coordinate, | |
| coordinate, | |
| tolerance | |
| ) | |
| def _search_coordinate( | |
| self, | |
| coordinate: Tuple[float, float, float], | |
| tolerance: float | |
| ) -> Optional[Dict]: | |
| """座標検索(同期版)""" | |
| x, y, z = coordinate | |
| for tile in self.loaded_tiles.values(): | |
| # NOTE: ここで "medical_space" にハードコードされている点を修正する必要がある | |
| # ドメインスキーマから適切な空間名を取得するべき | |
| domain_space = tile.get("coordinates", {}).get("medical_space") | |
| if not domain_space: | |
| continue | |
| distance = self._euclidean_distance( | |
| (x, y, z), | |
| domain_space | |
| ) | |
| if distance <= tolerance: | |
| return tile | |
| return None | |
| def _euclidean_distance( | |
| coord1: Tuple[float, float, float], | |
| coord2: Tuple[float, float, float] | |
| ) -> float: | |
| """ユークリッド距離を計算""" | |
| return sum((c1 - c2)**2 for c1, c2 in zip(coord1, coord2))**0.5 | |
| def search_by_keyword(self, keyword: str) -> List[Dict]: | |
| """ | |
| キーワードでタイルを検索 | |
| """ | |
| results = [] | |
| for tile in self.loaded_tiles.values(): | |
| content = tile.get("content", {}).get("final_response", "") | |
| if keyword.lower() in content.lower(): | |
| results.append(tile) | |
| return results | |
| def get_tile_by_id(self, tile_id: str) -> Optional[Dict]: | |
| """タイルIDで直接取得""" | |
| return self.loaded_tiles.get(tile_id) | |
| def list_all_tiles(self) -> List[Dict]: | |
| """全タイルを一覧""" | |
| return list(self.loaded_tiles.values()) | |
| def get_stats(self) -> Dict: | |
| """DB統計情報""" | |
| if not self.is_loaded: | |
| return {"status": "not_loaded"} | |
| certainties = [] | |
| for tile in self.loaded_tiles.values(): | |
| c = tile.get("coordinates", {}).get("meta_space", [0])[0] | |
| certainties.append(c) | |
| return { | |
| "status": "loaded", | |
| "total_tiles": len(self.loaded_tiles), | |
| "avg_certainty": sum(certainties) / len(certainties) if certainties else 0, | |
| "min_certainty": min(certainties) if certainties else 0, | |
| "max_certainty": max(certainties) if certainties else 0, | |
| "file_size_mb": os.path.getsize(self.db_file_path) / (1024**2) | |
| } | |
| # テスト用ヘルパー | |
| class IathDBTestHelper: | |
| """DB接続テスト用ユーティリティ""" | |
| async def test_basic_loading(db_file_path: str): | |
| """基本的なロードテスト""" | |
| db = IathDBInterface(db_file_path) | |
| print(f"\n【テスト】DB基本ロード") | |
| print(f"ファイル: {db_file_path}") | |
| success = db.load_db() | |
| if success: | |
| stats = db.get_stats() | |
| print(f"✓ ロード成功") | |
| print(f" タイル数: {stats['total_tiles']}") | |
| print(f" 平均確実性: {stats['avg_certainty']:.1f}%") | |
| else: | |
| print(f"✗ ロード失敗") | |
| return success | |
| async def test_coordinate_search(db_file_path: str): | |
| """座標検索テスト""" | |
| db = IathDBInterface(db_file_path) | |
| db.load_db() | |
| test_coords = [ | |
| (28, 35, 15), # 心筋梗塞の診断 | |
| (42, 50, 40), # 肺関連 | |
| ] | |
| print(f"\n【テスト】座標検索") | |
| for coord in test_coords: | |
| tile = await db.fetch_async(coord, tolerance=15) | |
| if tile: | |
| print(f"✓ 座標{coord}: 見つかった") | |
| print(f" トピック: {tile.get('metadata', {}).get('topic', 'N/A')}") | |
| else: | |
| print(f"✗ 座標{coord}: 見つからない") | |
| return True | |
| # 使用例 | |
| if __name__ == "__main__": | |
| import asyncio | |
| # --- 注意 --- | |
| # このテストを実行する前に、まず create_tile_from_topic.py を実行して | |
| # `cardiology_prototype_v1.iath` ファイルを作成しておく必要があります。 | |
| # `python create_tile_from_topic.py cardiology_prototype_v1` のように実行し、 | |
| # そのファイル名を `db_file` 変数に指定してください。 | |
| # ---------- | |
| db_file = "cardiology_prototype_v1.iath" # サンプルDBファイル名 | |
| print("="*60) | |
| print("Ilm-Athens DB接続テスト") | |
| print("="*60) | |
| async def main(): | |
| helper = IathDBTestHelper() | |
| # テスト1: ロード | |
| if await helper.test_basic_loading(db_file): | |
| print("\n✓ テスト1パス") | |
| # テスト2: 座標検索 | |
| if await helper.test_coordinate_search(db_file): | |
| print("\n✓ テスト2パス") | |
| print("\n" + "="*60) | |
| print("全テストPASS ✓") | |
| print("="*60) | |
| asyncio.run(main()) | |