akryldigital Yeroyan commited on
Commit
9e1adca
Β·
verified Β·
1 Parent(s): 92633a7

fix old "Document" import (#3)

Browse files

- fix old "Document" import (933edc57044ac89ba060526525a9bdfdb9b5acff)
- update reqs (49a2a7185d954271fb50dc7f9dcd7befd2d9b60c)
- download HF models during image build (5c02889da4e27203b934318b9deb5c23dd140f47)
- Pre-download Hugging Face models during build (06d3da632b935e3480a41c9cab85c18d42b89613)


Co-authored-by: Ara Yeroyan <Yeroyan@users.noreply.huggingface.co>

Files changed (4) hide show
  1. Dockerfile +6 -0
  2. download_models.py +54 -0
  3. requirements.txt +20 -5
  4. src/pipeline.py +5 -1
Dockerfile CHANGED
@@ -15,6 +15,12 @@ COPY requirements.txt ./
15
  # Install Python dependencies
16
  RUN pip3 install --no-cache-dir -r requirements.txt
17
 
 
 
 
 
 
 
18
  # Copy all application files (excluding .dockerignore patterns)
19
  COPY . .
20
 
 
15
  # Install Python dependencies
16
  RUN pip3 install --no-cache-dir -r requirements.txt
17
 
18
+ # Pre-download Hugging Face models during build
19
+ # This caches models in the Docker image for faster container startup
20
+ COPY download_models.py ./
21
+ COPY src/config/settings.yaml ./src/config/settings.yaml
22
+ RUN python download_models.py
23
+
24
  # Copy all application files (excluding .dockerignore patterns)
25
  COPY . .
26
 
download_models.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Pre-download Hugging Face models during Docker image build.
3
+
4
+ This script loads the models to trigger download and caching.
5
+ """
6
+ import os
7
+ import sys
8
+
9
+ print("πŸ”½ Downloading Hugging Face models during build...")
10
+
11
+ # Model configurations from settings.yaml
12
+ EMBEDDING_MODEL = "BAAI/bge-m3"
13
+ RERANKER_MODEL = "BAAI/bge-reranker-v2-m3"
14
+
15
+ try:
16
+ print(f"πŸ“¦ Downloading embedding model: {EMBEDDING_MODEL}")
17
+ from langchain_community.embeddings import HuggingFaceEmbeddings
18
+
19
+ # Load embedding model (will download if not cached)
20
+ embeddings = HuggingFaceEmbeddings(
21
+ model_name=EMBEDDING_MODEL,
22
+ model_kwargs={"device": "cpu"}, # Use CPU during build
23
+ encode_kwargs={"normalize_embeddings": True},
24
+ show_progress=True,
25
+ )
26
+
27
+ # Trigger actual download by encoding a small text
28
+ test_text = "test"
29
+ _ = embeddings.embed_query(test_text)
30
+ print(f"βœ… Embedding model downloaded: {EMBEDDING_MODEL}")
31
+
32
+ except Exception as e:
33
+ print(f"⚠️ Warning: Could not download embedding model: {e}")
34
+ # Don't exit on error - allow build to continue (model will download at runtime)
35
+ pass
36
+
37
+ try:
38
+ print(f"πŸ“¦ Downloading reranker model: {RERANKER_MODEL}")
39
+ from sentence_transformers import CrossEncoder
40
+
41
+ # Load reranker model (will download if not cached)
42
+ reranker = CrossEncoder(RERANKER_MODEL)
43
+
44
+ # Trigger actual download by running inference
45
+ test_pairs = [("test query", "test document")]
46
+ _ = reranker.predict(test_pairs)
47
+ print(f"βœ… Reranker model downloaded: {RERANKER_MODEL}")
48
+
49
+ except Exception as e:
50
+ print(f"⚠️ Warning: Could not download reranker model: {e}")
51
+ # Don't exit on error - allow build to continue (model will download at runtime)
52
+ pass
53
+
54
+ print("βœ… All models downloaded and cached successfully!")
requirements.txt CHANGED
@@ -1,9 +1,24 @@
 
 
 
 
 
 
 
1
  streamlit>=1.28.0
2
- langchain>=0.1.0
3
- langchain-core>=0.1.0
4
- langgraph>=0.0.20
 
 
 
 
 
 
 
5
  qdrant-client>=1.7.0
6
  python-dotenv>=1.0.0
7
  openai>=1.0.0
8
- snowflake-connector-python>=4.0.0
9
- pydantic>=2.0.0
 
 
1
+ pydantic>=2.0.0
2
+ torch>=2.0.0
3
+ numpy>=1.24.0
4
+ pandas>=2.0.0
5
+ FlagEmbedding==1.3.5
6
+ sentence-transformers>=2.2.2
7
+ transformers>=4.35.0
8
  streamlit>=1.28.0
9
+ langchain==0.3.25
10
+ langchain-community==0.3.24
11
+ langchain-core==0.3.79
12
+ langchain-huggingface==0.3.0
13
+ langchain-mistralai==0.2.10
14
+ langchain-ollama==0.3.3
15
+ langchain-openai==0.3.23
16
+ langchain-qdrant==0.2.0
17
+ langchain-text-splitters==0.3.8
18
+ langgraph==0.6.10
19
  qdrant-client>=1.7.0
20
  python-dotenv>=1.0.0
21
  openai>=1.0.0
22
+ pyyaml>=6.0
23
+ tqdm>=4.65.0
24
+ snowflake-connector-python>=4.0.0
src/pipeline.py CHANGED
@@ -4,7 +4,11 @@ from pathlib import Path
4
  from dataclasses import dataclass
5
  from typing import Dict, Any, List, Optional
6
 
7
- from langchain.docstore.document import Document
 
 
 
 
8
 
9
  from .logging import log_error
10
  from .llm.adapters import LLMRegistry
 
4
  from dataclasses import dataclass
5
  from typing import Dict, Any, List, Optional
6
 
7
+ try:
8
+ from langchain.docstore.document import Document
9
+ except ModuleNotFoundError as me:
10
+ print(me.__str__())
11
+ from langchain.schema import Document
12
 
13
  from .logging import log_error
14
  from .llm.adapters import LLMRegistry