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(retrieve): fixed count on entities and relationships retrieve
Christian30470dce5614
diff --git a/.env.example b/.env.examplenew file mode 100644index 0000000..1ea7934--- /dev/null+++ b/.env.example@@ -0,0 +1,41 @@+# LLM Implementation envs+# The following are just examples of the adapter implementation, you can have completely different envs+AZURE_LARGE_LLM_MODEL="gpt-4o"+AZURE_LARGE_LLM_API_VERSION="2024-12-01-preview"+AZURE_LARGE_LLM_ENDPOINT="https://yourproject.openai.azure.com"+AZURE_LLM_SUBSCRIPTION_KEY="xyz"++# Embedding envs+# The following are just examples of the adapter implementation, you can have completely different envs+AZURE_EMBEDDING_FULL_ENDPOINT="https://yourproject.openai.azure.com/openai/deployments/text-embedding-3-large/embeddings?api-version=2023-05-15"+AZURE_EMBEDDING_KEY="xyz"++# Cache envs+# The following are just examples of the adapter implementation, you can have completely different envs+REDIS_HOST="localhost"+REDIS_PORT=6379++# Worker envs+# Can be whatever you prefer+# CELERY_BACKEND="rabbitmq"+CELERY_BACKEND="redis"++# GraphDB envs+# The following are just examples of the adapter implementation, you can have completely different envs+NEO4J_HOST="localhost"+NEO4J_PORT=7687+NEO4J_USERNAME="neo4j"+NEO4J_PASSWORD="your_password"++# VectorDB envs+# The following are just examples of the adapter implementation, you can have completely different envs+MILVUS_HOST="localhost"+MILVUS_PORT=19530++# DataDB envs+# The following are just examples of the adapter implementation, you can have completely different envs+MONGO_HOST="localhost"+MONGO_PORT=27017+MONGO_USERNAME="root"+MONGO_PASSWORD="password"+diff --git a/Dockerfile b/Dockerfiledeleted file mode 100644index 8efa7da..0000000--- a/Dockerfile+++ /dev/null@@ -1,87 +0,0 @@-# 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 \- PIP_NO_CACHE_DIR=1 \- PIP_DISABLE_PIP_VERSION_CHECK=1--# Install system dependencies-RUN apt-get update && apt-get install -y \- build-essential \- curl \- && rm -rf /var/lib/apt/lists/*--# Install Poetry-RUN pip install poetry==1.8.3--# Configure Poetry-ENV POETRY_NO_INTERACTION=1 \- POETRY_VENV_IN_PROJECT=1 \- POETRY_CACHE_DIR=/tmp/poetry_cache \- POETRY_VENV_PATH=/app/.venv--# Set work directory-WORKDIR /app--# Copy Poetry files-COPY pyproject.toml poetry.lock ./--# Install dependencies-RUN poetry config virtualenvs.in-project true && \- poetry lock && poetry install --no-root --sync && rm -rf $POETRY_CACHE_DIR--# 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 \- PATH="/app/.venv/bin:$PATH"--# Install runtime dependencies-RUN apt-get update && apt-get install -y \- curl \- && rm -rf /var/lib/apt/lists/*--# Create non-root user-RUN groupadd -r appuser && useradd -r -g appuser appuser--# Set work directory-WORKDIR /app--# Copy virtual environment from builder stage-COPY --from=builder /app/.venv /app/.venv--# Copy application code-COPY src/ ./src/--# Change ownership to non-root user-RUN chown -R appuser:appuser /app-USER appuser--# Switch to non-root user-USER root--# Expose port-EXPOSE 8000--# Health check-HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \- CMD curl -f http://localhost:8000/docs || exit 1--# Default command-CMD ["/app/.venv/bin/python", "-m", "uvicorn", "src.services.api.app:app", "--host", "0.0.0.0", "--port", "8000"]\ No newline at end of filediff --git a/LICENSE b/LICENSEnew file mode 100644index 0000000..e69de29diff --git a/README.md b/README.mdindex bc73877..e69de29 100644--- a/README.md+++ b/README.md@@ -1,89 +0,0 @@-BEFORE OPEN SOURCING REMOVE PAT AND ALL SECRETS--## New deploy config--```-sudo apt update-sudo apt install -y ca-certificates curl gnupg lsb-release-sudo mkdir -p /etc/apt/keyrings-curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | \-sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg-echo \- "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \- https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \- $(lsb_release -cs) stable" | \- sudo tee /etc/apt/sources.list.d/docker.list > /dev/null-sudo apt update-sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin-sudo systemctl enable docker-sudo systemctl start docker-sudo docker pull nginx:latest-docker network create appnet || true-sudo docker run -d \- --network appnet \- --name nginx-server \- -p 80:80 \- -v /srv/nginx/html:/usr/share/nginx/html \- -v /srv/nginx/conf:/etc/nginx/conf.d \- --restart always \- nginx-sudo systemctl enable docker-sudo docker run -it --rm \- -v /etc/letsencrypt:/etc/letsencrypt \- -v /var/lib/letsencrypt:/var/lib/letsencrypt \- -p 80:80 \- certbot/certbot certonly --standalone \- -d glo-matcher.brainapi.lumen-labs.ai-sudo tee /srv/nginx/conf/default.conf >/dev/null <<'NGINX'-server {- listen 80;- server_name glo-matcher.brainapi.lumen-labs.ai;- return 301 https://$host$request_uri;-}-server {- listen 443 ssl;- server_name glo-matcher.brainapi.lumen-labs.ai;-- ssl_certificate /etc/letsencrypt/live/glo-matcher.brainapi.lumen-labs.ai/fullchain.pem;- ssl_certificate_key /etc/letsencrypt/live/glo-matcher.brainapi.lumen-labs.ai/privkey.pem;-- client_max_body_size 50m;-- location / {- proxy_pass http://127.0.0.1:8000;- proxy_http_version 1.1;- proxy_set_header Host $host;- proxy_set_header X-Real-IP $remote_addr;- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;- proxy_set_header X-Forwarded-Proto $scheme;-- proxy_set_header Upgrade $http_upgrade;- proxy_set_header Connection "upgrade";-- proxy_connect_timeout 60s;- proxy_send_timeout 300s;- proxy_read_timeout 300s;- send_timeout 300s;- }-}-NGINX--docker rm -f nginx-server 2>/dev/null || true-docker run -d --name nginx-server \- -p 80:80 -p 443:443 \- -v /srv/nginx/html:/usr/share/nginx/html \- -v /srv/nginx/conf:/etc/nginx/conf.d \- -v /etc/letsencrypt:/etc/letsencrypt:ro \- --restart always \- nginx:latest--echo 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 | docker login ghcr.io -u ChrisCoder9000 --password-stdin-docker pull ghcr.io/lumen-labs/brainapi:latest-docker run -d \- --name brainapi \- -p 8000:8000 \- --network appnet \- --restart always \- ghcr.io/lumen-labs/brainapi:latest--```diff --git a/docker-compose-partial.yaml b/docker-compose-partial.yamldeleted file mode 100644index 3d873ff..0000000--- a/docker-compose-partial.yaml+++ /dev/null@@ -1,123 +0,0 @@-services:- redis:- image: redis:latest- ports:- - "6379:6379"- volumes:- - redis-data:/data- command: redis-server --appendonly yes- networks:- - appnet- restart: unless-stopped- healthcheck:- test: ["CMD", "redis-cli", "ping"]- interval: 10s- timeout: 3s- retries: 3-- neo4j:- image: neo4j:latest- ports:- - "7474:7474"- - "7687:7687"- volumes:- - neo4j-data:/data- - neo4j-logs:/logs- - neo4j-plugins:/plugins- - ./src/lib/neo4j/config:/var/lib/neo4j/conf- environment:- - NEO4J_AUTH=neo4j/${NEO4J_PASSWORD:-your_password}- - NEO4J_PLUGINS=["apoc"]- networks:- - appnet- restart: unless-stopped- healthcheck:- test: ["CMD-SHELL", "wget -q --spider http://localhost:7474 || exit 1"]- interval: 15s- timeout: 10s- retries: 5- start_period: 90s-- brainapi:- image: ghcr.io/lumen-labs/brainapi:latest- ports:- - "8000:8000"- env_file:- - /root/.env- environment:- - REDIS_HOST=redis- - REDIS_PORT=6379- - NEO4J_HOST=neo4j- - NEO4J_PORT=7687- - NEO4J_USERNAME=neo4j- - NEO4J_PASSWORD=${NEO4J_PASSWORD:-your_password}- depends_on:- redis:- condition: service_healthy- neo4j:- condition: service_started- networks:- - appnet- restart: unless-stopped- healthcheck:- test: ["CMD", "curl", "-f", "http://localhost:8000/docs"]- interval: 30s- timeout: 10s- retries: 3- start_period: 40s-- brainapi-worker:- image: ghcr.io/lumen-labs/brainapi:latest- command: /app/.venv/bin/celery -A src.workers.app worker --loglevel=info- env_file:- - /root/.env- environment:- - REDIS_HOST=redis- - REDIS_PORT=6379- - NEO4J_HOST=neo4j- - NEO4J_PORT=7687- - NEO4J_USERNAME=neo4j- - NEO4J_PASSWORD=${NEO4J_PASSWORD:-your_password}- depends_on:- redis:- condition: service_healthy- neo4j:- condition: service_started- networks:- - appnet- restart: unless-stopped-- nginx:- image: nginx:latest- ports:- - "80:80"- - "443:443"- volumes:- - /srv/nginx/conf:/etc/nginx/conf.d:ro- - /etc/letsencrypt:/etc/letsencrypt:ro- - /srv/nginx/html:/usr/share/nginx/html:ro- depends_on:- brainapi:- condition: service_healthy- networks:- - appnet- restart: unless-stopped- healthcheck:- test: ["CMD", "nginx", "-t"]- interval: 30s- timeout: 5s- retries: 3--networks:- appnet:- driver: bridge--volumes:- redis-data:- driver: local- neo4j-data:- driver: local- neo4j-logs:- driver: local- neo4j-plugins:- driver: local\ No newline at end of filediff --git a/pyproject.toml b/pyproject.tomlindex f537eb7..b727703 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -1,6 +1,6 @@[project]name = "brainapi2"-version = "1.5.0"+version = "1.5.1"description = "Version 1.x.x of the BrainAPI memory layer."authors = [{name = "Christian",email = "[email protected]"}diff --git a/src/lib/neo4j/client.py b/src/lib/neo4j/client.pyindex 69b982c..1538981 100644--- a/src/lib/neo4j/client.py+++ b/src/lib/neo4j/client.py@@ -721,7 +721,8 @@ class Neo4jClient(GraphClient):LIMIT {limit}"""cypher_count = """- MATCH ()-[r]-()+ MATCH (n)-[r]-(m)+ {"WHERE " + " AND ".join(filters) if filters else ""}RETURN count(r) AS total"""result = self.driver.execute_query(cypher_query)@@ -847,6 +848,7 @@ class Neo4jClient(GraphClient):"""cypher_count = """MATCH (n)+ {"WHERE " + " AND ".join(filters) if filters else ""}RETURN count(n) AS total"""result = self.driver.execute_query(cypher_query)