9edcb58c93
Adds a searchable KB for חוק הביטוח הלאומי, תקנות הביטוח הלאומי, and חוזרי הביטוח הלאומי. Hybrid search (pgvector cosine + tsvector/trgm) fused with Reciprocal Rank Fusion, exposed to Shira as the `search_insurance_kb` tool. - api/services/kb/: asyncpg pool, Voyage voyage-multilingual-2 client, per-kind chunker (statute-by-section / circular header-aware), ingest pipeline with supersession (old source → superseded_by), hybrid search. - api/routes/admin_kb.py: POST /admin/kb/ingest (multipart), GET /admin/kb/stats. - mcp_server/tools/legal_kb_tools.py: `search_insurance_kb` registered under the `legal` toolset. - pyproject.toml: +asyncpg, +python-docx, +boto3, +python-multipart. Infra (external): pgvector/pgvector:pg16 on the shared PG, insurance_kb DB with hnsw + gin indexes, MinIO bucket insurance-kb, KB_DATABASE_URL in Infisical /espocrm, VOYAGE_API_KEY/VOYAGE_MODEL/KB_DATABASE_URL on the shira-hermes Coolify app. Refs Task Master #2 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
"""shira-hermes — FastAPI application."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from api.routes.admin_kb import router as admin_kb_router
|
|
from api.routes.health import router as health_router
|
|
from api.routes.smart_assistant import router as smart_assistant_router
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
|
|
)
|
|
|
|
logger = logging.getLogger("shira.app")
|
|
|
|
app = FastAPI(
|
|
title="shira-hermes",
|
|
description="Shira AI Assistant — Hermes Agent backend for EspoCRM SmartAssistant",
|
|
version="0.2.0",
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["GET", "POST", "OPTIONS"],
|
|
allow_headers=["Content-Type", "X-Api-Key"],
|
|
)
|
|
|
|
app.include_router(health_router)
|
|
app.include_router(smart_assistant_router)
|
|
app.include_router(admin_kb_router)
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def ensure_data_dirs():
|
|
"""Create persistent data directories if they don't exist."""
|
|
data_dir = os.environ.get("SHIRA_DATA_DIR", "/opt/data")
|
|
dirs = [
|
|
f"{data_dir}/skills",
|
|
f"{data_dir}/profiles",
|
|
f"{data_dir}/cases",
|
|
]
|
|
for d in dirs:
|
|
Path(d).mkdir(parents=True, exist_ok=True)
|
|
logger.info("Data directories ready at %s", data_dir)
|