Kevin Hu
commited on
Commit
·
d55a6be
1
Parent(s):
613b83b
make it lighten (#2577)
Browse files### What problem does this PR solve?
#2295
### Type of change
- [x] Refactoring
- Dockerfile.scratch +6 -5
- pyproject.toml +1 -1
- rag/llm/embedding_model.py +4 -4
- rag/llm/rerank_model.py +2 -2
Dockerfile.scratch
CHANGED
|
@@ -14,7 +14,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
|
| 14 |
RUN sed -i 's|http://archive.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/ubuntu.sources
|
| 15 |
|
| 16 |
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
| 17 |
-
apt update && apt install -y curl libpython3-dev nginx
|
| 18 |
&& rm -rf /var/lib/apt/lists/* \
|
| 19 |
&& curl -sSL https://install.python-poetry.org | python3 -
|
| 20 |
|
|
@@ -33,7 +33,7 @@ USER root
|
|
| 33 |
WORKDIR /ragflow
|
| 34 |
|
| 35 |
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
| 36 |
-
apt update && apt install -y nodejs npm
|
| 37 |
rm -rf /var/lib/apt/lists/*
|
| 38 |
|
| 39 |
COPY web web
|
|
@@ -42,7 +42,10 @@ RUN cd web && npm i --force && npm run build
|
|
| 42 |
# install dependencies from poetry.lock file
|
| 43 |
COPY pyproject.toml poetry.toml poetry.lock ./
|
| 44 |
RUN --mount=type=cache,target=/root/.cache/pypoetry,sharing=locked \
|
| 45 |
-
/root/.local/bin/poetry
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# production stage
|
| 48 |
FROM base AS production
|
|
@@ -76,8 +79,6 @@ ENV PATH="${VIRTUAL_ENV}/bin:/root/.local/bin:${PATH}"
|
|
| 76 |
# Download nltk data
|
| 77 |
RUN python3 -m nltk.downloader wordnet punkt punkt_tab
|
| 78 |
|
| 79 |
-
# Copy models downloaded via download_deps.sh
|
| 80 |
-
COPY det.onnx layout.laws.onnx layout.manual.onnx layout.onnx layout.paper.onnx ocr.res rec.onnx tsr.onnx updown_concat_xgb.model /ragflow/rag/res/deepdoc/
|
| 81 |
|
| 82 |
ENV PYTHONPATH=/ragflow/
|
| 83 |
|
|
|
|
| 14 |
RUN sed -i 's|http://archive.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/ubuntu.sources
|
| 15 |
|
| 16 |
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
| 17 |
+
apt update && apt install -y curl libpython3-dev nginx libglib2.0-0 libglx-mesa0 \
|
| 18 |
&& rm -rf /var/lib/apt/lists/* \
|
| 19 |
&& curl -sSL https://install.python-poetry.org | python3 -
|
| 20 |
|
|
|
|
| 33 |
WORKDIR /ragflow
|
| 34 |
|
| 35 |
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
| 36 |
+
apt update && apt install -y nodejs npm && \
|
| 37 |
rm -rf /var/lib/apt/lists/*
|
| 38 |
|
| 39 |
COPY web web
|
|
|
|
| 42 |
# install dependencies from poetry.lock file
|
| 43 |
COPY pyproject.toml poetry.toml poetry.lock ./
|
| 44 |
RUN --mount=type=cache,target=/root/.cache/pypoetry,sharing=locked \
|
| 45 |
+
/root/.local/bin/poetry lock
|
| 46 |
+
|
| 47 |
+
RUN --mount=type=cache,target=/root/.cache/pypoetry,sharing=locked \
|
| 48 |
+
/root/.local/bin/poetry install --sync --no-cache --no-root
|
| 49 |
|
| 50 |
# production stage
|
| 51 |
FROM base AS production
|
|
|
|
| 79 |
# Download nltk data
|
| 80 |
RUN python3 -m nltk.downloader wordnet punkt punkt_tab
|
| 81 |
|
|
|
|
|
|
|
| 82 |
|
| 83 |
ENV PYTHONPATH=/ragflow/
|
| 84 |
|
pyproject.toml
CHANGED
|
@@ -99,7 +99,7 @@ tika = "2.6.0"
|
|
| 99 |
tiktoken = "0.6.0"
|
| 100 |
torch = "2.3.0"
|
| 101 |
transformers = "4.38.1"
|
| 102 |
-
|
| 103 |
vertexai = "1.64.0"
|
| 104 |
volcengine = "1.0.146"
|
| 105 |
voyageai = "0.2.3"
|
|
|
|
| 99 |
tiktoken = "0.6.0"
|
| 100 |
torch = "2.3.0"
|
| 101 |
transformers = "4.38.1"
|
| 102 |
+
umap_learn = "0.5.6"
|
| 103 |
vertexai = "1.64.0"
|
| 104 |
volcengine = "1.0.146"
|
| 105 |
voyageai = "0.2.3"
|
rag/llm/embedding_model.py
CHANGED
|
@@ -245,8 +245,8 @@ class FastEmbed(Base):
|
|
| 245 |
threads: Optional[int] = None,
|
| 246 |
**kwargs,
|
| 247 |
):
|
| 248 |
-
|
| 249 |
-
|
| 250 |
self._model = TextEmbedding(model_name, cache_dir, threads, **kwargs)
|
| 251 |
|
| 252 |
def encode(self, texts: list, batch_size=32):
|
|
@@ -291,8 +291,8 @@ class YoudaoEmbed(Base):
|
|
| 291 |
_client = None
|
| 292 |
|
| 293 |
def __init__(self, key=None, model_name="maidalun1020/bce-embedding-base_v1", **kwargs):
|
| 294 |
-
|
| 295 |
-
|
| 296 |
try:
|
| 297 |
print("LOADING BCE...")
|
| 298 |
YoudaoEmbed._client = qanthing(model_name_or_path=os.path.join(
|
|
|
|
| 245 |
threads: Optional[int] = None,
|
| 246 |
**kwargs,
|
| 247 |
):
|
| 248 |
+
if not LIGHTEN and not FastEmbed._model:
|
| 249 |
+
from fastembed import TextEmbedding
|
| 250 |
self._model = TextEmbedding(model_name, cache_dir, threads, **kwargs)
|
| 251 |
|
| 252 |
def encode(self, texts: list, batch_size=32):
|
|
|
|
| 291 |
_client = None
|
| 292 |
|
| 293 |
def __init__(self, key=None, model_name="maidalun1020/bce-embedding-base_v1", **kwargs):
|
| 294 |
+
if not LIGHTEN and not YoudaoEmbed._client:
|
| 295 |
+
from BCEmbedding import EmbeddingModel as qanthing
|
| 296 |
try:
|
| 297 |
print("LOADING BCE...")
|
| 298 |
YoudaoEmbed._client = qanthing(model_name_or_path=os.path.join(
|
rag/llm/rerank_model.py
CHANGED
|
@@ -109,8 +109,8 @@ class YoudaoRerank(DefaultRerank):
|
|
| 109 |
_model_lock = threading.Lock()
|
| 110 |
|
| 111 |
def __init__(self, key=None, model_name="maidalun1020/bce-reranker-base_v1", **kwargs):
|
| 112 |
-
|
| 113 |
-
|
| 114 |
with YoudaoRerank._model_lock:
|
| 115 |
if not YoudaoRerank._model:
|
| 116 |
try:
|
|
|
|
| 109 |
_model_lock = threading.Lock()
|
| 110 |
|
| 111 |
def __init__(self, key=None, model_name="maidalun1020/bce-reranker-base_v1", **kwargs):
|
| 112 |
+
if not LIGHTEN and not YoudaoRerank._model:
|
| 113 |
+
from BCEmbedding import RerankerModel
|
| 114 |
with YoudaoRerank._model_lock:
|
| 115 |
if not YoudaoRerank._model:
|
| 116 |
try:
|