feat: language-aware routing (English -> llama3:8b-instruct; else Qwen 7B/14B). Docs updated

This commit is contained in:
hyungi
2025-08-13 07:45:49 +09:00
parent d17ec57b2e
commit bcb1e543e6
3 changed files with 15 additions and 3 deletions

View File

@@ -123,6 +123,9 @@ TIP: 긴 문서를 다루려면 `num_ctx`(컨텍스트 길이)와 `num_thread`
- **시놀로지 메일/오피스 연동** - **시놀로지 메일/오피스 연동**
- 본문/첨부 텍스트를 `/index/upsert`로 누적(사전 색인) - 본문/첨부 텍스트를 `/index/upsert`로 누적(사전 색인)
- 사용자 질의는 `/chat` 호출(`use_rag=true`, 필요 시 `force_boost=true`) - 사용자 질의는 `/chat` 호출(`use_rag=true`, 필요 시 `force_boost=true`)
- 자동 라우팅 규칙(기본):
- 영어 비율이 높으면 `ENGLISH_MODEL`(기본 `llama3:8b-instruct`)
- 그 외는 길이/강제 부스팅 기준으로 `BASE_MODEL`(7B) 또는 `BOOST_MODEL`(14B)
## API 개요(요약) ## API 개요(요약)
@@ -225,6 +228,7 @@ curl -s -X POST http://localhost:26000/paperless/hook \
- `OLLAMA_HOST`(기본 `http://localhost:11434`): Ollama API 호스트 - `OLLAMA_HOST`(기본 `http://localhost:11434`): Ollama API 호스트
- `BASE_MODEL`(기본 `qwen2.5:7b-instruct`) - `BASE_MODEL`(기본 `qwen2.5:7b-instruct`)
- `BOOST_MODEL`(기본 `qwen2.5:14b-instruct`) - `BOOST_MODEL`(기본 `qwen2.5:14b-instruct`)
- `ENGLISH_MODEL`(기본 `llama3:8b-instruct`): 영어 감지 시 라우팅 대상
- `EMBEDDING_MODEL`(기본 `nomic-embed-text`) - `EMBEDDING_MODEL`(기본 `nomic-embed-text`)
- `INDEX_PATH`(기본 `data/index.jsonl`) - `INDEX_PATH`(기본 `data/index.jsonl`)
- `PAPERLESS_BASE_URL`, `PAPERLESS_TOKEN`(선택): Paperless API 연동 시 사용 - `PAPERLESS_BASE_URL`, `PAPERLESS_TOKEN`(선택): Paperless API 연동 시 사용

View File

@@ -9,6 +9,7 @@ class Settings:
ollama_host: str = os.getenv("OLLAMA_HOST", "http://localhost:11434") ollama_host: str = os.getenv("OLLAMA_HOST", "http://localhost:11434")
base_model: str = os.getenv("BASE_MODEL", "qwen2.5:7b-instruct") base_model: str = os.getenv("BASE_MODEL", "qwen2.5:7b-instruct")
boost_model: str = os.getenv("BOOST_MODEL", "qwen2.5:14b-instruct") boost_model: str = os.getenv("BOOST_MODEL", "qwen2.5:14b-instruct")
english_model: str = os.getenv("ENGLISH_MODEL", "llama3:8b-instruct")
embedding_model: str = os.getenv("EMBEDDING_MODEL", "nomic-embed-text") embedding_model: str = os.getenv("EMBEDDING_MODEL", "nomic-embed-text")
index_path: str = os.getenv("INDEX_PATH", "data/index.jsonl") index_path: str = os.getenv("INDEX_PATH", "data/index.jsonl")

View File

@@ -84,9 +84,16 @@ def search(req: SearchRequest) -> Dict[str, Any]:
def chat(req: ChatRequest) -> Dict[str, Any]: def chat(req: ChatRequest) -> Dict[str, Any]:
model = req.model model = req.model
if not model: if not model:
# 라우팅: 메시지 길이/force_boost 기준 간단 분기 # 언어 감지(매우 단순): 영문 비율이 높으면 영어 모델, 아니면 기본/부스팅
total_chars = sum(len(m.get("content", "")) for m in req.messages) user_text = "\n".join(m.get("content", "") for m in req.messages if m.get("role") == "user")
model = settings.boost_model if (req.force_boost or total_chars > 2000) else settings.base_model ascii_letters = sum(ch.isascii() and ch.isalpha() for ch in user_text)
non_ascii_letters = sum((not ch.isascii()) and ch.isalpha() for ch in user_text)
english_ratio = ascii_letters / max(ascii_letters + non_ascii_letters, 1)
total_chars = len(user_text)
if english_ratio > 0.8:
model = settings.english_model
else:
model = settings.boost_model if (req.force_boost or total_chars > 2000) else settings.base_model
context_docs: List[str] = [] context_docs: List[str] = []
if req.use_rag and index.rows: if req.use_rag and index.rows: