BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications.
Python ai-agentsai-memoryknowledge-graphknowledge-managementknowledge-representationreccomendation-system
fix(build): added deps on container build time not startup anymore
Christian6e223f81170a
diff --git a/.dockerignore b/.dockerignoreindex 88e0562..762e050 100644--- a/.dockerignore+++ b/.dockerignore@@ -7,7 +7,7 @@README.md*.md-# Python+# Python caches__pycache__/*.py[cod]*$py.class@@ -31,7 +31,6 @@ wheels/MANIFEST# Virtual environments-.env.venvenv/venv/@@ -39,9 +38,14 @@ ENV/env.bak/venv.bak/+# Cache directories+.cache/+.ruff_cache/+# IDE.vscode/.idea/+.cursor/*.swp*.swo*~@@ -58,11 +62,14 @@ Thumbs.db# DockerDockerfile*docker-compose*.yml+docker-compose*.yaml+example-docker-compose.yaml.dockerignore-# Development files+# Development / CI filesMakefile*.excalidraw+.github/# Logs*.log@@ -74,7 +81,7 @@ logs/.tmp/.temp/-# Coverage reports+# Coverage / Testinghtmlcov/.coverage.coverage.*@@ -92,9 +99,6 @@ coverage.xml# pipenvPipfile.lock-# Poetry-# poetry.lock - needed for reproducible builds-# Celerycelerybeat-schedulecelerybeat.pid@@ -102,25 +106,29 @@ celerybeat.pid# SageMath parsed files*.sage.py-# Environments-.env.local-.env.development.local-.env.test.local-.env.production.local+# Environment files (secrets)+.env+.env.*-# Database volumes+# Database volumes (local dev)src/lib/*/volumes/src/lib/*/docker-compose.yaml-# Terraform-deploy/terraform/+# Terraform / Infrastructure+deploy/+infra/*.tfstate*.tfstate.*.terraform/+# Credentialsgcp_credentials.json+*.pem+*.key++# Misc+.favorites.jsonREADMEP.mdUntitled-1.excalidraw-.favorites.json-.env-.env*\ No newline at end of file+mcp-stdio-http-bridge/+agent-transcripts/diff --git a/Dockerfile b/Dockerfileindex c41ed7e..5934915 100644--- a/Dockerfile+++ b/Dockerfile@@ -1,4 +1,49 @@# syntax=docker/dockerfile:1.4++# ── Stage 1: builder ────────────────────────────────────────+FROM python:3.11-slim AS builder++ENV PYTHONUNBUFFERED=1 \+ PYTHONDONTWRITEBYTECODE=1 \+ PIP_NO_CACHE_DIR=1 \+ PIP_RETRIES=8 \+ PIP_TIMEOUT=900 \+ PIP_DEFAULT_TIMEOUT=900 \+ POETRY_NO_INTERACTION=1 \+ POETRY_VIRTUALENVS_IN_PROJECT=true \+ HF_HOME=/app/.cache \+ TRANSFORMERS_CACHE=/app/.cache \+ SENTENCE_TRANSFORMERS_HOME=/app/.cache++RUN apt-get update && apt-get install -y --no-install-recommends \+ build-essential \+ curl \+ && rm -rf /var/lib/apt/lists/*++RUN pip install --no-cache-dir poetry==2.1.3++WORKDIR /app++COPY pyproject.toml poetry.lock ./++RUN poetry sync --no-root \+ && TORCH_VER=$(/app/.venv/bin/python -c "import torch; print(torch.__version__.split('+')[0])") \+ && TV_VER=$(/app/.venv/bin/python -c "import torchvision; print(torchvision.__version__.split('+')[0])") \+ && /app/.venv/bin/pip install --no-cache-dir --no-deps --force-reinstall \+ "torch==${TORCH_VER}" "torchvision==${TV_VER}" \+ --index-url https://download.pytorch.org/whl/cpu \+ && rm -rf /root/.cache /tmp/*++COPY src/ ./src/++RUN /app/.venv/bin/python -c "\+from sentence_transformers import SentenceTransformer; \+SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2'); \+SentenceTransformer('intfloat/e5-small')" \+ && /app/.venv/bin/python -m spacy download en_core_web_sm \+ && rm -rf /root/.cache /tmp/*++# ── Stage 2: runtime ────────────────────────────────────────FROM python:3.11-slimARG BUILD_DATE@@ -13,35 +58,34 @@ ENV PYTHONUNBUFFERED=1 \HF_HOME=/app/.cache \TRANSFORMERS_CACHE=/app/.cache \SENTENCE_TRANSFORMERS_HOME=/app/.cache \- POETRY_NO_INTERACTION=1 \- POETRY_VENV_IN_PROJECT=1 \+ PIP_NO_CACHE_DIR=1 \PIP_RETRIES=8 \PIP_TIMEOUT=900 \PIP_DEFAULT_TIMEOUT=900-RUN apt-get update && apt-get install -y \- build-essential \+RUN apt-get update && apt-get install -y --no-install-recommends \curl \- wget \- && rm -rf /var/lib/apt/lists/* && \- pip install poetry==2.1.3 && \- groupadd -r appuser && useradd -r -g appuser -m appuser && \- GOSU_VERSION=1.19 && \- dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" && \- wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${dpkgArch}" && \- chmod +x /usr/local/bin/gosu+ && rm -rf /var/lib/apt/lists/* \+ && GOSU_VERSION=1.19 \+ && dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \+ && curl -fsSL -o /usr/local/bin/gosu \+ "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${dpkgArch}" \+ && chmod +x /usr/local/bin/gosu \+ && groupadd -r appuser && useradd -r -g appuser -m appuserWORKDIR /app-COPY --chown=root:root pyproject.toml poetry.lock ./-COPY --chown=root:root src/ ./src/-COPY --chown=root:root entrypoint.sh ./+COPY --from=builder /app/.venv /app/.venv+COPY --from=builder /app/.cache /app/.cache+COPY --from=builder /app/src /app/src+COPY --from=builder /app/pyproject.toml /app/+COPY entrypoint.sh ./RUN chmod +x /app/entrypoint.shEXPOSE 8000-HEALTHCHECK --interval=30s --timeout=30s --start-period=900s --retries=5 \+HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=5 \CMD curl -f http://localhost:8000/docs || exit 1USER rootdiff --git a/entrypoint.sh b/entrypoint.shindex 3ec3a2d..4aa4f90 100644--- a/entrypoint.sh+++ b/entrypoint.sh@@ -1,20 +1,8 @@#!/bin/bashset -e-if [ ! -f "/app/.venv/bin/python" ] || ! /app/.venv/bin/python -c "import torch; import sentence_transformers; import spacy" 2>/dev/null; then- echo "Installing dependencies..."- mkdir -p /app/.venv /app/.cache- if [ -d "/app/.venv" ] && [ "$(ls -A /app/.venv 2>/dev/null)" ]; then- find /app/.venv -mindepth 1 -delete- fi- poetry config virtualenvs.in-project true- poetry sync --no-root- chown -R appuser:appuser /app/.venv /app/.cache+if [ -d /app/.cache ]; then+ chown -R appuser:appuser /app/.cache 2>/dev/null || truefi-echo "Checking for sentence-transformers model..."-gosu appuser /app/.venv/bin/python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')"-echo "Ready."-exec gosu appuser /app/.venv/bin/python "$@"-diff --git a/example-docker-compose.yaml b/example-docker-compose.yamlindex 64345ec..ffc0fca 100644--- a/example-docker-compose.yaml+++ b/example-docker-compose.yaml@@ -183,6 +183,8 @@ services:--timeout-keep-alive 30--limit-concurrency 200--backlog 2048+ tmpfs:+ - /tmp:size=512Mdepends_on:redis:condition: service_healthy@@ -220,12 +222,14 @@ services:environment:CELERY_WORKER_CONCURRENCY: ${CELERY_WORKER_CONCURRENCY:-4}command: >- /app/.venv/bin/celery+ -m celery-A src.workers.app:ingestion_app worker-Q ingest_data,process_architect_relationships,ingest_structured_data,consolidate_graph--loglevel=info--prefetch-multiplier=1--optimization=fair+ tmpfs:+ - /tmp:size=512Mdepends_on:redis:condition: service_healthy@@ -264,6 +268,8 @@ services:--host 0.0.0.0--port 8001--timeout-keep-alive 30+ tmpfs:+ - /tmp:size=512Mdepends_on:redis:condition: service_healthy