diff --git a/SETUP.md b/SETUP.md index fe36328..c2fda5b 100644 --- a/SETUP.md +++ b/SETUP.md @@ -54,7 +54,11 @@ Boot up the vector database and internal services: docker compose up -d ``` > [!NOTE] -> This spins up **Qdrant** (our semantic memory vector store) alongside necessary backend supporting services. +> This spins up **Qdrant** (our semantic memory vector store) and the **Intelligence Layer** +> (the Python NLP service that extracts entities/relationships into your knowledge graph). +> The Intelligence Layer image is large on first build (bundled spaCy + sentence-transformers +> models), so the initial `docker compose up` can take a few minutes. It's optional at runtime — +> the agent calls it best-effort, so chat and memory keep working even while it's still starting. ### 4. Start Ollama Start your local inference engine: diff --git a/docker-compose.yml b/docker-compose.yml index 3da4005..baed4cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,6 +44,24 @@ services: wait $$OLLAMA_PID ' + # Python Intelligence Layer (NLP): entity + relationship extraction that feeds + # the knowledge graph. The agent calls it best-effort, so the stack still works + # if this container is starting up or unavailable. + python-agent: + build: + context: ./services/python-agent + dockerfile: Dockerfile + container_name: torvaix-intelligence + ports: + - "8000:8000" + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/health"] + interval: 30s + timeout: 10s + retries: 5 + start_period: 40s + torvaix: build: context: . @@ -57,6 +75,7 @@ services: - NODE_ENV=production - OLLAMA_URL=http://ollama:11434 - QDRANT_URL=http://qdrant:6333 + - PYTHON_SERVICE_URL=http://python-agent:8000 - AGENT_PORT=3001 - JWT_SECRET=${JWT_SECRET:-change-me-in-production} - TORVAIX_MODEL=${TORVAIX_MODEL:-llama3.2} @@ -73,6 +92,8 @@ services: condition: service_healthy ollama: condition: service_started + python-agent: + condition: service_started restart: unless-stopped healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3001/api/health"] diff --git a/services/python-agent/.dockerignore b/services/python-agent/.dockerignore new file mode 100644 index 0000000..d605235 --- /dev/null +++ b/services/python-agent/.dockerignore @@ -0,0 +1,8 @@ +__pycache__/ +*.pyc +*.pyo +.venv/ +venv/ +.pytest_cache/ +.mypy_cache/ +*.egg-info/ diff --git a/services/python-agent/Dockerfile b/services/python-agent/Dockerfile new file mode 100644 index 0000000..2181f23 --- /dev/null +++ b/services/python-agent/Dockerfile @@ -0,0 +1,29 @@ +# Torvaix Intelligence Layer (NLP) — spaCy + sentence-transformers behind FastAPI +FROM python:3.11-slim + +WORKDIR /app + +# curl is used by the container healthcheck +RUN apt-get update \ + && apt-get install -y --no-install-recommends curl \ + && rm -rf /var/lib/apt/lists/* + +# Install CPU-only PyTorch first so the requirements install below does NOT pull the +# multi-GB CUDA build. This keeps the image ~800MB instead of ~2.5GB. +RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Bake the models into the image so the first request is instant and works offline. +RUN python -m spacy download en_core_web_sm \ + && python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')" + +COPY app ./app + +EXPOSE 8000 + +HEALTHCHECK --interval=30s --timeout=10s --retries=5 --start-period=40s \ + CMD curl -f http://localhost:8000/health || exit 1 + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]