faiss server

This commit is contained in:
2026-04-10 11:55:00 +00:00
parent bc82e3e708
commit 8e39e609cc
30 changed files with 1271 additions and 1048 deletions

48
faiss/Dockerfile Normal file
View File

@@ -0,0 +1,48 @@
# Dockerfile
FROM python:3.12-slim AS builder
# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# 安装系统依赖faiss-cpu 编译需要)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libopenblas-dev \
libomp-dev \
&& rm -rf /var/lib/apt/lists/*
# 复制依赖文件并安装
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# 最终镜像
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# 运行时需要的系统库
RUN apt-get update && apt-get install -y --no-install-recommends \
libopenblas-dev \
libomp-dev \
&& rm -rf /var/lib/apt/lists/*
# 从 builder 复制已安装的 Python 包
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# 复制项目代码
COPY . .
# 暴露端口
EXPOSE 8000
# 启动命令(使用字符串路径,兼容 reload
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]