启动Mem0 REST API服务报错

前提

Mem0 Restfull API 

github地址:https://github.com/mem0ai/mem0/tree/main/server

介绍文档:https://docs.mem0.ai/open-source/features/rest-api

开始配置

按正常流程,我把Mem0的包上传到虚拟机之后,修改.env基础配置如下(OPENAI_API_KEY修改成自己的):

OPENAI_API_KEY=abc

POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_COLLECTION_NAME=memories

NEO4J_URI=bolt://neo4j:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=mem0graph

然后修改docker-compose.yaml内容如下:

name: mem0-dev

services:
  mem0:
    build:
      context: ..  # Set context to parent directory
      dockerfile: mem0/dev.Dockerfile
    ports:
      - "8888:8000"
    env_file:
      - .env
    networks:
      - mem0_network
    volumes:
      - ./history:/app/history      # History db location. By default, it creates a history.db file on the server folder
      - .:/app                      # Server code. This allows to reload the app when the server code is updated
      - ../mem0:/app/packages/mem0  # Mem0 library. This allows to reload the app when the library code is updated
    depends_on:
      postgres:
        condition: service_healthy
      neo4j:
        condition: service_healthy
    command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload  # Enable auto-reload
    environment:
      - PYTHONDONTWRITEBYTECODE=1  # Prevents Python from writing .pyc files
      - PYTHONUNBUFFERED=1  # Ensures Python output is sent straight to terminal

  postgres:
      image: ankane/pgvector:v0.5.1
      restart: on-failure
      shm_size: "128mb" # Increase this if vacuuming fails with a "no space left on device" error
      networks:
        - mem0_network
      environment:
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
      healthcheck:
        test: ["CMD", "pg_isready", "-q", "-d", "postgres", "-U", "postgres"]
        interval: 5s
        timeout: 5s
        retries: 5
      volumes:
        - postgres_db:/var/lib/postgresql/data
      ports:
        - "8432:5432"
  neo4j:
    image: neo4j:5.26.4
    networks:
      - mem0_network
    healthcheck:
      test: wget bolt://neo4j:8687 || exit 1
      interval: 1s
      timeout: 10s
      retries: 20
      start_period: 90s
    ports:
      - "8474:7474" # HTTP
      - "8687:7687" # Bolt
    volumes:
      - ./neo4j/data:/data  # 将 Neo4j 数据存储到 mem0 目录
      - ./neo4j/logs:/logs  # 将 Neo4j 日志存储到 mem0 目录
      - ./neo4j/import:/var/lib/neo4j/import  # 将 Neo4j 导入目录存储到 mem0 目录
    environment:
      - NEO4J_AUTH=neo4j/mem0graph
      - NEO4J_PLUGINS=["apoc"]  # Add this line to install APOC
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true

volumes:
  neo4j_data:
  postgres_db:

networks:
  mem0_network:
    driver: bridge

执行报错

然后执行 docker compose up 命令启动,结果报错:

dependency failed to start: container mem0-dev-neo4j-1 is unhealthy

查看neo4j日志:docker-compose logs neo4j

报错内容如下:

/usr/local/lib/python3.6/site-packages/paramiko/transport.py:32: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6. from cryptography.hazmat.backends import default_backend ERROR: The Compose file './docker-compose.yaml' is invalid because: 'name' does not match any of the regexes: '^x-'
You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1. For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

错误信息显示有两个问题:

1. Docker Compose 版本问题:你的 Docker Compose 版本不支持 name 字段(mem0-dev 不被支持 - 这是 Docker Compose V2 的新特性)

2. 健康检查命令还没修改:日志显示还在使用旧的 wget bolt://neo4j:8687 命令

问题修正

后面我就重新修改了docker-compose.yaml配置如下:

version: '3.8'

services:
  mem0:
    build:
      context: ..  # Set context to parent directory
      dockerfile: mem0/dev.Dockerfile
    container_name: mem0-dev-mem0
    ports:
      - "8888:8000"
    env_file:
      - .env
    networks:
      - mem0_network
    volumes:
      - ./history:/app/history      # History db location. By default, it creates a history.db file on the server folder
      - .:/app                      # Server code. This allows to reload the app when the server code is updated
      - ../mem0:/app/packages/mem0  # Mem0 library. This allows to reload the app when the library code is updated
    depends_on:
      postgres:
        condition: service_healthy
      neo4j:
        condition: service_healthy
    command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload  # Enable auto-reload
    environment:
      - PYTHONDONTWRITEBYTECODE=1  # Prevents Python from writing .pyc files
      - PYTHONUNBUFFERED=1  # Ensures Python output is sent straight to terminal

  postgres:
      image: ankane/pgvector:v0.5.1
      container_name: mem0-dev-postgres
      restart: on-failure
      shm_size: "128mb" # Increase this if vacuuming fails with a "no space left on device" error
      networks:
        - mem0_network
      environment:
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
      healthcheck:
        test: ["CMD", "pg_isready", "-q", "-d", "postgres", "-U", "postgres"]
        interval: 5s
        timeout: 5s
        retries: 5
      volumes:
        - postgres_db:/var/lib/postgresql/data
      ports:
        - "8432:5432"

  neo4j:
    image: neo4j:5.26.4
    container_name: mem0-dev-neo4j
    networks:
      - mem0_network
    healthcheck:
      # test: ["CMD-SHELL", "curl -f http://localhost:7474 || exit 1"]
      test: ["CMD-SHELL", "wget -q --spider http://localhost:7474 || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 90s
    ports:
      - "8474:7474" # HTTP
      - "8687:7687" # Bolt
    volumes:
      - ./neo4j/data:/data  # 将 Neo4j 数据存储到 mem0 目录
      - ./neo4j/logs:/logs  # 将 Neo4j 日志存储到 mem0 目录
      - ./neo4j/import:/var/lib/neo4j/import  # 将 Neo4j 导入目录存储到 mem0 目录
    environment:
      - NEO4J_AUTH=neo4j/mem0graph
      - NEO4J_PLUGINS=["apoc"]
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true

volumes:
  neo4j_data:
  postgres_db:

networks:
  mem0_network:
    driver: bridge

然后执行命令:

docker-compose down     # 将之前启动的容器关闭并删除
docker-compose up -d     # 重启容器

然后看到运行正常了:

image

 访问Swagger页面也正常:

image

 

posted @ 2026-06-12 06:14  君莫笑我十年游  阅读(10)  评论(0)    收藏  举报