Skip to content

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.

build(docker + envs): fix build and handled managed milvus

Christianc30b2584a408
diff --git a/Dockerfile b/Dockerfile
index d47311a..8efa7da 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,10 @@
# Multi-stage build for brainapi2
FROM python:3.11-slim AS builder
+ARG BUILD_DATE
+ARG BUILD_SHA
+ARG CACHE_BUST
+
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
@@ -35,6 +39,14 @@ RUN poetry config virtualenvs.in-project true && \
# Production stage
FROM python:3.11-slim AS production
+ARG BUILD_DATE
+ARG BUILD_SHA
+ARG CACHE_BUST
+
+LABEL build_date="${BUILD_DATE}" \
+ build_sha="${BUILD_SHA}" \
+ cache_bust="${CACHE_BUST}"
+
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
@@ -59,9 +71,10 @@ COPY src/ ./src/
# Change ownership to non-root user
RUN chown -R appuser:appuser /app
+USER appuser
# Switch to non-root user
-USER appuser
+USER root
# Expose port
EXPOSE 8000
@@ -71,4 +84,4 @@ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/docs || exit 1
# Default command
-CMD ["python", "-m", "uvicorn", "src.services.api.app:app", "--host", "0.0.0.0", "--port", "8000"]
+CMD ["/app/.venv/bin/python", "-m", "uvicorn", "src.services.api.app:app", "--host", "0.0.0.0", "--port", "8000"]
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 2dc461d..2368099 100644
--- a/Makefile
+++ b/Makefile
@@ -83,7 +83,7 @@ clear-all-volumes:
VERSION := $(shell poetry version -s)
container-build:
- docker build --platform linux/amd64 -t ghcr.io/lumen-labs/brainapi:v$(VERSION) ./
+ docker build --no-cache --platform linux/amd64 -t ghcr.io/lumen-labs/brainapi:v$(VERSION) ./
docker tag ghcr.io/lumen-labs/brainapi:v$(VERSION) ghcr.io/lumen-labs/brainapi:latest
container-push:
@@ -92,7 +92,10 @@ container-push:
container-release:
VERSION=$$(poetry version -s)
- docker build --platform linux/amd64 -t ghcr.io/lumen-labs/brainapi:v$$VERSION ./
+ BUILD_DATE=$$(date -u +'%Y-%m-%dT%H:%M:%SZ')
+ BUILD_SHA=$$(git rev-parse HEAD || echo "unknown")
+ CACHE_BUST=$$(date +%s)
+ docker build --no-cache --build-arg BUILD_DATE="$$BUILD_DATE" --build-arg BUILD_SHA="$$BUILD_SHA" --build-arg CACHE_BUST="$$CACHE_BUST" --platform linux/amd64 -t ghcr.io/lumen-labs/brainapi:v$$VERSION ./
docker tag ghcr.io/lumen-labs/brainapi:v$$VERSION ghcr.io/lumen-labs/brainapi:latest
docker push ghcr.io/lumen-labs/brainapi:v$$VERSION
docker push ghcr.io/lumen-labs/brainapi:latest
\ No newline at end of file
diff --git a/poetry.lock b/poetry.lock
index 09962b9..6defc31 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -3560,4 +3560,4 @@ cffi = ["cffi (>=1.17,<2.0) ; platform_python_implementation != \"PyPy\" and pyt
[metadata]
lock-version = "2.1"
python-versions = ">=3.11,<4.0.0"
-content-hash = "381b2973dcf8c9582e20346fa790827d877a9eb8318e81c43271350690fbe654"
+content-hash = "a7d1ddad4410905fd6f3d8b9a364aa18395c1f54685d8fb76ad7ba45479d37cf"
diff --git a/pyproject.toml b/pyproject.toml
index 8a62f60..caaec02 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "brainapi2"
-version = "0.1.0"
+version = "0.1.3"
description = "Version 1.x.x of the BrainAPI memory layer."
authors = [
{name = "Christian",email = "[email protected]"}
@@ -8,7 +8,6 @@ authors = [
readme = "README.md"
requires-python = ">=3.11,<4.0.0"
dependencies = [
- "milvus (>=2.3.9,<3.0.0)",
"redis (>=6.4.0,<7.0.0)",
"pymongo (>=4.15.3,<5.0.0)",
"cpp-chunker (>=0.1.4,<0.2.0)",
@@ -31,6 +30,25 @@ dependencies = [
[tool.poetry]
package-mode = false
+[tool.poetry.dependencies]
+python = ">=3.11,<4.0.0"
+redis = ">=6.4.0,<7.0.0"
+pymongo = ">=4.15.3,<5.0.0"
+cpp-chunker = ">=0.1.4,<0.2.0"
+neo4j = ">=6.0.2,<7.0.0"
+pylint = ">=4.0.1,<5.0.0"
+langchain = ">=1.0.0,<2.0.0"
+openai = ">=2.5.0,<3.0.0"
+celery = ">=5.5.3,<6.0.0"
+kombu = {extras = ["rabbitmq"], version = ">=5.3.0,<6.0.0"}
+fastapi = ">=0.119.0,<0.120.0"
+langchain-core = ">=1.0.0,<2.0.0"
+uvicorn = ">=0.38.0,<0.39.0"
+python-dotenv = ">=1.1.1,<2.0.0"
+langchain-openai = ">=1.0.0,<2.0.0"
+google-genai = ">=1.46.0,<2.0.0"
+langchain-google-vertexai = ">=3.0.1,<4.0.0"
+pymilvus = ">=2.6.2,<3.0.0"
[tool.pylint.messages_control]
enable = ["abstract-method"]
@@ -47,4 +65,4 @@ good-names = ["i", "j", "k", "ex", "Run", "_", "id", "db", "ai", "llm"]
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
-build-backend = "poetry.core.masonry.api"
+build-backend = "poetry.core.masonry.api"
\ No newline at end of file
diff --git a/src/config.py b/src/config.py
index 6dc79fd..0282e62 100644
--- a/src/config.py
+++ b/src/config.py
@@ -78,8 +78,11 @@ class MilvusConfig:
def __init__(self):
self.host = os.getenv("MILVUS_HOST")
self.port = os.getenv("MILVUS_PORT")
-
- if [self.host, self.port].count(None) > 0:
+ self.uri = os.getenv("MILVUS_URI")
+ self.token = os.getenv("MILVUS_TOKEN")
+ if [self.host, self.port].count(None) > 0 and [self.uri, self.token].count(
+ None
+ ) > 0:
raise ValueError("Milvus configuration is not complete")
diff --git a/src/lib/milvus/client.py b/src/lib/milvus/client.py
index c7b12ed..bf214f6 100644
--- a/src/lib/milvus/client.py
+++ b/src/lib/milvus/client.py
@@ -36,7 +36,12 @@ class MilvusClient(VectorStoreClient):
Lazy initialization of the Milvus client.
"""
if self._client is None:
- self._client = Milvus(host=config.milvus.host, port=config.milvus.port)
+ self._client = Milvus(
+ host=config.milvus.host,
+ port=config.milvus.port,
+ uri=config.milvus.uri,
+ token=config.milvus.token,
+ )
return self._client
def _ensure_store(self, store: str) -> None:
diff --git a/src/lib/neo4j/config/neo4j.conf b/src/lib/neo4j/config/neo4j.conf
new file mode 100644
index 0000000..1640ea5
--- /dev/null
+++ b/src/lib/neo4j/config/neo4j.conf
@@ -0,0 +1,27 @@
+# Neo4j Configuration File
+
+# Java Memory Settings
+dbms.memory.heap.initial_size=512m
+dbms.memory.heap.max_size=2g
+dbms.memory.pagecache.size=1g
+
+# Database Settings
+dbms.default_database=neo4j
+
+# Network Settings
+dbms.default_listen_address=0.0.0.0
+dbms.connector.http.listen_address=:7474
+dbms.connector.bolt.listen_address=:7687
+
+# Security Settings
+dbms.security.auth_enabled=true
+
+# Logging Settings
+dbms.logs.http.enabled=true
+dbms.logs.query.enabled=true
+dbms.logs.query.threshold=0
+
+# Performance Settings
+dbms.tx_log.rotation.retention_policy=1G size
+dbms.checkpoint.interval.time=10m
+dbms.checkpoint.interval.tx=10000
diff --git a/src/lib/neo4j/docker-compose.yaml b/src/lib/neo4j/docker-compose.yaml
index 4c6e9d8..ad5f538 100644
--- a/src/lib/neo4j/docker-compose.yaml
+++ b/src/lib/neo4j/docker-compose.yaml
@@ -3,7 +3,7 @@ services:
image: neo4j:latest
volumes:
- /$HOME/neo4j/logs:/logs
- - /$HOME/neo4j/config:/config
+ - ./config:/config
- /$HOME/neo4j/data:/data
- /$HOME/neo4j/plugins:/plugins
environment: