fix: replace sentence-transformers with fastembed to eliminate torch/CUDA dependency

This commit is contained in:
Power BI Dev
2026-06-04 09:40:00 +07:00
parent 1e30885e1a
commit e8e7f02aff
4 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Pre-download embedding model agar tidak diunduh ulang saat runtime # Pre-download embedding model agar tidak diunduh ulang saat runtime
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')" RUN python -c "from fastembed import TextEmbedding; TextEmbedding('sentence-transformers/all-MiniLM-L6-v2')"
COPY src/ ./src/ COPY src/ ./src/
+1 -1
View File
@@ -4,4 +4,4 @@ python-dotenv==1.0.1
chromadb==0.5.3 chromadb==0.5.3
pdfplumber==0.11.0 pdfplumber==0.11.0
python-docx==1.1.2 python-docx==1.1.2
sentence-transformers==3.0.1 fastembed==0.4.2
+1 -1
View File
@@ -11,4 +11,4 @@ ADMIN_TELEGRAM_ID = int(os.environ["ADMIN_TELEGRAM_ID"])
DB_PATH = os.getenv("DB_PATH", "/app/data/second_brain.db") DB_PATH = os.getenv("DB_PATH", "/app/data/second_brain.db")
CHROMA_PATH = os.getenv("CHROMA_PATH", "/app/data/chromadb") CHROMA_PATH = os.getenv("CHROMA_PATH", "/app/data/chromadb")
UPLOAD_PATH = os.getenv("UPLOAD_PATH", "/app/data/uploads") UPLOAD_PATH = os.getenv("UPLOAD_PATH", "/app/data/uploads")
EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "all-MiniLM-L6-v2") EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "sentence-transformers/all-MiniLM-L6-v2")
+4 -4
View File
@@ -1,10 +1,10 @@
import asyncio import asyncio
import chromadb import chromadb
from sentence_transformers import SentenceTransformer from fastembed import TextEmbedding
from config import CHROMA_PATH, EMBEDDING_MODEL from config import CHROMA_PATH, EMBEDDING_MODEL
_chroma = chromadb.PersistentClient(path=CHROMA_PATH) _chroma = chromadb.PersistentClient(path=CHROMA_PATH)
_embedding_model = SentenceTransformer(EMBEDDING_MODEL) _embedding_model = TextEmbedding(model_name=EMBEDDING_MODEL)
def _get_collection(name: str): def _get_collection(name: str):
@@ -12,8 +12,8 @@ def _get_collection(name: str):
async def _embed(text: str) -> list: async def _embed(text: str) -> list:
embedding = await asyncio.to_thread(_embedding_model.encode, text) result = await asyncio.to_thread(lambda: list(_embedding_model.embed([text]))[0])
return embedding.tolist() return result.tolist()
async def add_memory(user_id: int, memory_id: int, content: str, scope: str = "private"): async def add_memory(user_id: int, memory_id: int, content: str, scope: str = "private"):